Skip to content

Commit 47280bc

Browse files
Rugvipfrebenjhaals
committed
add playright setup + migrate a few tests in example app
Co-authored-by: Fredrik Adelöw <freben@gmail.com> Co-authored-by: Johan Haals <johan.haals@gmail.com> Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
1 parent 2b6e572 commit 47280bc

File tree

7 files changed

+154
-0
lines changed

7 files changed

+154
-0
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
**/microsite/**
1010
**/templates/**
1111
**/sample-templates/**
12+
playwright.config.ts

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ tsconfig.tmp.json
150150
# vscode database functionality support files
151151
*.session.sql
152152

153+
# E2E test reports
154+
e2e-test-report/
155+
153156
# Lighthouse CI Reports
154157
**/.lighthouseci/*
155158
!**/.lighthouseci/scripts

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"clean": "backstage-cli repo clean",
1919
"test": "backstage-cli repo test",
2020
"test:all": "backstage-cli repo test --coverage",
21+
"test:e2e": "playwright test",
2122
"fix": "backstage-cli repo fix",
2223
"lint": "backstage-cli repo lint --since origin/master",
2324
"lint:docs": "node ./scripts/check-docs-quality",
@@ -58,9 +59,11 @@
5859
"@backstage/cli": "workspace:*",
5960
"@backstage/codemods": "workspace:*",
6061
"@backstage/create-app": "workspace:*",
62+
"@backstage/e2e-test-utils": "workspace:*",
6163
"@backstage/repo-tools": "workspace:*",
6264
"@changesets/cli": "^2.14.0",
6365
"@octokit/rest": "^19.0.3",
66+
"@playwright/test": "^1.32.3",
6467
"@spotify/eslint-plugin": "^14.1.3",
6568
"@spotify/prettier-config": "^14.0.0",
6669
"@techdocs/cli": "workspace:*",
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2021 The Backstage Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { test, expect } from '@playwright/test';
18+
19+
test('the results are rendered as expected', async ({ page }) => {
20+
await page.goto('/');
21+
22+
const enterButton = page.getByRole('button', { name: 'Enter' });
23+
await expect(enterButton).toBeVisible();
24+
await enterButton.click();
25+
26+
await page.goto('/search');
27+
await page.route(`http://*/api/search/query?term=*`, async route => {
28+
const results = [
29+
{
30+
type: 'software-catalog',
31+
document: {
32+
title: 'backstage',
33+
text: 'Backstage system documentation',
34+
location: '/result/location/path',
35+
},
36+
},
37+
];
38+
await route.fulfill({ json: { results } });
39+
});
40+
41+
await expect(
42+
page.getByPlaceholder('Search in Backstage Example App'),
43+
).toBeVisible();
44+
45+
await expect(page.getByText('Backstage system documentation')).toBeVisible();
46+
});

packages/app/e2e-tests/app.test.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2020 The Backstage Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { test, expect } from '@playwright/test';
18+
19+
test('App should render the welcome page', async ({ page }) => {
20+
await page.goto('/');
21+
22+
const enterButton = page.getByRole('button', { name: 'Enter' });
23+
await expect(enterButton).toBeVisible();
24+
await enterButton.click();
25+
26+
await expect(page.getByText('My Company Catalog')).toBeVisible();
27+
28+
const supportButton = page.getByTestId('support-button');
29+
await expect(supportButton).toBeVisible();
30+
await supportButton.click();
31+
32+
await expect(page.getByText('#backstage')).toBeVisible();
33+
});

packages/app/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
},
104104
"devDependencies": {
105105
"@backstage/test-utils": "workspace:^",
106+
"@playwright/test": "^1.32.3",
106107
"@testing-library/dom": "^8.0.0",
107108
"@testing-library/jest-dom": "^5.10.1",
108109
"@testing-library/react": "^12.1.3",

playwright.config.ts

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2023 The Backstage Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { defineConfig } from '@playwright/test';
18+
import { generateProjects } from '@backstage/e2e-test-utils/playwright';
19+
20+
/**
21+
* See https://playwright.dev/docs/test-configuration.
22+
*/
23+
export default defineConfig({
24+
timeout: 30_000,
25+
26+
expect: {
27+
timeout: 5_000,
28+
},
29+
30+
// Run your local dev server before starting the tests
31+
webServer: process.env.CI
32+
? []
33+
: [
34+
{
35+
command: 'yarn start',
36+
port: 3000,
37+
reuseExistingServer: true,
38+
timeout: 60_000,
39+
},
40+
// TODO: Before encouraging e2e tests for backend we'll want to provide better utilities for mocking auth
41+
// {
42+
// command: 'yarn start-backend',
43+
// port: 7007,
44+
// reuseExistingServer: true,
45+
// timeout: 60_000,
46+
// },
47+
],
48+
49+
forbidOnly: !!process.env.CI,
50+
51+
retries: process.env.CI ? 2 : 0,
52+
53+
reporter: [['html', { open: 'never', outputFolder: 'e2e-test-report' }]],
54+
55+
use: {
56+
actionTimeout: 0,
57+
baseURL:
58+
process.env.PLAYWRIGHT_URL ??
59+
(process.env.CI ? 'http://localhost:7007' : 'http://localhost:3000'),
60+
screenshot: 'only-on-failure',
61+
trace: 'on-first-retry',
62+
},
63+
64+
outputDir: 'node_modules/.cache/e2e-test-results',
65+
66+
projects: generateProjects(), // Find all packages with e2e-test folders
67+
});

0 commit comments

Comments
 (0)