Skip to content

Commit e350f81

Browse files
f-alizadaFarhad Alizada
andauthored
Playwright tests (#2254)
* Add Playwright tests with image comparison for profile page --------- Co-authored-by: Farhad Alizada <falizada@microsoft.com>
1 parent d395754 commit e350f81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1552
-895
lines changed

.github/workflows/test.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
run: npm run test
2121

2222
end2end-tests:
23-
runs-on: ubuntu-latest
23+
runs-on: windows-latest
2424

2525
steps:
2626
- name: Checkout code
@@ -32,16 +32,29 @@ jobs:
3232
- name: Install
3333
run: npm install
3434

35+
- name: Compile
36+
run: npx tsc -p tests\tsconfig.json
37+
38+
- name: Install Playwright Browsers
39+
run: npx playwright install --with-deps
40+
3541
- name: Build static data
3642
run: npm run build-mock-static-data
3743

3844
- name: Start mock server
3945
run: npm run serve-website &
46+
shell: bash
4047

4148
- name: Wait for the server
4249
run: ./.github/scripts/wait-for-server.ps1 -HostName "http://localhost:8080"
4350
shell: pwsh
4451

4552
- name: Run tests
46-
run: npm run test-e2e
47-
53+
run: npx playwright test tests/ --workers 1
54+
55+
- uses: actions/upload-artifact@v3
56+
if: failure()
57+
with:
58+
name: playwright-report
59+
path: test-results/
60+
retention-days: 30

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ node_modules/
77
src/config.design.json
88
src/config.publish.json
99
src/config.runtime.json
10-
10+
test-results/
11+
tsconfig.tsbuildinfo

package-lock.json

Lines changed: 280 additions & 271 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"build-publisher": "webpack --config webpack.publisher.js",
1818
"build-runtime": "webpack --config webpack.runtime.js",
1919
"build-function": "webpack --config webpack.function.js",
20-
"test-e2e": "node node_modules/mocha/bin/_mocha -r mocha.js tests/e2e/**/*.spec.ts --timeout 3000000",
2120
"test": "node node_modules/mocha/bin/_mocha -r mocha.js src/**/*.spec.ts",
2221
"deploy-function": "npm run build-function && cd dist/function && func azure functionapp publish < function app name >",
2322
"publish": "webpack --config webpack.publisher.js && node dist/publisher/index.js && npm run serve-website",
@@ -38,7 +37,6 @@
3837
"@types/mime": "^3.0.1",
3938
"@types/mocha": "10.0.1",
4039
"@types/node": "^20.3.1",
41-
"@types/puppeteer": "5.4.7",
4240
"@typescript-eslint/eslint-plugin": "^5.60.0",
4341
"@typescript-eslint/parser": "^5.60.0",
4442
"autoprefixer": "^10.4.14",
@@ -54,7 +52,6 @@
5452
"mocha": "^10.2.0",
5553
"path": "^0.12.7",
5654
"postcss-loader": "^7.3.3",
57-
"puppeteer": "19.7.5",
5855
"querystring-es3": "^0.2.1",
5956
"raw-loader": "^4.0.2",
6057
"sass": "^1.63.6",
@@ -65,11 +62,12 @@
6562
"ts-loader": "^9.4.3",
6663
"ts-node": "10.9.1",
6764
"typescript": "^4.9.5",
68-
"url-loader": "^4.1.1",
6965
"webpack": "5.88.0",
7066
"webpack-cli": "5.1.4",
7167
"webpack-dev-server": "4.15.1",
72-
"webpack-merge": "5.9.0"
68+
"webpack-merge": "5.9.0",
69+
"playwright": "1.35.1",
70+
"@playwright/test": "1.35.1"
7371
},
7472
"dependencies": {
7573
"@azure/api-management-custom-widgets-scaffolder": "^1.0.0-beta.2",

playwright.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from '@playwright/test';
2+
3+
export default defineConfig({
4+
retries: 2,
5+
use: {
6+
video: 'retain-on-failure'
7+
}
8+
});

src/config.validate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"environment": "validation",
3+
"isLocalRun": true,
34
"root": "http://localhost:8080",
45
"urls": {
56
"home": "/",

src/services/usersService.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ export class UsersService {
255255
*/
256256
public async ensureSignedIn(): Promise<string> {
257257
const userId = await this.getCurrentUserId();
258-
259258
if (!userId) {
260259
this.navigateToSignin();
261260
return; // intentionally exiting without resolving the promise.

tests/constants.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/e2e/maps/apis.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
import { Page } from "puppeteer";
1+
import { Page } from "playwright";
22

33
export class ApisWidget {
44
constructor(private readonly page: Page) { }
55

6-
public async apis(): Promise<void> {
7-
await this.page.waitForSelector("api-list div.table div.table-body div.table-row");
6+
public async waitRuntimeInit(): Promise<void> {
7+
await this.page.locator("api-list").waitFor();
8+
9+
}
10+
11+
public async getApiByName(apiName: string): Promise<string | null> {
12+
return await this.page.locator('api-list div.table div.table-body div.table-row a').filter({ hasText: apiName }).first().innerText();
813
}
914

1015
public async getApisCount(): Promise<number | undefined> {

tests/e2e/maps/home.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Locator, Page } from "playwright";
2+
3+
export class HomePageWidget {
4+
constructor(private readonly page: Page) { }
5+
6+
public async waitRuntimeInit(): Promise<void> {
7+
await this.getWelcomeMessageLocator().waitFor();
8+
}
9+
10+
public getWelcomeMessageLocator(): Locator {
11+
return this.page.locator("h1 span").filter({ hasText: "Welcome to Contoso!" });
12+
}
13+
}

0 commit comments

Comments
 (0)