Skip to content

Commit

Permalink
Try to fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Nov 19, 2024
1 parent 149bc8d commit 4ece7a3
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
66 changes: 66 additions & 0 deletions packages/admin/test/guiHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const puppeteer = require('puppeteer');
const { blue, cyan, red, yellow } = require('colorette');
const fs = require('node:fs');

let rootDir = `${__dirname}/../`;
let gBrowser;
let gPage;

async function startBrowser(headless) {
const browser = await puppeteer.launch({
headless: headless === undefined ? false : headless,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
});
const pages = await browser.pages();
const timeout = 5000;
pages[0].setDefaultTimeout(timeout);

await pages[0].setViewport({
width: 1920,
height: 1080,
deviceScaleFactor: 1,
});

gBrowser = browser;
gPage = pages[0];

// LOGGING
gPage
.on('console', message => {
const type = message.type().substr(0, 3).toUpperCase();
const colors = {
LOG: text => text,
ERR: red,
WAR: yellow,
INF: cyan,
};

const color = colors[type] || blue;
console.log(color(`[BROWSER] ${type} ${message.text()}`));
})
.on('pageerror', ({ message }) => console.log(red(`[BROWSER] ${message}`)));

await gPage.goto(`http://127.0.0.1:18081`, { waitUntil: 'domcontentloaded' });

// Create directory
!fs.existsSync(`${rootDir}tmp/screenshots`) && fs.mkdirSync(`${rootDir}tmp/screenshots`);
await gPage.screenshot({ path: `${rootDir}tmp/screenshots/00_starting.png` });

return { browser, page: pages[0] };
}

async function stopBrowser(browser) {
browser = browser || gBrowser;
await browser.close();
}

async function screenshot(page, fileName) {
page = page || gPage;
await page.screenshot({ path: `${rootDir}tmp/screenshots/${fileName}.png` });
}

module.exports = {
startBrowser,
stopBrowser,
screenshot,
};
12 changes: 8 additions & 4 deletions packages/admin/test/testAdapter.gui.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
const engineHelper = require('./engineHelper');
const guiHelper = require('@iobroker/legacy-testing/guiHelper');
const guiHelper = require('./guiHelper');

let gPage;
const rootDir = `${__dirname}/../`;

async function screenshot(page, fileName) {
page = page || gPage;
await page.screenshot({ path: `${__dirname}/../tmp/screenshots/${fileName}.png` });
}

describe('admin-gui', () => {
before(async function () {
this.timeout(240_000);

// install js-controller, web and vis-2-beta
await engineHelper.startIoBroker();
const { page } = await guiHelper.startBrowser(null, rootDir, process.env.CI === 'true', '/');
const { page } = await guiHelper.startBrowser(process.env.CI === 'true');
gPage = page;
});

it('Check all widgets', async function () {
this.timeout(120_000);
await gPage.waitForSelector('a[href="/#easy"]', { timeout: 120_000 });
await guiHelper.screenshot(rootDir, gPage, '01_started');
await screenshot(gPage, '00_started');
});

after(async function () {
Expand Down

0 comments on commit 4ece7a3

Please sign in to comment.