mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-03-22 19:05:56 -04:00
Fix GH-1420 Issue/refactor helper functions (#1458)
* put helper functions in separate file following Paul's style in scratch-gui * remove console statements * address review comments, object destructuring
This commit is contained in:
parent
6dc5bfa788
commit
f232569355
4 changed files with 100 additions and 65 deletions
test
helpers
integration/smoke-testing
63
test/helpers/selenium-helpers.js
Normal file
63
test/helpers/selenium-helpers.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
const webdriver = require('selenium-webdriver');
|
||||
|
||||
const driver = new webdriver.Builder()
|
||||
.forBrowser('chrome')
|
||||
.build();
|
||||
|
||||
const {By, until} = webdriver;
|
||||
|
||||
const findByXpath = (xpath) => {
|
||||
return driver.wait(until.elementLocated(By.xpath(xpath), 5 * 1000));
|
||||
};
|
||||
|
||||
const clickXpath = (xpath) => {
|
||||
return findByXpath(xpath).then(el => el.click());
|
||||
};
|
||||
|
||||
const clickText = (text) => {
|
||||
return clickXpath(`//*[contains(text(), '${text}')]`);
|
||||
};
|
||||
|
||||
const clickButton = (text) => {
|
||||
return clickXpath(`//button[contains(text(), '${text}')]`);
|
||||
};
|
||||
|
||||
const findByCss = (css) => {
|
||||
return driver.wait(until.elementLocated(By.css(css), 1000 * 5));
|
||||
};
|
||||
|
||||
const getLogs = (whitelist) => {
|
||||
return driver.manage()
|
||||
.logs()
|
||||
.get('browser')
|
||||
.then((entries) => {
|
||||
return entries.filter((entry) => {
|
||||
const message = entry.message;
|
||||
for (let i = 0; i < whitelist.length; i++) {
|
||||
if (message.indexOf(whitelist[i]) !== -1) {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.warn('Ignoring whitelisted error: ' + whitelist[i]);
|
||||
return false;
|
||||
} else if (entry.level !== 'SEVERE') {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.warn('Ignoring non-SEVERE entry: ' + message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
webdriver,
|
||||
By,
|
||||
until,
|
||||
driver,
|
||||
clickXpath,
|
||||
findByXpath,
|
||||
clickText,
|
||||
clickButton,
|
||||
findByCss,
|
||||
getLogs
|
||||
};
|
|
@ -5,34 +5,20 @@
|
|||
*
|
||||
*/
|
||||
|
||||
const {
|
||||
clickText,
|
||||
findByXpath,
|
||||
clickXpath,
|
||||
clickButton,
|
||||
driver
|
||||
} = require('../../helpers/selenium-helpers.js');
|
||||
|
||||
var username = process.env.SMOKE_USERNAME;
|
||||
var password = process.env.SMOKE_PASSWORD;
|
||||
|
||||
|
||||
var tap = require('tap');
|
||||
const test = tap.test;
|
||||
const webdriver = require('selenium-webdriver');
|
||||
const By = webdriver.By;
|
||||
const until = webdriver.until;
|
||||
|
||||
const driver = new webdriver.Builder()
|
||||
.forBrowser('chrome')
|
||||
.build();
|
||||
|
||||
const findByXpath = (xpath) => {
|
||||
return driver.wait(until.elementLocated(By.xpath(xpath), 5 * 1000));
|
||||
};
|
||||
|
||||
const clickXpath = (xpath) => {
|
||||
return findByXpath(xpath).then(el => el.click());
|
||||
};
|
||||
|
||||
const clickText = (text) => {
|
||||
return clickXpath(`//*[contains(text(), '${text}')]`);
|
||||
};
|
||||
|
||||
const clickButton = (text) => {
|
||||
return clickXpath(`//button[contains(text(), '${text}')]`);
|
||||
};
|
||||
|
||||
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
||||
var url = rootUrl + '/users/anyuser';
|
||||
|
|
|
@ -1,27 +1,22 @@
|
|||
/*
|
||||
* Tests signing in according to smoke-tests at:
|
||||
*
|
||||
* https://github.com/LLK/scratchr2/wiki/Smoke-Testing-Test-Cases
|
||||
*
|
||||
*/
|
||||
|
||||
const {
|
||||
clickText,
|
||||
findByXpath,
|
||||
clickXpath,
|
||||
driver
|
||||
} = require('../../helpers/selenium-helpers.js');
|
||||
|
||||
var username = process.env.SMOKE_USERNAME;
|
||||
var password = process.env.SMOKE_PASSWORD;
|
||||
|
||||
var tap = require('tap');
|
||||
const test = tap.test;
|
||||
const webdriver = require('selenium-webdriver');
|
||||
const By = webdriver.By;
|
||||
const until = webdriver.until;
|
||||
|
||||
const driver = new webdriver.Builder()
|
||||
.forBrowser('chrome')
|
||||
.build();
|
||||
|
||||
const findByXpath = (xpath) => {
|
||||
return driver.wait(until.elementLocated(By.xpath(xpath), 5 * 1000));
|
||||
};
|
||||
|
||||
const clickXpath = (xpath) => {
|
||||
return findByXpath(xpath).then(el => el.click());
|
||||
};
|
||||
|
||||
const clickText = (text) => {
|
||||
return clickXpath(`//*[contains(text(), '${text}')]`);
|
||||
};
|
||||
|
||||
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
||||
|
||||
|
|
|
@ -1,28 +1,19 @@
|
|||
/*
|
||||
* Tests stats page according to smoke-tests at:
|
||||
*
|
||||
* https://github.com/LLK/scratchr2/wiki/Smoke-Testing-Test-Cases
|
||||
*
|
||||
*/
|
||||
|
||||
const {
|
||||
clickText,
|
||||
findByXpath,
|
||||
findByCss,
|
||||
driver
|
||||
} = require('../../helpers/selenium-helpers.js');
|
||||
|
||||
var tap = require('tap');
|
||||
const test = tap.test;
|
||||
const webdriver = require('selenium-webdriver');
|
||||
const By = webdriver.By;
|
||||
const until = webdriver.until;
|
||||
|
||||
const driver = new webdriver.Builder()
|
||||
.forBrowser('chrome')
|
||||
.build();
|
||||
|
||||
const findByXpath = (xpath) => {
|
||||
return driver.wait(until.elementLocated(By.xpath(xpath), 1000 * 5));
|
||||
};
|
||||
|
||||
const findByCss = (css) => {
|
||||
return driver.wait(until.elementLocated(By.css(css), 1000 * 5));
|
||||
};
|
||||
|
||||
const clickXpath = (xpath) => {
|
||||
return findByXpath(xpath).then(el => el.click());
|
||||
};
|
||||
|
||||
const clickText = (text) => {
|
||||
return clickXpath(`//*[contains(text(), '${text}')]`);
|
||||
};
|
||||
|
||||
tap.plan(2);
|
||||
|
||||
|
|
Loading…
Reference in a new issue