From 544f54e19e963e224a7835c2b22b49eeb01354d2 Mon Sep 17 00:00:00 2001 From: "Xenos F." Date: Wed, 6 Nov 2024 05:46:35 +0800 Subject: [PATCH] Adjust system test --- .github/workflows/system-test.yml | 5 +++-- test/HomePage.test.js | 11 +++++------ test/utils.js | 22 +++++++++++++--------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.github/workflows/system-test.yml b/.github/workflows/system-test.yml index 609fd2e5d4..652f13d09b 100644 --- a/.github/workflows/system-test.yml +++ b/.github/workflows/system-test.yml @@ -63,6 +63,7 @@ jobs: cd client npm ci npm run start & - sleep 2 - name: Run Tests - run: xvfb-run --server-args="-screen 0 1024x768x24" npm run test + run: | + sleep 20 + xvfb-run --server-args="-screen 0 1024x768x24" npm run test diff --git a/test/HomePage.test.js b/test/HomePage.test.js index 759610a125..09492e2645 100644 --- a/test/HomePage.test.js +++ b/test/HomePage.test.js @@ -1,15 +1,14 @@ -let utils = require("./utils"); +let {TIMEOUT, getWebDriver, URL} = require("./utils"); const {By} = require('selenium-webdriver') let driver; -const url = "http://localhost:3000" beforeAll(async () => { - driver = await utils.getWebDriver(); -}, 10000); + driver = await getWebDriver(); +}, TIMEOUT); beforeEach(async () => { - await driver.get(url); + await driver.get(URL); }); afterAll(async () => { @@ -20,6 +19,6 @@ test('clicking "PeerPrep" text in toolbar navigates to homepage', async () => { let link = await driver.findElement(By.linkText("PeerPrep")); await link.click(); let newUrl = await driver.getCurrentUrl(); - expect(newUrl).toMatch(url); + expect(newUrl).toMatch(URL); }); diff --git a/test/utils.js b/test/utils.js index 0ba9fdebc3..d1ae8cefbd 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,13 +1,17 @@ -const {Builder} = require("selenium-webdriver"); +const { Builder } = require("selenium-webdriver"); + +module.exports.TIMEOUT = 30 * 1000; + +module.exports.URL = "http://localhost:3000"; module.exports.getWebDriver = async () => { - let browser = process.env.BROWSER; - let driver = await new Builder().forBrowser(browser).build(); - console.log(driver) - return driver; -} + let browser = process.env.BROWSER; + let driver = await new Builder().forBrowser(browser).build(); + console.log(driver); + return driver; +}; module.exports.scrollTo = async (driver, element) => { - driver.executeScript("arguments[0].scrollIntoView(false)", element); - driver.sleep(300); -} \ No newline at end of file + driver.executeScript("arguments[0].scrollIntoView(false)", element); + driver.sleep(300); +};