Update tests for CI

This commit is contained in:
Girish Ramakrishnan 2024-11-11 17:45:53 +01:00
parent 7bab576c1b
commit f3abbdd291
1 changed files with 20 additions and 9 deletions

View File

@ -1,11 +1,7 @@
#!/usr/bin/env node
/* jshint esversion: 8 */
/* global describe */
/* global before */
/* global after */
/* global it */
/* global xit */
/* global it, xit, describe, before, after, afterEach */
'use strict';
@ -13,6 +9,7 @@ require('chromedriver');
const execSync = require('child_process').execSync,
expect = require('expect.js'),
fs = require('fs'),
path = require('path'),
timers = require('timers/promises'),
{ Builder, By, until } = require('selenium-webdriver'),
@ -26,7 +23,7 @@ if (!process.env.USERNAME || !process.env.PASSWORD) {
describe('Application life cycle test', function () {
this.timeout(0);
const LOCATION = 'test';
const LOCATION = process.env.LOCATION || 'test';
const TEST_TIMEOUT = 30000;
const FOLDER = 'xmf'; // keep this small. long folder names fail in automation, not sure why
const SYNC_PORT = 22001;
@ -34,17 +31,31 @@ describe('Application life cycle test', function () {
let browser, app;
const adminUsername = 'admin', adminPassword = 'changeme';
let username = process.env.USERNAME;
let password = process.env.PASSWORD;
const username = process.env.USERNAME;
const password = process.env.PASSWORD;
before(function () {
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).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');
});
function getAppInfo() {
const inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];