|
39 | 39 | options = options || {};
|
40 | 40 |
|
41 | 41 | if (browser.getSeleniumBrowserId() === 'firefox' &&
|
| 42 | + browser.getVersionNumber() <= 48 && |
42 | 43 | process.env.TRAVIS === 'true') {
|
43 | 44 | console.log('');
|
44 | 45 | console.warn(chalk.red(
|
|
49 | 50 | return Promise.resolve();
|
50 | 51 | }
|
51 | 52 |
|
| 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 | + |
52 | 67 | return createServer(options, webPush)
|
53 | 68 | .then(function(server) {
|
54 | 69 | globalServer = server;
|
|
87 | 102 | const seleniumOptions = browser.getSeleniumOptions();
|
88 | 103 | seleniumOptions.addArguments('user-data-dir=' + tempPreferenceDir + '/');
|
89 | 104 | }
|
| 105 | + |
90 | 106 | return browser.getSeleniumDriver();
|
91 | 107 | })
|
92 | 108 | .then(function(driver) {
|
|
96 | 112 | testServerURL += '?vapid=' + urlBase64.encode(options.vapid.publicKey);
|
97 | 113 | }
|
98 | 114 |
|
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() { |
119 | 126 | return globalDriver.executeScript(function() {
|
120 |
| - if (!window.subscribeSuccess) { |
121 |
| - return window.subscribeError; |
122 |
| - } |
123 |
| - |
124 |
| - return null; |
| 127 | + return typeof window.subscribeSuccess !== 'undefined'; |
125 | 128 | });
|
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; |
131 | 135 | }
|
132 | 136 |
|
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 |
135 | 168 | });
|
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.'); |
150 | 172 | }
|
151 | 173 |
|
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); |
159 | 188 | }
|
160 |
| - |
161 |
| - promise = webPush.sendNotification(subscription.endpoint, { |
162 |
| - payload: pushPayload, |
163 |
| - userPublicKey: subscription.keys.p256dh, |
164 |
| - userAuth: subscription.keys.auth, |
165 |
| - vapid: vapid |
166 |
| - }); |
167 | 189 | }
|
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); |
190 | 196 | });
|
191 | 197 | });
|
192 | 198 | });
|
|
0 commit comments