-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): add e2e tests setup with playwright and synpress (#502)
* feat(frontend): add e2e tests setup with playwright and synpress * chore(frontend): prepare fathom code before starting frontend in dev mode * chore: install playwright browsers in gh actions environment * chore: trigger ci * chore: prepare fathom before executing playwright * chore: fix test:e2e script * fix(frontend): fix playwright command * chore(frontend): increase timeout for web server start * chore: remove playwright tests from ci gh action --------- Co-authored-by: luzzifoss <fedeluzzi00@gmail.com>
- Loading branch information
Showing
14 changed files
with
2,018 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { test as base, chromium, type BrowserContext } from "@playwright/test"; | ||
import { initialSetup } from "@synthetixio/synpress/commands/metamask"; | ||
import { setExpectInstance } from "@synthetixio/synpress/commands/playwright"; | ||
import { resetState } from "@synthetixio/synpress/commands/synpress"; | ||
import { prepareMetamask } from "@synthetixio/synpress/helpers"; | ||
|
||
export const test = base.extend<{ | ||
context: BrowserContext; | ||
}>({ | ||
context: async ({}, use) => { | ||
// required for synpress as it shares same expect instance as playwright | ||
await setExpectInstance(expect); | ||
|
||
// download metamask | ||
const metamaskPath = await prepareMetamask( | ||
process.env.METAMASK_VERSION || "10.25.0", | ||
); | ||
|
||
// prepare browser args | ||
const browserArgs = [ | ||
`--disable-extensions-except=${metamaskPath}`, | ||
`--load-extension=${metamaskPath}`, | ||
"--remote-debugging-port=9222", | ||
]; | ||
|
||
if (process.env.CI) browserArgs.push("--disable-gpu"); | ||
if (process.env.HEADLESS_MODE) browserArgs.push("--headless=new"); | ||
|
||
// launch browser | ||
const context = await chromium.launchPersistentContext("", { | ||
headless: false, | ||
args: browserArgs, | ||
}); | ||
|
||
// wait for metamask | ||
await context.pages()[0].waitForTimeout(3000); | ||
|
||
// setup metamask | ||
await initialSetup(chromium, { | ||
secretWordsOrPrivateKey: | ||
"test test test test test test test test test test test junk", | ||
network: "sepolia", | ||
password: "Tester@1234", | ||
enableAdvancedSettings: true, | ||
}); | ||
|
||
await use(context); | ||
|
||
await context.close(); | ||
|
||
await resetState(); | ||
}, | ||
}); | ||
|
||
export const expect = test.expect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { test, expect } from "../fixtures"; | ||
import { acceptAccess } from "@synthetixio/synpress/commands/metamask"; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto("/"); | ||
}); | ||
|
||
test("connect with metamask", async ({ page }) => { | ||
await test.step("select network drop down", async () => { | ||
await page.locator("div").getByText("Network").nth(2).click(); | ||
}); | ||
|
||
await test.step("click sepolia network", async () => { | ||
await page.getByTestId("Sepolia-network-button").nth(1).click(); | ||
}); | ||
|
||
await test.step("click connect wallet", async () => { | ||
await page.getByTestId("connect-wallet-button").nth(1).click(); | ||
}); | ||
|
||
await test.step("click metamask", async () => { | ||
await page.getByTestId("metaMask-wallet-button").nth(1).click(); | ||
}); | ||
|
||
await test.step("connect to metamask", async () => { | ||
await acceptAccess(); | ||
}); | ||
|
||
await test.step("verify wallet is connected", async () => { | ||
await expect( | ||
page.getByTestId("profile-avatar-button").nth(1), | ||
).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { test } from "../fixtures"; | ||
|
||
test("home page", async ({ page }) => { | ||
await test.step("navigate to home page", async () => { | ||
await page.goto("/"); | ||
}); | ||
|
||
await test.step("about visible", async () => { | ||
await page.locator("div").getByText("About`").nth(1).isVisible(); | ||
}); | ||
|
||
await test.step("campaigns visible", async () => { | ||
await page.locator("div").getByText("Campaign").nth(1).isVisible(); | ||
}); | ||
|
||
await test.step("connect wallet button visible", async () => { | ||
await page | ||
.locator("div") | ||
.getByText("Connect wallet") | ||
.nth(1) | ||
.isVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
export default defineConfig({ | ||
timeout: 60_000, | ||
testDir: "./e2e", | ||
fullyParallel: true, | ||
forbidOnly: !!process.env.CI, | ||
retries: process.env.CI ? 2 : 0, | ||
workers: process.env.CI ? 1 : 1, | ||
reporter: process.env.CI ? "dot" : "list", | ||
use: { | ||
headless: false, | ||
baseURL: "http://localhost:3000/#/?chain=scroll+sepolia", | ||
trace: "on-first-retry", | ||
}, | ||
projects: [ | ||
{ | ||
name: "chromium", | ||
use: { | ||
...devices["Desktop Chrome"], | ||
viewport: { width: 1920, height: 1080 }, | ||
}, | ||
}, | ||
{ | ||
name: "firefox", | ||
use: { ...devices["Desktop Firefox"] }, | ||
}, | ||
{ | ||
name: "webkit", | ||
use: { ...devices["Desktop Safari"] }, | ||
}, | ||
], | ||
webServer: { | ||
command: "yarn start:staging", | ||
timeout: 120 * 1_000, | ||
url: "http://127.0.0.1:3000", | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
69a445a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ui – ./packages/ui
ui-carrot-labs.vercel.app
ui-git-main-carrot-labs.vercel.app
69a445a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
host-frontend – ./packages/frontend
host-frontend-carrot-labs.vercel.app
host-frontend-git-main-carrot-labs.vercel.app