From 4af7d00620725062530c68c841441defa9a1186d Mon Sep 17 00:00:00 2001 From: Nelson Chan Date: Tue, 23 Nov 2021 22:49:47 +0800 Subject: [PATCH] Test: improve create monitor, add screenshots --- .github/workflows/auto-test.yml | 8 ++++++++ .gitignore | 2 ++ test/e2e.spec.js | 23 +++++++++++++++++++++-- test/screenshots/.gitkeep | 0 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 test/screenshots/.gitkeep diff --git a/.github/workflows/auto-test.yml b/.github/workflows/auto-test.yml index e01c02cee..76f6150ae 100644 --- a/.github/workflows/auto-test.yml +++ b/.github/workflows/auto-test.yml @@ -33,3 +33,11 @@ jobs: env: HEADLESS_TEST: 1 JUST_FOR_TEST: ${{ secrets.JUST_FOR_TEST }} + - name: Upload test artifacts + uses: actions/upload-artifact@v2 + if: always() + with: + name: test-screenshots ${{ matrix.os }} ${{ matrix.node-version }} + path: | + test/screenshots + !test/screenshots/.gitkeep diff --git a/.gitignore b/.gitignore index cd654d903..ae5295871 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ dist-ssr /out /tmp .env + +test/screenshots/ diff --git a/test/e2e.spec.js b/test/e2e.spec.js index 66bbb794b..90a4dca02 100644 --- a/test/e2e.spec.js +++ b/test/e2e.spec.js @@ -14,6 +14,10 @@ page; */ browser; +function convertToValidFilename(string) { + return (string.replace(/[/|\\:*?"<>]/g, " ")); +} + beforeAll(async () => { await page.setViewport({ width: 1280, @@ -26,6 +30,13 @@ afterAll(() => { }); +afterEach(async () => { + const testName = convertToValidFilename(expect.getState().currentTestName); + await page.screenshot({ + path: `./test/screenshots/${testName}.png`, + type: "png" }); +}); + const baseURL = "http://127.0.0.1:3002"; describe("Init", () => { @@ -69,10 +80,17 @@ describe("Init", () => { await page.goto(baseURL + "/add"); await page.waitForSelector("#name"); + await sleep(1000); + await page.type("#name", "Myself"); await page.waitForSelector("#url"); - await page.click("#url", { clickCount: 3 }); - await page.keyboard.type(baseURL); + await page.evaluate(() => { + const urlInput = document.querySelector("#url"); + urlInput.value = ""; + }); + await page.type("#url", baseURL); + + await page.focus("#url"); await page.keyboard.press("Enter"); await page.waitForFunction(() => { @@ -247,6 +265,7 @@ describe("Init", () => { newPage.close(); await click(page, "#enableAuth-btn"); + await login("admin", "admin123"); await page.waitForSelector("#disableAuth-btn", { timeout: 3000 }); }); diff --git a/test/screenshots/.gitkeep b/test/screenshots/.gitkeep new file mode 100644 index 000000000..e69de29bb