Skip to content

Commit

Permalink
Create screenshot and upload to CI if an element cannot be found.
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp Hoenisch <[email protected]>
  • Loading branch information
bonomat committed Jul 29, 2021
1 parent 8a520b6 commit 45ea181
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ jobs:
name: Logfiles
path: |
./e2e_tests/bobtimus.log
./e2e_tests/liquid.log
./e2e_tests/electrs.log
./e2e_tests/esplora.log
./e2e_tests/screenshots
build_test_workspace:
strategy:
Expand Down
2 changes: 2 additions & 0 deletions e2e_tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules
/nigiri/config/regtest/
/nigiri/liquid-config/liquidregtest/

screenshots/*
!screenshots/.gitkeep
Empty file added e2e_tests/screenshots/.gitkeep
Empty file.
16 changes: 14 additions & 2 deletions e2e_tests/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Debug from "debug";
import { promises as fsp } from "fs";
import fetch from "node-fetch";
import { Builder, By, until, WebDriver } from "selenium-webdriver";
import { Driver } from "selenium-webdriver/firefox";
Expand All @@ -7,8 +8,14 @@ const firefox = require("selenium-webdriver/firefox");
const firefoxPath = require("geckodriver").path;

const getElementById = async (driver, xpath, timeout = 4000) => {
const el = await driver.wait(until.elementLocated(By.xpath(xpath)), timeout);
return await driver.wait(until.elementIsVisible(el), timeout);
try {
const el = await driver.wait(until.elementLocated(By.xpath(xpath)), timeout);
return await driver.wait(until.elementIsVisible(el), timeout);
} catch (e) {
const filename = xpath.replace(/[^\w\s]/gi, "");
await takeScreenshot(driver, `./screenshots/error-${filename}.png`);
throw e;
}
};

const setupBrowserWithExtension = async (webAppUrl: string) => {
Expand Down Expand Up @@ -112,4 +119,9 @@ async function switchToWindow(driver: WebDriver, name: string) {
await driver.switchTo().window(await getWindowHandle(driver, name));
}

async function takeScreenshot(driver, file) {
let image = await driver.takeScreenshot();
await fsp.writeFile(file, image, "base64");
}

export { faucet, getElementById, setupBrowserWithExtension, setupTestingWallet, switchToWindow, unlockWallet };

0 comments on commit 45ea181

Please sign in to comment.