Skip to content

Commit a17e677

Browse files
authored
Merge pull request #1103 from w3bdesign/1102-simple-playwright-test
1102 simple playwright test
2 parents 460fe9f + 051e13b commit a17e677

File tree

6 files changed

+166
-1
lines changed

6 files changed

+166
-1
lines changed

.github/workflows/playwright.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: 18
16+
- name: Install dependencies
17+
run: npm ci
18+
env:
19+
CI: true
20+
PUBLIC_GRAPHQL_URL: ${{ secrets.PUBLIC_GRAPHQL_URL }}
21+
ALGOLIA_SEARCH_API_KEY: ${{ secrets.ALGOLIA_SEARCH_API_KEY }}
22+
ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
23+
- name: Install Playwright Browsers
24+
run: npx playwright install --with-deps
25+
- name: Run Playwright tests
26+
run: npx playwright test
27+
env:
28+
CI: true
29+
PUBLIC_GRAPHQL_URL: ${{ secrets.PUBLIC_GRAPHQL_URL }}
30+
ALGOLIA_SEARCH_API_KEY: ${{ secrets.ALGOLIA_SEARCH_API_KEY }}
31+
ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
32+
- uses: actions/upload-artifact@v3
33+
if: always()
34+
with:
35+
name: playwright-report
36+
path: playwright-report/
37+
retention-days: 30

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ node_modules
66
.output
77
.env
88
dist
9+
/test-results/
10+
/playwright-report/
11+
/playwright/.cache/

package-lock.json

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"devDependencies": {
1414
"@nuxtjs/apollo": "^5.0.0-alpha.6",
1515
"@pinia-plugin-persistedstate/nuxt": "^1.1.1",
16+
"@playwright/test": "^1.35.1",
1617
"autoprefixer": "^10.4.14",
1718
"nuxt": "^3.6.2",
1819
"nuxt-icon": "^0.4.2",
@@ -23,7 +24,6 @@
2324
"overrides": {
2425
"vue": "^3.3.4",
2526
"tslib": "2.5.1"
26-
2727
},
2828
"dependencies": {
2929
"@formkit/nuxt": "^1.0.0-beta.9-f64c966",

playwright.config.ts

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// require('dotenv').config();
8+
9+
/**
10+
* See https://playwright.dev/docs/test-configuration.
11+
*/
12+
export default defineConfig({
13+
testDir: "./tests",
14+
/* Run tests in files in parallel */
15+
fullyParallel: true,
16+
/* Fail the build on CI if you accidentally left test.only in the source code. */
17+
forbidOnly: !!process.env.CI,
18+
/* Retry on CI only */
19+
retries: process.env.CI ? 2 : 0,
20+
/* Opt out of parallel tests on CI. */
21+
workers: process.env.CI ? 1 : undefined,
22+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
23+
reporter: "html",
24+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
25+
use: {
26+
/* Base URL to use in actions like `await page.goto('/')`. */
27+
// baseURL: 'http://127.0.0.1:3000',
28+
29+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
30+
trace: "on-first-retry",
31+
},
32+
33+
/* Configure projects for major browsers */
34+
projects: [
35+
{
36+
name: "chromium",
37+
use: { ...devices["Desktop Chrome"] },
38+
},
39+
40+
{
41+
name: "firefox",
42+
use: { ...devices["Desktop Firefox"] },
43+
},
44+
45+
{
46+
name: "webkit",
47+
use: { ...devices["Desktop Safari"] },
48+
},
49+
50+
/* Test against mobile viewports. */
51+
// {
52+
// name: 'Mobile Chrome',
53+
// use: { ...devices['Pixel 5'] },
54+
// },
55+
// {
56+
// name: 'Mobile Safari',
57+
// use: { ...devices['iPhone 12'] },
58+
// },
59+
60+
/* Test against branded browsers. */
61+
// {
62+
// name: 'Microsoft Edge',
63+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
64+
// },
65+
// {
66+
// name: 'Google Chrome',
67+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
68+
// },
69+
],
70+
71+
/* Run your local dev server before starting the tests */
72+
// webServer: {
73+
// command: 'npm run start',
74+
// url: 'http://127.0.0.1:3000',
75+
// reuseExistingServer: !process.env.CI,
76+
// },
77+
78+
/* Run your local dev server before starting the tests */
79+
webServer: {
80+
reuseExistingServer: true,
81+
command: "npm run dev",
82+
port: 3000,
83+
},
84+
});

tests/index.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("Has Index title", async ({ page }) => {
4+
//await page.goto('https://playwright.dev/');
5+
await page.goto("/");
6+
7+
// Expect a title "to contain" a substring.
8+
await expect(page).toHaveTitle(/Index - Nuxt 3 Woocommerce/);
9+
});

0 commit comments

Comments
 (0)