Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit cf1dd85
Author: blckclov3r <blckclov3r@gmail.com>
Date:   Sat Apr 13 04:07:05 2024 +0800

    playwright test
  • Loading branch information
blckclov3r committed Apr 12, 2024
1 parent a9d3835 commit 8575aa5
Show file tree
Hide file tree
Showing 7 changed files with 1,342 additions and 2 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 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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ dist
node_modules
.yarnrc.yml
.yarn
pnpm-lock.yaml
pnpm-lock.yaml
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
playwright-report
6 changes: 5 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ tsup.config.ts
start.sh
.yarnrc.yml
.yarn
pnpm-lock.yaml
pnpm-lock.yaml
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,22 @@
"email": "blckclov3r@gmail.com"
},
"devDependencies": {
"@playwright/test": "^1.43.0",
"@swc/core": "^1.4.11",
"@types/node": "^20.12.7",
"terser": "^5.29.2",
"tsup": "^8.0.2",
"typescript": "^5.4.3"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"test": "yarn playwright test",
"test-headed": "yarn playwright test --headed",
"test-web": "yarn playwright test --ui web",
"codegen": "yarn playwright codegen",
"debug-web": "yarn playwright test web --debug",
"report": "playwright show-report"
}
}
77 changes: 77 additions & 0 deletions playwright.config.ts
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,
// },
});
59 changes: 59 additions & 0 deletions tests/web.spec.ts
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');
});
Loading

0 comments on commit 8575aa5

Please sign in to comment.