File size: 3,604 Bytes
cf0f72e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | /*
Copyright 2016 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
'use strict';
/* eslint-disable max-len, no-console, padded-blocks, no-multiple-empty-lines */
/* eslint-env node,mocha */
// These tests make use of selenium-webdriver. You can find the relevant
// documentation here: https://github.com/SeleniumHQ/selenium
const path = require('path');
const seleniumAssistant = require('selenium-assistant');
const mochaUtils = require('sw-testing-helpers').mochaUtils;
require('geckodriver');
require('chromedriver');
require('chai').should();
const testServer = require('./server/index.js');
describe('Test SW-Toolbox', function() {
// Browser tests can be slow
this.timeout(100000);
// Selenium Tests are Flakey
this.retries(3);
// Driver is initialised to `null` to handle scenarios
// where the desired browser isn't installed / fails to load
// `null` allows afterEach a safe way to skip quiting the driver
let globalDriverReference = null;
let testServerURL;
before(function() {
return testServer.startServer(path.join(__dirname, '..'))
.then(portNumber => {
testServerURL = `http://localhost:${portNumber}`;
});
});
after(function() {
testServer.killServer();
});
afterEach(function() {
this.timeout(2 * 60 * 1000);
return seleniumAssistant.killWebDriver(globalDriverReference)
.then(() => {
globalDriverReference = null;
});
});
const queueUnitTest = browserInfo => {
it(`should pass all tests in ${browserInfo.getPrettyName()}`, () => {
return browserInfo.getSeleniumDriver()
.then(driver => {
globalDriverReference = driver;
return mochaUtils.startWebDriverMochaTests(
browserInfo.getPrettyName(),
globalDriverReference,
`${testServerURL}/test/browser-tests/`
);
})
.then(testResults => {
mochaUtils.prettyPrintResults(testResults);
if (testResults.failed.length > 0) {
throw new Error('Tests Failed');
}
});
});
};
const automatedBrowsers = seleniumAssistant.getLocalBrowsers();
automatedBrowsers.forEach(browserInfo => {
// Firefox before version 50 have issues that can't be duplicated outside
// of the selenium test runner.
if (browserInfo.getId() === 'firefox' &&
browserInfo.getVersionNumber() < 50) {
console.log(`Skipping ${browserInfo.getId()}: ${browserInfo.getRawVersionString()}`);
return;
}
// Opera has bad unregister API and it's driver is far from happy
// with latest builds.
if (browserInfo.getId() === 'opera') {
console.log(`Skipping ${browserInfo.getId()}: ${browserInfo.getRawVersionString()}`);
return;
}
// Block browsers w/o Service Worker support from being included in the
// tests on Travis
if (browserInfo.getId() !== 'firefox' &&
browserInfo.getId() !== 'chrome') {
console.log(`Skipping ${browserInfo.getId()}: ${browserInfo.getRawVersionString()}`);
return;
}
queueUnitTest(browserInfo);
});
});
|