Skip to content

Commit

Permalink
add simple playwright aria test
Browse files Browse the repository at this point in the history
  • Loading branch information
kan-pawes committed Nov 27, 2024
1 parent a834a47 commit 19ac12d
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 16 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
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 ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
node_modules
node_modules
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/.idea/
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Eksempel på
# Example project for a11y testing

## Aria snapshots

To create new aria snapshot use `playwright codegen`

To update all snapshot use `npx playwright test --update-snapshots`

Read more about aria in [docs](https://playwright.dev/docs/aria-snapshots)

## Prosjektet
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).


### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

83 changes: 76 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"uitest": "playwright test",
"uitest-codegen": "playwright codegen",
"uitest-report": "playwright show-report"
},
"eslintConfig": {
"extends": [
Expand All @@ -34,5 +37,9 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@playwright/test": "^1.49.0",
"@types/node": "^22.10.0"
}
}
78 changes: 78 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// @ts-check
const { defineConfig, devices } = require('@playwright/test');

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config({ path: path.resolve(__dirname, '.env') });

/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: './tests',
/* 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'] },
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
webServer: {
command: 'npm run start',
url: 'http://127.0.0.1:3000',
reuseExistingServer: !process.env.CI,
},
});

2 changes: 1 addition & 1 deletion src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import App from './App';

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
const linkElement = screen.getByText(/Eventyrbilder/i);
expect(linkElement).toBeInTheDocument();
});
33 changes: 33 additions & 0 deletions tests/example.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @ts-check
const { test, expect } = require('@playwright/test');

test('has title', async ({ page }) => {
await page.goto('http://localhost:3000/');
await expect(page.locator('#root')).toMatchAriaSnapshot(`
- heading "Eventyrbilder" [level=4]
- textbox "Søk"
- img "Bilde"
- text: Tid
- img "Bilde"
- text: Noe glemt
- img "Bilde"
- text: Et forsøk
- img "Bilde"
- text: Uheldig
- img "Bilde"
- text: Fri
- img "Bilde"
- text: Nytt liv
- img "Bilde"
- text: Evner
- img "Bilde"
- text: Fly
- img "Bilde"
- text: Det første som faller
`);
});

// test('get started link', async ({ page }) => {
//
//
// });

0 comments on commit 19ac12d

Please sign in to comment.