Skip to content
Snippets Groups Projects
Commit bf8c4a6e authored by Atte Keinänen's avatar Atte Keinänen
Browse files

First version of an improved E2E testing workflow

parent 651fde00
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env node
const exec = require('child_process').exec
const execSync = require('child_process').execSync
const fs = require('fs');
const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
// User input initialization
const stdin = fs.openSync('/dev/stdin', 'rs');
const buffer = Buffer.alloc(8);
// Yarn must be executed from project root
process.chdir(__dirname + '/../..');
const url = 'http://localhost:9515';
const driverProcess = exec('chromedriver --port=9515');
var options = new chrome.Options().
addExtensions("frontend/test/selector-picker-chrome-extension.crx");
const driver = new webdriver.Builder()
.forBrowser('chrome')
.usingServer(url)
.setChromeOptions(options)
.build();
driver.getSession().then(function(session) {
const id = session.getId()
console.log('Launched persistent Webdriver session with session ID ' + id, url);
function executeTest() {
if (process.argv.length >= 4 && process.argv[2] === '--exec-before') {
console.log(execSync(process.argv[3]).toString())
}
const cmd = 'WEBDRIVER_SESSION_ID=' + id + ' WEBDRIVER_SESSION_URL=' + url + ' yarn run test-e2e';
console.log(cmd);
const testProcess = exec(cmd);
testProcess.stdout.pipe(process.stdout);
testProcess.stderr.pipe(process.stderr);
testProcess.on('exit', function() {
console.log("Press <Enter> to rerun tests or <C-c> to quit.")
fs.readSync(stdin, buffer, 0, 8);
executeTest();
})
}
executeTest();
});
process.on('SIGTERM', function () {
console.log('Shutting down...')
driver.quit().then(function() { process.exit(0) });
driverProcess.kill('SIGINT');
});
......@@ -12,7 +12,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
describeE2E("auth/login", () => {
let sessionId;
describe("has no cookie", () => {
fdescribe("has no cookie", () => {
beforeEach(async () => {
await driver.get(`${server.host}/`);
await driver.manage().deleteAllCookies();
......
import { Builder } from "selenium-webdriver";
import { Builder, WebDriver } from "selenium-webdriver";
import { USE_SAUCE, sauceCapabilities, sauceServer } from './sauce';
import createSharedResource from "./shared-resource";
const SESSION_URL = process.env["WEBDRIVER_SESSION_URL"];
const SESSION_ID = process.env["WEBDRIVER_SESSION_ID"];
const USE_EXISTING_SESSION = SESSION_URL && SESSION_ID;
export const getConfig = ({ name }) => {
if (USE_SAUCE) {
return {
......@@ -35,24 +39,36 @@ export const WebdriverResource = createSharedResource("WebdriverResource", {
},
async start(webdriver) {
if (!webdriver.driver) {
let builder = new Builder();
if (webdriver.config.capabilities) {
builder.withCapabilities(webdriver.config.capabilities);
}
if (webdriver.config.server) {
builder.usingServer(webdriver.config.server);
}
if (webdriver.config.browser) {
builder.forBrowser(webdriver.config.browser);
if (USE_EXISTING_SESSION) {
const _http = require('selenium-webdriver/http');
const client = new _http.HttpClient(SESSION_URL, null, null);
const executor = new _http.Executor(client);
webdriver.driver = await WebDriver.attachToSession(executor, SESSION_ID);
} else {
let builder = new Builder();
if (webdriver.config.capabilities) {
builder.withCapabilities(webdriver.config.capabilities);
}
if (webdriver.config.server) {
builder.usingServer(webdriver.config.server);
}
if (webdriver.config.browser) {
builder.forBrowser(webdriver.config.browser);
}
webdriver.driver = builder.build();
}
webdriver.driver = builder.build();
}
},
async stop(webdriver) {
if (webdriver.driver) {
const driver = webdriver.driver;
delete webdriver.driver;
await driver.quit();
if (!USE_EXISTING_SESSION) {
await driver.quit();
}
}
}
});
File added
......@@ -151,6 +151,7 @@
"test": "karma start frontend/test/karma.conf.js --single-run",
"test-watch": "karma start frontend/test/karma.conf.js --auto-watch --reporters nyan",
"test-e2e": "JASMINE_CONFIG_PATH=./frontend/test/e2e/support/jasmine.json jasmine",
"test-e2e-dev": "./frontend/test/e2e-with-persistent-browser.js",
"test-e2e-sauce": "USE_SAUCE=true yarn run test-e2e",
"build": "webpack --bail",
"build-watch": "webpack --watch",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment