mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-23 07:38:07 -05:00
Merge pull request #1944 from BryceLTaylor/Selenium-Helper-Update
Selenium helper update
This commit is contained in:
commit
bdc2260531
10 changed files with 188 additions and 140 deletions
|
@ -6,8 +6,9 @@
|
||||||
"start": "make start",
|
"start": "make start",
|
||||||
"stop": "make stop",
|
"stop": "make stop",
|
||||||
"test": "make test",
|
"test": "make test",
|
||||||
"smoke": "make smoke",
|
"smoke": "tap ./test/integration/smoke-testing/*.js --timeout=3600",
|
||||||
"smoke-verbose": "make smoke-verbose",
|
"smoke-verbose": "make smoke-verbose",
|
||||||
|
"smoke-sauce": "tap ./test/integration/smoke-testing/*.js --timeout=60000",
|
||||||
"watch": "make watch",
|
"watch": "make watch",
|
||||||
"build": "make build",
|
"build": "make build",
|
||||||
"dev": "make watch && make start &"
|
"dev": "make watch && make start &"
|
||||||
|
|
|
@ -1,8 +1,37 @@
|
||||||
var webdriver = require('selenium-webdriver');
|
const webdriver = require('selenium-webdriver');
|
||||||
|
const bindAll = require('lodash.bindall');
|
||||||
|
|
||||||
const headless = process.env.SMOKE_HEADLESS || false;
|
const headless = process.env.SMOKE_HEADLESS || false;
|
||||||
|
const remote = process.env.SMOKE_REMOTE || false;
|
||||||
|
const {SAUCE_USERNAME, SAUCE_ACCESS_KEY} = process.env;
|
||||||
|
const {By, until} = webdriver;
|
||||||
|
|
||||||
const getDriver = function () {
|
class SeleniumHelper {
|
||||||
|
constructor () {
|
||||||
|
bindAll(this, [
|
||||||
|
'getDriver',
|
||||||
|
'getSauceDriver',
|
||||||
|
'buildDriver',
|
||||||
|
'clickXpath',
|
||||||
|
'findByXpath',
|
||||||
|
'clickText',
|
||||||
|
'findText',
|
||||||
|
'clickButton',
|
||||||
|
'findByCss',
|
||||||
|
'clickCss',
|
||||||
|
'getLogs'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
buildDriver (name) {
|
||||||
|
if (remote === 'true'){
|
||||||
|
this.driver = this.getSauceDriver(SAUCE_USERNAME, SAUCE_ACCESS_KEY, name);
|
||||||
|
} else {
|
||||||
|
this.driver = this.getDriver();
|
||||||
|
}
|
||||||
|
return this.driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
getDriver () {
|
||||||
const chromeCapabilities = webdriver.Capabilities.chrome();
|
const chromeCapabilities = webdriver.Capabilities.chrome();
|
||||||
let args = [];
|
let args = [];
|
||||||
if (headless) {
|
if (headless) {
|
||||||
|
@ -11,47 +40,66 @@ const getDriver = function () {
|
||||||
args.push('--no-sandbox');
|
args.push('--no-sandbox');
|
||||||
}
|
}
|
||||||
chromeCapabilities.set('chromeOptions', {args});
|
chromeCapabilities.set('chromeOptions', {args});
|
||||||
const newDriver = new webdriver.Builder()
|
let driver = new webdriver.Builder()
|
||||||
.forBrowser('chrome')
|
.forBrowser('chrome')
|
||||||
.withCapabilities(chromeCapabilities)
|
.withCapabilities(chromeCapabilities)
|
||||||
.build();
|
.build();
|
||||||
return newDriver;
|
return driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
getSauceDriver (username, accessKey, name) {
|
||||||
|
// Driver configs can be generated with the Sauce Platform Configurator
|
||||||
|
// https://wiki.saucelabs.com/display/DOCS/Platform+Configurator
|
||||||
|
let driverConfig = {
|
||||||
|
browserName: 'chrome',
|
||||||
|
platform: 'macOS 10.13',
|
||||||
|
version: '67.0'
|
||||||
};
|
};
|
||||||
|
var driver = new webdriver.Builder()
|
||||||
|
.withCapabilities({
|
||||||
|
browserName: driverConfig.browserName,
|
||||||
|
platform: driverConfig.platform,
|
||||||
|
version: driverConfig.version,
|
||||||
|
username: username,
|
||||||
|
accessKey: accessKey,
|
||||||
|
name: name
|
||||||
|
})
|
||||||
|
.usingServer(`http://${username}:${accessKey
|
||||||
|
}@ondemand.saucelabs.com:80/wd/hub`)
|
||||||
|
.build();
|
||||||
|
return driver;
|
||||||
|
}
|
||||||
|
|
||||||
const driver = getDriver();
|
findByXpath (xpath) {
|
||||||
|
return this.driver.wait(until.elementLocated(By.xpath(xpath), 5 * 1000));
|
||||||
|
}
|
||||||
|
|
||||||
const {By, until} = webdriver;
|
clickXpath (xpath) {
|
||||||
|
return this.findByXpath(xpath).then(el => el.click());
|
||||||
|
}
|
||||||
|
|
||||||
const findByXpath = (xpath) => {
|
clickText (text) {
|
||||||
return driver.wait(until.elementLocated(By.xpath(xpath), 5 * 1000));
|
return this.clickXpath(`//*[contains(text(), '${text}')]`);
|
||||||
};
|
}
|
||||||
|
|
||||||
const clickXpath = (xpath) => {
|
findText (text) {
|
||||||
return findByXpath(xpath).then(el => el.click());
|
return this.driver.wait(until.elementLocated(By.xpath(`//*[contains(text(), '${text}')]`), 5 * 1000));
|
||||||
};
|
}
|
||||||
|
|
||||||
const clickText = (text) => {
|
clickButton (text) {
|
||||||
return clickXpath(`//*[contains(text(), '${text}')]`);
|
return this.clickXpath(`//button[contains(text(), '${text}')]`);
|
||||||
};
|
}
|
||||||
|
|
||||||
const findText = (text) => {
|
findByCss (css) {
|
||||||
return driver.wait(until.elementLocated(By.xpath(`//*[contains(text(), '${text}')]`), 5 * 1000));
|
return this.driver.wait(until.elementLocated(By.css(css), 1000 * 5));
|
||||||
};
|
}
|
||||||
|
|
||||||
const clickButton = (text) => {
|
clickCss (css) {
|
||||||
return clickXpath(`//button[contains(text(), '${text}')]`);
|
return this.findByCss(css).then(el => el.click());
|
||||||
};
|
}
|
||||||
|
|
||||||
const findByCss = (css) => {
|
getLogs (whitelist) {
|
||||||
return driver.wait(until.elementLocated(By.css(css), 1000 * 5));
|
return this.driver.manage()
|
||||||
};
|
|
||||||
|
|
||||||
const clickCss = (css) => {
|
|
||||||
return findByCss(css).then(el => el.click());
|
|
||||||
};
|
|
||||||
|
|
||||||
const getLogs = (whitelist) => {
|
|
||||||
return driver.manage()
|
|
||||||
.logs()
|
.logs()
|
||||||
.get('browser')
|
.get('browser')
|
||||||
.then((entries) => {
|
.then((entries) => {
|
||||||
|
@ -72,20 +120,8 @@ const getLogs = (whitelist) => {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = {
|
}
|
||||||
webdriver,
|
|
||||||
By,
|
module.exports = SeleniumHelper;
|
||||||
until,
|
|
||||||
driver,
|
|
||||||
clickXpath,
|
|
||||||
findByXpath,
|
|
||||||
clickText,
|
|
||||||
findText,
|
|
||||||
clickButton,
|
|
||||||
findByCss,
|
|
||||||
clickCss,
|
|
||||||
getLogs,
|
|
||||||
getDriver
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,17 +1,22 @@
|
||||||
const {
|
const SeleniumHelper = require('../selenium-helpers.js');
|
||||||
driver,
|
const helper = new SeleniumHelper();
|
||||||
findByCss,
|
|
||||||
clickCss,
|
|
||||||
until
|
|
||||||
} = require('../selenium-helpers.js');
|
|
||||||
|
|
||||||
var username = process.env.SMOKE_USERNAME;
|
|
||||||
var password = process.env.SMOKE_PASSWORD;
|
|
||||||
|
|
||||||
|
|
||||||
var tap = require('tap');
|
var tap = require('tap');
|
||||||
const test = tap.test;
|
const test = tap.test;
|
||||||
|
|
||||||
|
const webdriver = require('selenium-webdriver');
|
||||||
|
const driver = helper.buildDriver('www-smoke test-login-failures');
|
||||||
|
|
||||||
|
const {
|
||||||
|
findByCss,
|
||||||
|
clickCss
|
||||||
|
} = helper;
|
||||||
|
|
||||||
|
var until = webdriver.until;
|
||||||
|
|
||||||
|
var username = process.env.SMOKE_USERNAME;
|
||||||
|
var password = process.env.SMOKE_PASSWORD;
|
||||||
|
|
||||||
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
||||||
var url = rootUrl + '/users/' + username;
|
var url = rootUrl + '/users/' + username;
|
||||||
|
|
||||||
|
|
|
@ -5,21 +5,24 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const SeleniumHelper = require('../selenium-helpers.js');
|
||||||
|
const helper = new SeleniumHelper();
|
||||||
|
|
||||||
|
var tap = require('tap');
|
||||||
|
const test = tap.test;
|
||||||
|
|
||||||
|
const driver = helper.buildDriver('www-smoke test-my-stuff');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
clickText,
|
clickText,
|
||||||
findByXpath,
|
findByXpath,
|
||||||
clickXpath,
|
clickXpath,
|
||||||
clickButton,
|
clickButton
|
||||||
driver
|
} = helper;
|
||||||
} = require('../selenium-helpers.js');
|
|
||||||
|
|
||||||
var username = process.env.SMOKE_USERNAME;
|
var username = process.env.SMOKE_USERNAME;
|
||||||
var password = process.env.SMOKE_PASSWORD;
|
var password = process.env.SMOKE_PASSWORD;
|
||||||
|
|
||||||
|
|
||||||
var tap = require('tap');
|
|
||||||
const test = tap.test;
|
|
||||||
|
|
||||||
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
||||||
var url = rootUrl + '/users/' + username;
|
var url = rootUrl + '/users/' + username;
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,13 @@
|
||||||
* Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows
|
* Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const SeleniumHelper = require('../selenium-helpers.js');
|
||||||
|
const helper = new SeleniumHelper();
|
||||||
|
|
||||||
const tap = require('tap');
|
const tap = require('tap');
|
||||||
|
|
||||||
const {
|
const webdriver = require('selenium-webdriver');
|
||||||
driver,
|
const driver = helper.buildDriver('www-smoke test_footer_links');
|
||||||
webdriver
|
|
||||||
} = require('../selenium-helpers.js');
|
|
||||||
|
|
||||||
// Selenium's promise driver will be deprecated, so we should not rely on it
|
|
||||||
webdriver.SELENIUM_PROMISE_MANAGER = 0;
|
|
||||||
|
|
||||||
const rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
const rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
||||||
|
|
||||||
|
|
|
@ -4,16 +4,13 @@
|
||||||
* Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows
|
* Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require('chromedriver');
|
const SeleniumHelper = require('../selenium-helpers.js');
|
||||||
|
const helper = new SeleniumHelper();
|
||||||
|
|
||||||
const {
|
|
||||||
driver,
|
|
||||||
webdriver
|
|
||||||
} = require('../selenium-helpers.js');
|
|
||||||
var tap = require('tap');
|
var tap = require('tap');
|
||||||
|
|
||||||
// Selenium's promise driver will be deprecated, so we should not rely on it
|
const webdriver = require('selenium-webdriver');
|
||||||
webdriver.SELENIUM_PROMISE_MANAGER = 0;
|
const driver = helper.buildDriver('www-smoke test_navbar_links');
|
||||||
|
|
||||||
// Set test url through environment variable
|
// Set test url through environment variable
|
||||||
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
||||||
|
|
|
@ -5,16 +5,13 @@
|
||||||
* Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows
|
* Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require('chromedriver');
|
const SeleniumHelper = require('../selenium-helpers.js');
|
||||||
|
const helper = new SeleniumHelper();
|
||||||
|
|
||||||
var tap = require('tap');
|
var tap = require('tap');
|
||||||
var seleniumWebdriver = require('selenium-webdriver');
|
|
||||||
|
|
||||||
// Selenium's promise driver will be deprecated, so we should not rely on it
|
const webdriver = require('selenium-webdriver');
|
||||||
seleniumWebdriver.SELENIUM_PROMISE_MANAGER = 0;
|
const driver = helper.buildDriver('www-smoke test_project_rows');
|
||||||
|
|
||||||
const {
|
|
||||||
driver
|
|
||||||
} = require('../selenium-helpers.js');
|
|
||||||
|
|
||||||
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
||||||
|
|
||||||
|
@ -34,7 +31,7 @@ tap.beforeEach(function () {
|
||||||
// checks that the title of the first row is Featured Projects
|
// checks that the title of the first row is Featured Projects
|
||||||
tap.test('checkFeaturedProjectsRowTitleWhenSignedOut', function (t) {
|
tap.test('checkFeaturedProjectsRowTitleWhenSignedOut', function (t) {
|
||||||
var xPathLink = '//div[@class="box"]/div[@class="box-header"]/h4';
|
var xPathLink = '//div[@class="box"]/div[@class="box-header"]/h4';
|
||||||
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
|
driver.findElement(webdriver.By.xpath(xPathLink))
|
||||||
.then(function (element) {
|
.then(function (element) {
|
||||||
element.getText('h4')
|
element.getText('h4')
|
||||||
.then(function (text) {
|
.then(function (text) {
|
||||||
|
@ -51,8 +48,8 @@ tap.test('checkFeaturedProjectsRowLinkWhenSignedOut', function (t) {
|
||||||
var xPathLink = '//div[contains(@class, "thumbnail") ' +
|
var xPathLink = '//div[contains(@class, "thumbnail") ' +
|
||||||
'and contains(@class, "project") and contains(@class, "slick-slide") ' +
|
'and contains(@class, "project") and contains(@class, "slick-slide") ' +
|
||||||
'and contains(@class, "slick-active")]/a[@class="thumbnail-image"]';
|
'and contains(@class, "slick-active")]/a[@class="thumbnail-image"]';
|
||||||
driver.wait(seleniumWebdriver.until
|
driver.wait(webdriver.until
|
||||||
.elementLocated(seleniumWebdriver.By.xpath(xPathLink)))
|
.elementLocated(webdriver.By.xpath(xPathLink)))
|
||||||
.then(function (element) {
|
.then(function (element) {
|
||||||
element.getAttribute('href')
|
element.getAttribute('href')
|
||||||
.then(function (url) {
|
.then(function (url) {
|
||||||
|
@ -68,7 +65,7 @@ tap.test('checkFeaturedProjectsRowLinkWhenSignedOut', function (t) {
|
||||||
// checks that the title of the 2nd row is Featured Studios
|
// checks that the title of the 2nd row is Featured Studios
|
||||||
tap.test('checkFeaturedStudiosRowWhenSignedOut', function (t) {
|
tap.test('checkFeaturedStudiosRowWhenSignedOut', function (t) {
|
||||||
var xPathLink = '//div[@class="box"][2]/div[@class="box-header"]/h4';
|
var xPathLink = '//div[@class="box"][2]/div[@class="box-header"]/h4';
|
||||||
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
|
driver.findElement(webdriver.By.xpath(xPathLink))
|
||||||
.then(function (element) {
|
.then(function (element) {
|
||||||
element.getText('h4')
|
element.getText('h4')
|
||||||
.then(function (text) {
|
.then(function (text) {
|
||||||
|
@ -83,7 +80,7 @@ tap.test('checkFeaturedStudiosRowWhenSignedOut', function (t) {
|
||||||
tap.test('checkFeaturedStudiosRowLinkWhenSignedOut', function (t) {
|
tap.test('checkFeaturedStudiosRowLinkWhenSignedOut', function (t) {
|
||||||
var xPathLink = '//div[contains(@class, "thumbnail") and contains(@class, "gallery") ' +
|
var xPathLink = '//div[contains(@class, "thumbnail") and contains(@class, "gallery") ' +
|
||||||
'and contains(@class, "slick-slide") and contains(@class, "slick-active")]/a[@class="thumbnail-image"]';
|
'and contains(@class, "slick-slide") and contains(@class, "slick-active")]/a[@class="thumbnail-image"]';
|
||||||
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
|
driver.findElement(webdriver.By.xpath(xPathLink))
|
||||||
.then(function (element) {
|
.then(function (element) {
|
||||||
element.getAttribute('href')
|
element.getAttribute('href')
|
||||||
.then(function (url) {
|
.then(function (url) {
|
||||||
|
|
|
@ -5,22 +5,25 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const SeleniumHelper = require('../selenium-helpers.js');
|
||||||
|
const helper = new SeleniumHelper();
|
||||||
|
|
||||||
|
var tap = require('tap');
|
||||||
|
const test = tap.test;
|
||||||
|
|
||||||
|
const driver = helper.buildDriver('www-smoke test_sign_in_out_discuss');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
clickText,
|
clickText,
|
||||||
findByXpath,
|
findByXpath,
|
||||||
findText,
|
findText,
|
||||||
clickXpath,
|
clickXpath,
|
||||||
clickButton,
|
clickButton
|
||||||
driver
|
} = helper;
|
||||||
} = require('../selenium-helpers.js');
|
|
||||||
|
|
||||||
var username = process.env.SMOKE_USERNAME;
|
var username = process.env.SMOKE_USERNAME;
|
||||||
var password = process.env.SMOKE_PASSWORD;
|
var password = process.env.SMOKE_PASSWORD;
|
||||||
|
|
||||||
|
|
||||||
var tap = require('tap');
|
|
||||||
const test = tap.test;
|
|
||||||
|
|
||||||
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
||||||
var url = rootUrl + '/discuss';
|
var url = rootUrl + '/discuss';
|
||||||
|
|
||||||
|
|
|
@ -5,20 +5,24 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const SeleniumHelper = require('../selenium-helpers.js');
|
||||||
|
const helper = new SeleniumHelper();
|
||||||
|
|
||||||
|
var tap = require('tap');
|
||||||
|
const test = tap.test;
|
||||||
|
|
||||||
|
const driver = helper.buildDriver('www-smoke test_sign_in_out_homepage');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
clickText,
|
clickText,
|
||||||
findText,
|
findText,
|
||||||
findByXpath,
|
findByXpath,
|
||||||
clickXpath,
|
clickXpath
|
||||||
driver
|
} = helper;
|
||||||
} = require('../selenium-helpers.js');
|
|
||||||
|
|
||||||
var username = process.env.SMOKE_USERNAME;
|
var username = process.env.SMOKE_USERNAME;
|
||||||
var password = process.env.SMOKE_PASSWORD;
|
var password = process.env.SMOKE_PASSWORD;
|
||||||
|
|
||||||
var tap = require('tap');
|
|
||||||
const test = tap.test;
|
|
||||||
|
|
||||||
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
||||||
|
|
||||||
tap.plan(2);
|
tap.plan(2);
|
||||||
|
|
|
@ -5,16 +5,20 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const {
|
const SeleniumHelper = require('../selenium-helpers.js');
|
||||||
clickText,
|
const helper = new SeleniumHelper();
|
||||||
findByXpath,
|
|
||||||
findByCss,
|
|
||||||
driver
|
|
||||||
} = require('../selenium-helpers.js');
|
|
||||||
|
|
||||||
var tap = require('tap');
|
var tap = require('tap');
|
||||||
const test = tap.test;
|
const test = tap.test;
|
||||||
|
|
||||||
|
const driver = helper.buildDriver('www-smoke test_statistics_page');
|
||||||
|
|
||||||
|
const {
|
||||||
|
clickText,
|
||||||
|
findByXpath,
|
||||||
|
findByCss
|
||||||
|
} = helper;
|
||||||
|
|
||||||
tap.plan(2);
|
tap.plan(2);
|
||||||
|
|
||||||
tap.tearDown(function () {
|
tap.tearDown(function () {
|
||||||
|
|
Loading…
Reference in a new issue