-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit cf1dd85 Author: blckclov3r <blckclov3r@gmail.com> Date: Sat Apr 13 04:07:05 2024 +0800 playwright test
- Loading branch information
1 parent
a9d3835
commit 8575aa5
Showing
7 changed files
with
1,342 additions
and
2 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 yarn && yarn | ||
- name: Install Playwright Browsers | ||
run: yarn playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: yarn playwright test | ||
- uses: actions/upload-artifact@v4 | ||
if: always() | ||
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
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,77 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default 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, | ||
// }, | ||
}); |
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,59 @@ | ||
import {expect, Page, test} from '@playwright/test'; | ||
|
||
const baseUrl = 'https://use-postal-ph.vercel.app/'; | ||
|
||
async function setup(page: Page) { | ||
await page.goto(baseUrl); | ||
await page.waitForLoadState('domcontentloaded'); | ||
await expect(page).toHaveTitle(/use-postal-ph/); | ||
const buttons = ['Main', 'Municipality', 'Region', 'Location', 'Post Code']; | ||
for (const buttonName of buttons) { | ||
const button = await page.getByRole('button', {name: buttonName}); | ||
await expect(button).toBeVisible(); | ||
} | ||
} | ||
|
||
async function clickButton(page: Page, buttonName: string) { | ||
await page.getByRole('button', {name: buttonName}).click(); | ||
} | ||
|
||
async function selectOptionAndSubmit(page: Page, comboboxName: string, optionName: string) { | ||
const combobox = await page.getByRole('combobox', {name: comboboxName}); | ||
await combobox.type(optionName); | ||
await page.getByRole('option', {name: optionName, exact: true}).click(); | ||
await page.locator('.MuiBox-root > button').first().click(); | ||
} | ||
|
||
async function clearInput(page: Page, comboboxName: string) { | ||
await page.getByRole('combobox', {name: comboboxName}).click(); | ||
await page.getByLabel('Clear').click(); | ||
await page.locator('.MuiBox-root > button').first().click(); | ||
} | ||
|
||
test('main-municipality', async ({page}) => { | ||
await setup(page); | ||
await clickButton(page, 'Main'); | ||
await selectOptionAndSubmit(page, 'municipality', 'Talisay'); | ||
await clearInput(page, 'municipality'); | ||
}); | ||
|
||
test('main-region', async ({page}) => { | ||
await setup(page); | ||
await clickButton(page, 'Main'); | ||
await selectOptionAndSubmit(page, 'region', 'VII'); | ||
await clearInput(page, 'region'); | ||
}); | ||
|
||
test('main-location', async ({page}) => { | ||
await setup(page); | ||
await clickButton(page, 'Main'); | ||
await selectOptionAndSubmit(page, 'location', 'Cebu'); | ||
await clearInput(page, 'location'); | ||
}); | ||
|
||
test('main-postcode', async ({page}) => { | ||
await setup(page); | ||
await clickButton(page, 'Main'); | ||
await selectOptionAndSubmit(page, 'post_code', '6045'); | ||
await clearInput(page, 'post_code'); | ||
}); |
Oops, something went wrong.