From bcde4b30d6bf1efdcd51b77cbb2f299ee1f8358c Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Thu, 3 Oct 2024 18:23:28 +0200 Subject: [PATCH] add ci files --- test/test.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/test/test.js b/test/test.js index eae8eb7..621113d 100644 --- a/test/test.js +++ b/test/test.js @@ -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'; @@ -28,24 +24,38 @@ 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 = parseInt(process.env.TIMEOUT, 10) || 30000; const BUCKET = 'cloudrontestbucket'; const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }; let browser, app; let athenticated_by_oidc = false, rootPassword; - 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'); + }); + async function waitForElement(elem) { await browser.wait(until.elementLocated(elem), TEST_TIMEOUT); await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);