-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add playwright system test (#64)
- Loading branch information
Showing
10 changed files
with
179 additions
and
7 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,42 @@ | ||
name: Verifies gh-page is up and running | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- playwright-base | ||
workflow_dispatch: | ||
|
||
jobs: | ||
verify-gh-page: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# - name: Delay start | ||
# run: sleep 30s | ||
# shell: bash | ||
|
||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
|
||
- name: Install dependencies | ||
run: | | ||
corepack enable | ||
corepack prepare --activate | ||
pnpm install --frozen-lockfile | ||
- name: Run Playwright tests | ||
run: pnpm stest | ||
working-directory: ./examples | ||
|
||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: examples/test-results/* | ||
retention-days: 5 |
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 |
---|---|---|
|
@@ -3,3 +3,6 @@ node_modules | |
dist | ||
dist-ssr | ||
*.local | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
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,42 @@ | ||
import { Config, PlaywrightTestConfig } from "@playwright/test"; | ||
|
||
type UseConfig = Config["use"]; | ||
type Projects = Config["projects"]; | ||
|
||
export const chromium = ({ flags }: { flags?: string[] } = {}): UseConfig => ({ | ||
browserName: "chromium", | ||
channel: process.env.BROWSER ?? "chrome", | ||
viewport: { width: 1280, height: 720 }, | ||
permissions: ["clipboard-write", "clipboard-read"], | ||
launchOptions: { | ||
args: [ | ||
"--ignore-certificate-errors", | ||
"--use-fake-ui-for-media-stream", | ||
"--use-fake-device-for-media-stream", | ||
...(flags ?? []), | ||
], | ||
}, | ||
}); | ||
|
||
export function createConfig( | ||
projects: Projects, | ||
addUseOptions: Partial<PlaywrightTestConfig["use"]> = {} | ||
): PlaywrightTestConfig { | ||
return { | ||
forbidOnly: !!process.env.CI, | ||
projects: projects, | ||
use: { | ||
// Context options | ||
ignoreHTTPSErrors: true, | ||
contextOptions: { | ||
locale: "en_GB", | ||
}, | ||
// Artifacts | ||
screenshot: "only-on-failure", | ||
trace: "on-first-retry", | ||
...addUseOptions, | ||
}, | ||
retries: process.env.CI ? 1 : 0, | ||
reporter: process.env.CI ? [["github"], ["list"]] : [["list"]], | ||
}; | ||
} |
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,13 @@ | ||
import { PlaywrightTestConfig } from "@playwright/test"; | ||
import { chromium, createConfig } from "./playwright.confg.base"; | ||
|
||
const config: PlaywrightTestConfig = { | ||
...createConfig([ | ||
{ | ||
name: "fluent-components:stest:chromium", | ||
use: chromium(), | ||
testMatch: ["system-test/**.stest.ts"], | ||
}, | ||
]), | ||
}; | ||
export default config; |
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,10 @@ | ||
import { expect, test } from "@playwright/test"; | ||
import { goToPage } from "./utils"; | ||
|
||
test("should be able to navigate to home page", async ({ page }) => { | ||
await goToPage(page); | ||
|
||
const homePage = page.locator("#welcome-page"); | ||
|
||
await expect(homePage).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,17 @@ | ||
import { Page } from "@playwright/test"; | ||
|
||
const GH_PAGE = "https://axiscommunications.github.io/fluent-components/"; | ||
const LOCAL_HOST = "http://127.0.0.1:3000/fluent-components/"; | ||
|
||
export function goToPage(page: Page, url?: string) { | ||
if (url) { | ||
return page.goto(url); | ||
} | ||
|
||
const envUrl = isCi() ? GH_PAGE : LOCAL_HOST; | ||
return page.goto(envUrl); | ||
} | ||
|
||
export function isCi(): boolean { | ||
return process.env.CI === "true"; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.