From 4b50754ed2490ab425f5467c49b23a64200b7181 Mon Sep 17 00:00:00 2001 From: Ryan Chia Date: Tue, 12 Nov 2024 17:35:37 +0800 Subject: [PATCH] Squashed commit of the following: commit 196329a8a96e5a5742e8e4c733133388719e8b43 Author: Ryan Chia Date: Tue Nov 12 17:25:34 2024 +0800 remove webdriver working workflow commit 1add73da99db880d598f11dd2164d7c9346cdbd1 Author: Ryan Chia Date: Tue Nov 12 17:16:25 2024 +0800 asd commit 974caa60ad0657ddcb2e8c35f3a9136d16901f54 Author: Ryan Chia Date: Tue Nov 12 16:09:05 2024 +0800 asad commit f1e3deb88ffb4d02ea53d77785d1477aaef6e7c9 Merge: 5dbc8a0 77f62db Author: Ryan Chia Date: Tue Nov 12 16:04:54 2024 +0800 Merge branch 'browser-compatibility-tests' into browser-tests commit 5dbc8a083ddd10f7ba2065843e88feea63df9e6e Author: Ryan Chia Date: Tue Nov 12 15:50:20 2024 +0800 asd --- .github/workflows/test.yml | 9 +++- .../__tests__/browser-tests/browser.test.ts | 46 ++++++++++++++----- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 13bcff8e10..06afbd05a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -237,8 +237,15 @@ jobs: uses: nanasess/setup-chromedriver@v2 with: chromedriver-version: '130.0.6723.116' + - name: Install Edge + uses: browser-actions/setup-edge@v1 + with: + edge-version: stable + - name: Install Geckodriver + uses: browser-actions/setup-geckodriver@latest + - name: Run Browser Test run: | cd ./apps/frontend - pnpm browser-test \ No newline at end of file + pnpm browser-test diff --git a/apps/frontend/__tests__/browser-tests/browser.test.ts b/apps/frontend/__tests__/browser-tests/browser.test.ts index a80c55d645..145c036b81 100644 --- a/apps/frontend/__tests__/browser-tests/browser.test.ts +++ b/apps/frontend/__tests__/browser-tests/browser.test.ts @@ -1,30 +1,53 @@ -import { Actions, Browser, Builder, By, Key, until, WebDriver } from "selenium-webdriver" +import { Actions, Browser, Builder, By, Capabilities, Key, until, WebDriver } from "selenium-webdriver" + +import {Options as ChromeOptions} from "selenium-webdriver/chrome" +import {Options as EdgeOptions} from "selenium-webdriver/edge" +import {Options as FirefoxOptions} from "selenium-webdriver/firefox" -import Chrome from "selenium-webdriver/chrome" const URL = 'http://localhost:3000/'; const ETERNAL_JWT = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjk5OTk5OTk5OTk5fQ.Z4_FVGQ5lIcouP3m4YLMr6pGMF17IJFfo2yOTiN58DY" -describe("chrome browser", () => { - const options = new Chrome.Options() - .addArguments("--headless=new") as Chrome.Options; // uncomment locally to see the steps in action - const builder = new Builder().forBrowser(Browser.CHROME).setChromeOptions(options); +const CHROME_OPTIONS = new ChromeOptions() + .addArguments("--headless=new") as ChromeOptions; // uncomment locally to see the steps in action +const EDGE_OPTIONS = new EdgeOptions() + .setBinaryPath("/opt/hostedtoolcache/msedge/stable/x64/msedge") // need to point to the correct path + .addArguments("--headless=new") as EdgeOptions; + +const FIREFOX_OPTIONS = new FirefoxOptions() + .addArguments("--headless") as FirefoxOptions; + +const builder = new Builder() + .setChromeOptions(CHROME_OPTIONS) + .setEdgeOptions(EDGE_OPTIONS) + .setFirefoxOptions(FIREFOX_OPTIONS) + +describe.each([Browser.CHROME, Browser.EDGE, Browser.FIREFOX])("%s driver test", (browser) => { let driver: WebDriver; + beforeAll(() => { + const cap = new Capabilities().setBrowserName(browser) + builder.withCapabilities(cap); + }) beforeEach(async () => { + console.log(browser + ": building..."); driver = await builder.build(); - }) + console.log(browser + ": built"); + }, 20000) afterEach(async () => { - await driver.quit(); + if (driver) { + await driver.quit(); + } }) - describe("chrome webdriver installed correctly", () => { + describe("webdriver installed correctly", () => { it("does google search", async () => { await driver.get('http://www.google.com'); await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN); await driver.wait(until.titleIs('webdriver - Google Search'), 1000); }, 10000); - it("does another google search", async () => { + + it.skip("does another google search", async () => { await driver.get('http://www.google.com'); await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN); await driver.wait(until.titleIs('webdriver - Google Search'), 1000); @@ -52,7 +75,8 @@ describe("chrome browser", () => { expect(slogan2).toBe("peers"); }, 10000); }) -}) +}, 60000) +