Prepare for ci
This commit is contained in:
28
test/test.js
28
test/test.js
@@ -1,10 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/* jshint esversion: 8 */
|
||||
/* global describe */
|
||||
/* global before */
|
||||
/* global after */
|
||||
/* global it */
|
||||
/* global it, xit, describe, before, after, afterEach */
|
||||
|
||||
'use strict';
|
||||
|
||||
@@ -12,6 +8,7 @@ require('chromedriver');
|
||||
|
||||
const execSync = require('child_process').execSync,
|
||||
expect = require('expect.js'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
{ Builder, By, Key, until } = require('selenium-webdriver'),
|
||||
{ Options } = require('selenium-webdriver/chrome');
|
||||
@@ -24,7 +21,7 @@ if (!process.env.USERNAME || !process.env.EMAIL || !process.env.PASSWORD) {
|
||||
describe('Application life cycle test', function () {
|
||||
this.timeout(0);
|
||||
|
||||
const LOCATION = 'test';
|
||||
const LOCATION = process.env.LOCATION || 'test';
|
||||
const TEST_TIMEOUT = 20000;
|
||||
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
||||
const DEVICE_NAME = 'FancyDevice';
|
||||
@@ -39,16 +36,27 @@ describe('Application life cycle test', function () {
|
||||
let athenticated_by_oidc = false;
|
||||
|
||||
before(function () {
|
||||
const options = new Options().windowSize({ width: 1280, height: 1024 });
|
||||
if (process.env.HEADLESS) options.addArguments('headless');
|
||||
|
||||
browser = new Builder().forBrowser('chrome').setChromeOptions(options).build();
|
||||
const chromeOptions = new Options().windowSize({ width: 1280, height: 1024 });
|
||||
if (process.env.CI) chromeOptions.addArguments('no-sandbox', 'disable-dev-shm-usage', 'headless');
|
||||
browser = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
|
||||
if (!fs.existsSync('./screenshots')) fs.mkdirSync('./screenshots');
|
||||
});
|
||||
|
||||
after(function () {
|
||||
browser.quit();
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
if (!process.env.CI || !app) return;
|
||||
|
||||
const currentUrl = await browser.getCurrentUrl();
|
||||
if (!currentUrl.includes(app.domain)) return;
|
||||
expect(this.currentTest.title).to.be.a('string');
|
||||
|
||||
const screenshotData = await browser.takeScreenshot();
|
||||
fs.writeFileSync(`./screenshots/${new Date().getTime()}-${this.currentTest.title.replaceAll(' ', '_')}.png`, screenshotData, 'base64');
|
||||
});
|
||||
|
||||
async function waitForElement(elem) {
|
||||
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
|
||||
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
|
||||
|
Reference in New Issue
Block a user