Skip to content

Commit 1d47bd0

Browse files
authored
Merge pull request #204 from gauntface/test-fix
Bring the tests back to life
2 parents f9b8d32 + 4b42e42 commit 1d47bd0

File tree

3 files changed

+126
-95
lines changed

3 files changed

+126
-95
lines changed

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
"devDependencies": {
4444
"chalk": "^1.1.3",
45-
"chromedriver": "^2.21.2",
45+
"chromedriver": "^2.23.1",
4646
"del": "^2.2.1",
4747
"dmg": "^0.1.0",
4848
"eslint": "^2.10.2",
@@ -54,11 +54,10 @@
5454
"mocha": "^2.4.5",
5555
"portfinder": "^1.0.2",
5656
"request": "^2.69.0",
57-
"selenium-assistant": "0.3.0",
57+
"selenium-assistant": "0.4.0",
5858
"selenium-webdriver": "~2.53.2",
5959
"semver": "^5.1.0",
60-
"temp": "^0.8.3",
61-
"which": "^1.2.9"
60+
"temp": "^0.8.3"
6261
},
6362
"engines": {
6463
"node": ">= v0.10.0"

test/helpers/download-test-browsers.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,50 @@
44
const invalidNodeVersions = /0.(10|12).(\d+)/;
55
if (process.versions.node.match(invalidNodeVersions)) {
66
console.log('Skipping downloading browsers as selenium tests can\'t run on ' + process.versions.node);
7-
return;
7+
return null;
88
}
99

1010
/* eslint-disable global-require*/
1111
const seleniumAssistant = require('selenium-assistant');
1212
/* eslint-enable global-require*/
1313

14+
let forceDownload = false;
15+
if (process.env.TRAVIS) {
16+
forceDownload = true;
17+
}
18+
1419
const promises = [
15-
seleniumAssistant.downloadFirefoxDriver(),
16-
seleniumAssistant.downloadBrowser('firefox', 'stable'),
17-
seleniumAssistant.downloadBrowser('firefox', 'beta'),
18-
seleniumAssistant.downloadBrowser('firefox', 'unstable'),
19-
seleniumAssistant.downloadBrowser('chrome', 'stable'),
20-
seleniumAssistant.downloadBrowser('chrome', 'beta'),
21-
seleniumAssistant.downloadBrowser('chrome', 'unstable')
20+
seleniumAssistant.downloadFirefoxDriver()
21+
.catch(function(err) {
22+
console.error('Firefox Driver Download Error: ', err);
23+
}),
24+
seleniumAssistant.downloadBrowser('firefox', 'stable', forceDownload)
25+
.catch(function(err) {
26+
console.error('Firefox Stable Download Error: ', err);
27+
}),
28+
seleniumAssistant.downloadBrowser('firefox', 'beta', forceDownload)
29+
.catch(function(err) {
30+
console.error('Firefox Beta Download Error: ', err);
31+
}),
32+
seleniumAssistant.downloadBrowser('firefox', 'unstable', forceDownload)
33+
.catch(function(err) {
34+
console.error('Firefox Unstable Download Error: ', err);
35+
}),
36+
seleniumAssistant.downloadBrowser('chrome', 'stable', forceDownload)
37+
.catch(function(err) {
38+
console.error('Chrome Stable Download Error: ', err);
39+
}),
40+
seleniumAssistant.downloadBrowser('chrome', 'beta', forceDownload)
41+
.catch(function(err) {
42+
console.error('Chrome Beta Download Error: ', err);
43+
}),
44+
seleniumAssistant.downloadBrowser('chrome', 'unstable', forceDownload)
45+
.catch(function(err) {
46+
console.error('Chrome Unstable Download Error: ', err);
47+
})
2248
];
2349

24-
Promise.all(promises)
50+
return Promise.all(promises)
2551
.then(function() {
2652
console.log('Download complete.');
2753
});

test/testSelenium.js

Lines changed: 88 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
options = options || {};
4040

4141
if (browser.getSeleniumBrowserId() === 'firefox' &&
42+
browser.getVersionNumber() <= 48 &&
4243
process.env.TRAVIS === 'true') {
4344
console.log('');
4445
console.warn(chalk.red(
@@ -49,6 +50,20 @@
4950
return Promise.resolve();
5051
}
5152

53+
// Works locally, but on Travis breaks. Probably best to wait for next
54+
// ChromeDriver release.
55+
if (browser.getSeleniumBrowserId() === 'chrome' &&
56+
browser.getVersionNumber() === 54 &&
57+
process.env.TRAVIS === 'true') {
58+
console.log('');
59+
console.warn(chalk.red(
60+
'Running on Travis so skipping Chrome V54 tests as ' +
61+
'they don\'t currently work.'
62+
));
63+
console.log('');
64+
return Promise.resolve();
65+
}
66+
5267
return createServer(options, webPush)
5368
.then(function(server) {
5469
globalServer = server;
@@ -87,6 +102,7 @@
87102
const seleniumOptions = browser.getSeleniumOptions();
88103
seleniumOptions.addArguments('user-data-dir=' + tempPreferenceDir + '/');
89104
}
105+
90106
return browser.getSeleniumDriver();
91107
})
92108
.then(function(driver) {
@@ -96,97 +112,87 @@
96112
testServerURL += '?vapid=' + urlBase64.encode(options.vapid.publicKey);
97113
}
98114

99-
// Tests will likely expect a native promise with then and catch
100-
// Not the web driver promise of then and thenCatch
101-
return new Promise(function(resolve, reject) {
102-
globalDriver.get(testServerURL)
103-
.then(function() {
104-
return globalDriver.executeScript(function() {
105-
return typeof navigator.serviceWorker !== 'undefined';
106-
});
107-
})
108-
.then(function(serviceWorkerSupported) {
109-
assert(serviceWorkerSupported);
110-
})
111-
.then(function() {
112-
return globalDriver.wait(function() {
113-
return globalDriver.executeScript(function() {
114-
return typeof window.subscribeSuccess !== 'undefined';
115-
});
116-
});
117-
})
118-
.then(function() {
115+
return globalDriver.get(testServerURL)
116+
.then(function() {
117+
return globalDriver.executeScript(function() {
118+
return typeof navigator.serviceWorker !== 'undefined';
119+
});
120+
})
121+
.then(function(serviceWorkerSupported) {
122+
assert(serviceWorkerSupported);
123+
})
124+
.then(function() {
125+
return globalDriver.wait(function() {
119126
return globalDriver.executeScript(function() {
120-
if (!window.subscribeSuccess) {
121-
return window.subscribeError;
122-
}
123-
124-
return null;
127+
return typeof window.subscribeSuccess !== 'undefined';
125128
});
126-
})
127-
.then(function(subscribeError) {
128-
if (subscribeError) {
129-
console.log('subscribeError: ', subscribeError);
130-
throw subscribeError;
129+
});
130+
})
131+
.then(function() {
132+
return globalDriver.executeScript(function() {
133+
if (!window.subscribeSuccess) {
134+
return window.subscribeError;
131135
}
132136

133-
return globalDriver.executeScript(function() {
134-
return window.testSubscription;
137+
return null;
138+
});
139+
})
140+
.then(function(subscribeError) {
141+
if (subscribeError) {
142+
console.log('subscribeError: ', subscribeError);
143+
throw subscribeError;
144+
}
145+
146+
return globalDriver.executeScript(function() {
147+
return window.testSubscription;
148+
});
149+
})
150+
.then(function(subscription) {
151+
if (!subscription) {
152+
throw new Error('No subscription found.');
153+
}
154+
155+
subscription = JSON.parse(subscription);
156+
157+
let promise;
158+
let pushPayload = null;
159+
let vapid = null;
160+
if (options) {
161+
pushPayload = options.payload;
162+
vapid = options.vapid;
163+
}
164+
165+
if (!pushPayload) {
166+
promise = webPush.sendNotification(subscription.endpoint, {
167+
vapid: vapid
135168
});
136-
})
137-
.then(function(subscription) {
138-
if (!subscription) {
139-
throw new Error('No subscription found.');
140-
}
141-
142-
subscription = JSON.parse(subscription);
143-
144-
let promise;
145-
let pushPayload = null;
146-
let vapid = null;
147-
if (options) {
148-
pushPayload = options.payload;
149-
vapid = options.vapid;
169+
} else {
170+
if (!subscription.keys) {
171+
throw new Error('Require subscription.keys not found.');
150172
}
151173

152-
if (!pushPayload) {
153-
promise = webPush.sendNotification(subscription.endpoint, {
154-
vapid: vapid
155-
});
156-
} else {
157-
if (!subscription.keys) {
158-
throw new Error('Require subscription.keys not found.');
174+
promise = webPush.sendNotification(subscription.endpoint, {
175+
payload: pushPayload,
176+
userPublicKey: subscription.keys.p256dh,
177+
userAuth: subscription.keys.auth,
178+
vapid: vapid
179+
});
180+
}
181+
182+
return promise
183+
.then(function(response) {
184+
if (response.length > 0) {
185+
const data = JSON.parse(response);
186+
if (typeof data.failure !== 'undefined' && data.failure > 0) {
187+
throw new Error('Bad GCM Response: ' + response);
159188
}
160-
161-
promise = webPush.sendNotification(subscription.endpoint, {
162-
payload: pushPayload,
163-
userPublicKey: subscription.keys.p256dh,
164-
userAuth: subscription.keys.auth,
165-
vapid: vapid
166-
});
167189
}
168-
169-
return promise
170-
.then(function(response) {
171-
if (response.length > 0) {
172-
const data = JSON.parse(response);
173-
if (typeof data.failure !== 'undefined' && data.failure > 0) {
174-
throw new Error('Bad GCM Response: ' + response);
175-
}
176-
}
177-
});
178-
})
179-
.then(function() {
180-
const expectedTitle = options.payload ? options.payload : 'no payload';
181-
return globalDriver.wait(function() {
182-
return webdriver.until.titleIs(expectedTitle, 60000);
183-
});
184-
})
185-
.then(function() {
186-
resolve();
187-
})
188-
.thenCatch(function(err) {
189-
reject(err);
190+
});
191+
})
192+
.then(function() {
193+
const expectedTitle = options.payload ? options.payload : 'no payload';
194+
return globalDriver.wait(function() {
195+
return webdriver.until.titleIs(expectedTitle, 60000);
190196
});
191197
});
192198
});

0 commit comments

Comments
 (0)