@@ -2,49 +2,106 @@ _ = require("jasmine-node");
2
2
var server = require ( "./../../src/server.js" ) ;
3
3
var webdriver = require ( 'selenium-webdriver' ) ;
4
4
5
- server . start ( {
6
- baseUrl : process . env [ "BASE_URL" ] ,
7
- port : process . env [ "PORT" ] ,
8
- sessionSecret : process . env [ "SESSION_SECRET" ] ,
9
- google : {
10
- clientId : process . env [ "GOOGLE_CLIENT_ID" ] ,
11
- clientSecret : process . env [ "GOOGLE_CLIENT_SECRET" ] ,
12
- redirect : "/oauth2callback"
13
- }
14
- } , afterServer ) ;
5
+ if ( process . env [ "TEST_LOC" ] === "local" ) {
6
+ server . start ( {
7
+ baseUrl : process . env [ "BASE_URL" ] ,
8
+ port : process . env [ "PORT" ] ,
9
+ sessionSecret : process . env [ "SESSION_SECRET" ] ,
10
+ google : {
11
+ clientId : process . env [ "GOOGLE_CLIENT_ID" ] ,
12
+ clientSecret : process . env [ "GOOGLE_CLIENT_SECRET" ] ,
13
+ redirect : "/oauth2callback"
14
+ }
15
+ } , function ( app , server ) {
16
+ var driver = new webdriver . Builder ( ) .
17
+ withCapabilities ( { browserName : "chrome" } ) .
18
+ build ( ) ;
19
+ afterServer ( server , process . env [ "BASE_URL" ] , driver ) ;
20
+ } ) ;
21
+ }
22
+ else {
23
+ var driver = new webdriver . Builder ( ) .
24
+ usingServer ( "https://ondemand.saucelabs.com/wd/hub" ) .
25
+ withCapabilities ( {
26
+ browserName : "internet explorer" ,
27
+ username : process . env [ "SAUCE_USERNAME" ] ,
28
+ accessKey : process . env [ "SAUCE_ACCESS_KEY" ]
29
+ } ) .
30
+ build ( ) ;
31
+ afterServer ( null , process . env [ "SAUCE_TEST_TARGET" ] , driver ) ;
32
+ }
33
+
15
34
16
35
var googleUsername = process . env [ "SELENIUM_GOOGLE_USER" ] ;
17
36
var googlePassword = process . env [ "SELENIUM_GOOGLE_PASSWORD" ] ;
18
37
19
- function afterServer ( app , server ) {
38
+ function afterServer ( maybeServer , baseUrl , driver ) {
39
+ function googleLogin ( driver ) {
40
+ driver . wait ( function ( ) {
41
+ return driver . getTitle ( ) . then ( function ( title ) {
42
+ return title === 'Sign in - Google Accounts' ;
43
+ } ) ;
44
+ } , 3000 ) ;
45
+ // Sometimes email isn't present because the browser remembers which
46
+ // Google account we last logged in as
47
+ driver . findElement ( webdriver . By . id ( "Email" ) ) . getAttribute ( "class" ) . then ( function ( cls ) {
48
+ if ( cls . indexOf ( "hidden" ) === - 1 ) {
49
+ driver . findElement ( webdriver . By . id ( "Email" ) ) . sendKeys ( googleUsername ) ;
50
+ }
51
+ driver . findElement ( webdriver . By . id ( "Passwd" ) ) . sendKeys ( googlePassword ) ;
52
+ driver . findElement ( webdriver . By . id ( "signIn" ) ) . click ( ) ;
53
+ } ) ;
54
+ }
55
+ function waitThenClick ( driver , query ) {
56
+ driver . wait ( function ( ) {
57
+ return driver . isElementPresent ( query ) ;
58
+ } , 4000 ) ;
59
+ return driver . findElement ( query ) . click ( ) ;
60
+ }
20
61
describe ( "Sign in" , function ( ) {
21
- var /*driver;
22
- beforeEach(function() {
23
- console.log("running test");*/
24
- driver = new webdriver . Builder ( ) .
25
- withCapabilities ( webdriver . Capabilities . chrome ( ) ) .
26
- build ( ) ;
27
- // });
62
+ webdriver . promise . controlFlow ( ) . on ( 'uncaughtException' , function ( e ) {
63
+ console . error ( 'Unhandled error: ' + e ) ;
64
+ fail ( ) ;
65
+ } ) ;
66
+
67
+ it ( "Should forget everything it knows" , function ( done ) {
68
+ try {
69
+ driver . get ( "https://security.google.com/settings/security/permissions" ) ;
70
+ googleLogin ( driver ) ;
71
+ console . log ( "waiting..." ) ;
72
+ driver . wait ( function ( ) {
73
+ console . log ( "Waiting for page..." ) ;
74
+ return driver . executeScript ( "return document.readyState === 'complete'" ) ;
75
+ } , 3000 ) ;
76
+ // driver.isElementPresent(webdriver.By.xpath("//*[contains(text(), 'Patch Test')]")).then(function(p) { console.log(p); });
77
+ driver . isElementPresent ( webdriver . By . xpath ( "//*[contains(text(), 'Patch Test')]" ) ) . then ( function ( present ) {
78
+ console . log ( "present: " , present ) ;
79
+ if ( present ) {
80
+ waitThenClick ( driver , webdriver . By . xpath ( "//*[contains(text(), 'Patch Test')]" ) ) ;
81
+ waitThenClick ( driver , webdriver . By . xpath ( "//*[contains(text(), 'Revoke access')]" ) ) ;
82
+ return waitThenClick ( driver , webdriver . By . name ( "ok" ) ) ;
83
+ } else {
84
+ // do nothing
85
+ }
86
+ } ) ;
87
+ driver . get ( "https://accounts.google.com/Logout" ) ;
88
+ driver . call ( function ( ) { done ( ) ; } ) ;
89
+ }
90
+ catch ( e ) { console . log ( e ) ; }
91
+ } , 60000 ) ;
28
92
29
- it ( "Should sign up" , function ( done ) {
30
- console . log ( "foo " ) ;
31
- driver . get ( 'http://localhost:5000' ) ;
93
+ it ( "Should sign up from not being logged in " , function ( done ) {
94
+ console . log ( "sign up " ) ;
95
+ driver . get ( baseUrl ) ;
32
96
driver . findElement ( webdriver . By . id ( 'login' ) ) . click ( ) ;
33
- driver . wait ( function ( ) {
34
- return driver . getTitle ( ) . then ( function ( title ) {
35
- return title === 'Sign in - Google Accounts' ;
36
- } ) ;
37
- } , 1000 ) ;
38
- driver . findElement ( webdriver . By . id ( "Email" ) ) . sendKeys ( googleUsername ) ;
39
- driver . findElement ( webdriver . By . id ( "Passwd" ) ) . sendKeys ( googlePassword ) ;
40
- driver . findElement ( webdriver . By . id ( "signIn" ) ) . click ( ) ;
97
+ googleLogin ( driver ) ;
41
98
driver . wait ( function ( ) {
42
99
console . log ( "Waiting for confirmation button to activate..." ) ;
43
100
return driver . findElement ( webdriver . By . id ( "submit_approve_access" ) ) . getAttribute ( "disabled" )
44
101
. then ( function ( disabled ) {
45
102
return ! disabled ;
46
103
} ) ;
47
- } ) ;
104
+ } , 3000 ) ;
48
105
driver . findElement ( webdriver . By . id ( "submit_approve_access" ) ) . click ( ) ;
49
106
var loaded = driver . wait ( function ( ) {
50
107
console . log ( "Waiting for page to load.." ) ;
@@ -53,13 +110,14 @@ function afterServer(app, server) {
53
110
console . log ( "style: " , d ) ;
54
111
return d === "none" ;
55
112
} ) ;
56
- } ) ;
57
- loaded . then ( function ( ) { done ( ) ; } ) ;
58
- driver . quit ( ) ;
59
- } , 15000 ) ;
113
+ } , 3000 ) ;
114
+ loaded . then ( function ( ) { console . log ( "done with test" ) ; done ( ) ; } ) ;
115
+ } , 60000 ) ;
60
116
61
- it ( "Should close the server" , function ( done ) {
62
- server . close ( ) ;
117
+ it ( "Should close the server and the connection to the browser" , function ( done ) {
118
+ console . log ( "closing down server" ) ;
119
+ if ( maybeServer ) { maybeServer . close ( ) ; }
120
+ driver . quit ( ) ;
63
121
done ( ) ;
64
122
} ) ;
65
123
0 commit comments