diff --git a/test/helpers/selenium-helper.js b/test/helpers/selenium-helper.js new file mode 100644 index 0000000000000000000000000000000000000000..cb2ad19371450658a5b0c76916fcd81ae53b2a0d --- /dev/null +++ b/test/helpers/selenium-helper.js @@ -0,0 +1,68 @@ +/* eslint-env jest */ +jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; // eslint-disable-line no-undef + +import bindAll from 'lodash.bindall'; +import webdriver from 'selenium-webdriver'; + +const {By, until} = webdriver; + +class SeleniumHelper { + constructor () { + bindAll(this, [ + 'clickText', + 'clickButton', + 'clickXpath', + 'findByXpath', + 'getDriver', + 'getLogs' + ]); + } + + getDriver () { + this.driver = new webdriver.Builder() + .forBrowser('chrome') + .build(); + return this.driver; + } + + findByXpath (xpath) { + return this.driver.wait(until.elementLocated(By.xpath(xpath), 5 * 1000)); + } + + clickXpath (xpath) { + return this.findByXpath(xpath).then(el => el.click()); + } + + clickText (text) { + return this.clickXpath(`//*[contains(text(), '${text}')]`); + } + + clickButton (text) { + return this.clickXpath(`//button[contains(text(), '${text}')]`); + } + + getLogs (whitelist) { + return this.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; + }); + }); + } +} + +export default SeleniumHelper; diff --git a/test/helpers/selenium-helpers.js b/test/helpers/selenium-helpers.js deleted file mode 100644 index 909f3a1553eaca14269f494216a1f55140aff87e..0000000000000000000000000000000000000000 --- a/test/helpers/selenium-helpers.js +++ /dev/null @@ -1,58 +0,0 @@ -/* eslint-env jest */ -jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; // eslint-disable-line no-undef - -import webdriver from 'selenium-webdriver'; - -const {By, until} = webdriver; - -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}')]`); -}; - -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; - }); - }); -}; - -export { - clickText, - clickButton, - clickXpath, - driver, - findByXpath, - getLogs -}; diff --git a/test/integration/examples.test.js b/test/integration/examples.test.js new file mode 100644 index 0000000000000000000000000000000000000000..2982fc39c12eb2d19e86023eb5044ac396ea2d16 --- /dev/null +++ b/test/integration/examples.test.js @@ -0,0 +1,63 @@ +/* eslint-env jest */ +/* globals Promise */ + +import path from 'path'; +import SeleniumHelper from '../helpers/selenium-helper'; + +const { + clickXpath, + getDriver, + getLogs +} = new SeleniumHelper(); + +const errorWhitelist = [ + 'The play() request was interrupted by a call to pause()' +]; + +let driver; + +describe('player example', () => { + const uri = path.resolve(__dirname, '../../build/player.html'); + + beforeAll(() => { + driver = getDriver(); + }); + + afterAll(async () => { + await driver.quit(); + }); + + test('Load a project by ID', async () => { + const projectId = '96708228'; + await driver.get('file://' + uri + '#' + projectId); + await new Promise(resolve => setTimeout(resolve, 2000)); + await clickXpath('//img[@title="Go"]'); + await new Promise(resolve => setTimeout(resolve, 2000)); + await clickXpath('//img[@title="Stop"]'); + const logs = await getLogs(errorWhitelist); + await expect(logs).toEqual([]); + }); +}); + +describe('blocks example', () => { + const uri = path.resolve(__dirname, '../../build/blocks-only.html'); + + beforeAll(() => { + driver = getDriver(); + }); + + afterAll(async () => { + await driver.quit(); + }); + + test('Load a project by ID', async () => { + const projectId = '96708228'; + await driver.get('file://' + uri + '#' + projectId); + await new Promise(resolve => setTimeout(resolve, 2000)); + await clickXpath('//img[@title="Go"]'); + await new Promise(resolve => setTimeout(resolve, 2000)); + await clickXpath('//img[@title="Stop"]'); + const logs = await getLogs(errorWhitelist); + await expect(logs).toEqual([]); + }); +}); diff --git a/test/integration/test.js b/test/integration/test.js index 7e3e60a651a6e7d64f06ad56c561058449432f20..0a9bda512641bf701b4af6f068f56053b5aabc55 100644 --- a/test/integration/test.js +++ b/test/integration/test.js @@ -2,14 +2,16 @@ /* globals Promise */ import path from 'path'; -import { +import SeleniumHelper from '../helpers/selenium-helper'; + +const { clickText, clickButton, clickXpath, - driver, findByXpath, + getDriver, getLogs -} from '../helpers/selenium-helpers'; +} = new SeleniumHelper(); const uri = path.resolve(__dirname, '../../build/index.html'); @@ -17,7 +19,13 @@ const errorWhitelist = [ 'The play() request was interrupted by a call to pause()' ]; +let driver; + describe('costumes, sounds and variables', () => { + beforeAll(() => { + driver = getDriver(); + }); + afterAll(async () => { await driver.quit(); });