Skip to content

Commit

Permalink
support playwright service
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Nov 23, 2023
1 parent 21a7647 commit 95ed926
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
node_modules
npm-debug.log

# env
.env

# tests
test-results
playwright-report
Expand Down
73 changes: 53 additions & 20 deletions package-lock.json

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

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"scripts": {
"test": "npx bddgen && npx playwright test",
"test:cloud": "npx bddgen && npx playwright test --config=playwright.service.config.ts",
"test:todo": "npx bddgen --tags '@todo' && npx playwright test",
"test:chromium": "npx bddgen && npx playwright test --project chromium",
"watch:bdd": "nodemon -w ./features -w ./steps -e feature,js,ts --exec 'npx bddgen'",
Expand All @@ -12,9 +13,14 @@
"steps": "npx bddgen export"
},
"devDependencies": {
"@types/node": "^20.9.4",
"dotenv": "^16.3.1",
"nodemon": "^3.0.1",
"npm-run-all": "^4.1.5",
"playwright-bdd": "^5.5.0",
"typescript": "^5.3.2"
},
"dependencies": {
"@playwright/test": "^1.40.0"
}
}
51 changes: 51 additions & 0 deletions playwright.service.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { defineConfig } from '@playwright/test';
import config from './playwright.config';
import dotenv from 'dotenv';

// Define environment on the dev box in .env file:
// .env:
// PLAYWRIGHT_SERVICE_ACCESS_TOKEN=XXX
// PLAYWRIGHT_SERVICE_URL=XXX

// Define environment in your GitHub workflow spec.
// env:
// PLAYWRIGHT_SERVICE_ACCESS_TOKEN: ${{ secrets.PLAYWRIGHT_SERVICE_ACCESS_TOKEN }}
// PLAYWRIGHT_SERVICE_URL: ${{ secrets.PLAYWRIGHT_SERVICE_URL }}
// PLAYWRIGHT_SERVICE_RUN_ID: ${{ github.run_id }}-${{ github.run_attempt }}-${{ github.sha }}

dotenv.config();

// Name the test run if it's not named yet.
process.env.PLAYWRIGHT_SERVICE_RUN_ID = process.env.PLAYWRIGHT_SERVICE_RUN_ID || new Date().toISOString();

// Can be 'linux' or 'windows'.
const os = process.env.PLAYWRIGHT_SERVICE_OS || 'linux';

export default defineConfig(config, {
workers: 10,
fullyParallel: true,

// Enable screenshot testing and configure directory with expectations.
// https://learn.microsoft.com/azure/playwright-testing/how-to-configure-visual-comparisons
ignoreSnapshots: true,
snapshotPathTemplate: `{testDir}/__screenshots__/{testFilePath}/${os}/{arg}{ext}`,

use: {
// Specify the service endpoint.
connectOptions: {
wsEndpoint: `${process.env.PLAYWRIGHT_SERVICE_URL}?cap=${JSON.stringify({
// Can be 'linux' or 'windows'.
os,
runId: process.env.PLAYWRIGHT_SERVICE_RUN_ID
})}`,
timeout: 30000,
headers: {
'x-mpt-access-key': process.env.PLAYWRIGHT_SERVICE_ACCESS_TOKEN!
},
// Allow service to access the localhost.
exposeNetwork: '<loopback>'
}
},
// Tenmp workaround for config merge bug in OSS https://github.com/microsoft/playwright/pull/28224
projects: config.projects? config.projects : [{}]
});

0 comments on commit 95ed926

Please sign in to comment.