2019-05-31 11:56:07 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2019-05-31 11:56:07 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
const webdriverio = require('webdriverio');
|
|
|
|
const desiredCapabilities = {
|
|
|
|
android60: {
|
|
|
|
deviceName: 'Android GoogleAPI Emulator',
|
|
|
|
browserName: 'Chrome',
|
|
|
|
platformName: 'Android',
|
|
|
|
platformVersion: '6.0',
|
|
|
|
deviceOrientation: 'portrait',
|
|
|
|
appiumVersion: '1.12.1'
|
|
|
|
},
|
|
|
|
android71: {
|
|
|
|
deviceName: 'Android GoogleAPI Emulator',
|
|
|
|
browserName: 'Chrome',
|
|
|
|
platformName: 'Android',
|
|
|
|
platformVersion: '7.1',
|
|
|
|
deviceOrientation: 'portrait',
|
|
|
|
appiumVersion: '1.12.1'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const errors = [];
|
|
|
|
const tasks = [];
|
|
|
|
|
|
|
|
if (process.env.TRAVIS) {
|
|
|
|
process.env.SAUCE_ACCESS_KEY = process.env.SAUCE_ACCESS_KEY.split('').reverse().join('');
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.keys(desiredCapabilities).forEach(key => {
|
|
|
|
console.log('begin webdriver test', key);
|
|
|
|
if (process.env.TRAVIS) {
|
|
|
|
desiredCapabilities[key]['tunnel-identifier'] = process.env.TRAVIS_JOB_NUMBER;
|
|
|
|
}
|
|
|
|
const client = require('webdriverio').remote({
|
|
|
|
user: process.env.SAUCE_USERNAME,
|
|
|
|
key: process.env.SAUCE_ACCESS_KEY,
|
|
|
|
host: 'localhost',
|
|
|
|
port: 4445,
|
|
|
|
desiredCapabilities: desiredCapabilities[key]
|
|
|
|
});
|
|
|
|
|
|
|
|
const p = client.init()
|
|
|
|
.timeouts('script', 60000)
|
|
|
|
.url('http://localhost:8080/test/webdriver/test-es2015.html')
|
2020-04-13 19:40:21 -04:00
|
|
|
.executeAsync(function(done) {
|
|
|
|
window.setTimeout(done, 1000)
|
|
|
|
})
|
2019-05-31 11:56:07 -04:00
|
|
|
.execute(function() {
|
|
|
|
const elem = document.getElementById('thetext');
|
|
|
|
const zone = window['Zone'] ? Zone.current.fork({name: 'webdriver'}) : null;
|
|
|
|
if (zone) {
|
|
|
|
zone.run(function() {
|
|
|
|
elem.addEventListener('click', function(e) {
|
|
|
|
e.target.innerText = 'clicked' + Zone.current.name;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
2020-04-13 19:40:21 -04:00
|
|
|
elem.addEventListener('click', function(e) {
|
|
|
|
e.target.innerText = 'clicked';
|
|
|
|
});
|
2019-05-31 11:56:07 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.click('#thetext')
|
|
|
|
.getText('#thetext')
|
|
|
|
.then(
|
|
|
|
(text => {
|
|
|
|
if (text !== 'clickedwebdriver') {
|
|
|
|
errors.push(`Env: ${key}, expected clickedwebdriver, get ${text}`);
|
|
|
|
}
|
|
|
|
}),
|
2020-04-13 19:40:21 -04:00
|
|
|
(error) => {
|
|
|
|
errors.push(`Env: ${key}, error occurs: ${error}`);
|
|
|
|
})
|
2019-05-31 11:56:07 -04:00
|
|
|
.end();
|
|
|
|
tasks.push(p);
|
|
|
|
});
|
|
|
|
|
|
|
|
function exit(exitCode) {
|
|
|
|
const http = require('http');
|
2020-04-13 19:40:21 -04:00
|
|
|
http.get('http://localhost:8080/close', () => {
|
|
|
|
process.exit(exitCode);
|
|
|
|
});
|
2019-05-31 11:56:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Promise.all(tasks).then(() => {
|
|
|
|
if (errors.length > 0) {
|
|
|
|
let nonTimeoutError = false;
|
|
|
|
errors.forEach(error => {
|
|
|
|
console.log(error);
|
|
|
|
if (error.toString().lastIndexOf('timeout') === -1) {
|
|
|
|
nonTimeoutError = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (nonTimeoutError) {
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
});
|