-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add and config playwright - Add fixtures to use chromium with the extension - Add simple test to check popup and content script on github files changed - Add github workflow
- Loading branch information
1 parent
00d8eef
commit c317faa
Showing
8 changed files
with
186 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Playwright Tests | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- name: Install dependencies | ||
run: npm install -g pnpm && pnpm install | ||
- name: Install Playwright Browsers | ||
run: pnpm exec playwright install --with-deps | ||
- name: Run Playwright E2E tests | ||
run: pnpm e2e | ||
- uses: actions/upload-artifact@v4 | ||
if: ${{ !cancelled() }} | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
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,24 @@ | ||
import { test, expect } from "./fixtures"; | ||
|
||
test("Goto github PR files changed and check diff", async ({ page }) => { | ||
await page.goto( | ||
"https://github.com/bancorprotocol/carbon-app/pull/1464/files" | ||
); | ||
const firstIframe = page.frameLocator("iframe").first(); | ||
const iframeBody = firstIframe.locator("body"); | ||
|
||
await expect(iframeBody).toContainText("Difference"); | ||
await expect(iframeBody).toContainText("Overlay"); | ||
}); | ||
|
||
test("Check settings page contains right header and labels", async ({ | ||
page, | ||
extensionId, | ||
}) => { | ||
await page.goto(`chrome-extension://${extensionId}/src/popup/index.html`); | ||
await expect(page.locator("h1")).toContainText("Settings"); | ||
expect(page.locator("form > label")).toHaveText([ | ||
"Diff Color", | ||
"Default Algo", | ||
]); | ||
}); |
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 as base, chromium, type BrowserContext } from "@playwright/test"; | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
import { resolve } from "node:path"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
const rootPath = resolve(__dirname, ".."); | ||
|
||
export const test = base.extend<{ | ||
context: BrowserContext; | ||
extensionId: string; | ||
}>({ | ||
context: async ({}, use) => { | ||
const pathToExtension = path.join(rootPath, "dist"); | ||
const context = await chromium.launchPersistentContext("", { | ||
headless: false, | ||
args: [ | ||
`--disable-extensions-except=${pathToExtension}`, | ||
`--load-extension=${pathToExtension}`, | ||
], | ||
}); | ||
await use(context); | ||
await context.close(); | ||
}, | ||
extensionId: async ({ context }, use) => { | ||
let [background] = context.serviceWorkers(); | ||
if (!background) background = await context.waitForEvent("serviceworker"); | ||
|
||
const extensionId = background.url().split("/")[2]; | ||
await use(extensionId); | ||
}, | ||
}); | ||
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
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,52 @@ | ||
/** | ||
* @see {@link https://playwright.dev/docs/chrome-extensions Chrome extensions | Playwright} | ||
*/ | ||
|
||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// import dotenv from 'dotenv'; | ||
// import path from 'path'; | ||
// dotenv.config({ path: path.resolve(__dirname, '.env') }); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: "./e2e", | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: "html", | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://127.0.0.1:3000', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: "on-first-retry", | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: "chromium", | ||
use: { ...devices["Desktop Chrome"] }, | ||
}, | ||
], | ||
// webServer: { | ||
// command: "pnpm dev", | ||
// // start e2e test after the Vite server is fully prepared | ||
// url: "http://localhost:3303/popup/main.ts", | ||
// reuseExistingServer: true, | ||
// }, | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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