Skip to content
This repository was archived by the owner on Jun 18, 2023. It is now read-only.

Commit 989913d

Browse files
committed
feat: Improve first playwright tests
1 parent cf32041 commit 989913d

File tree

6 files changed

+54
-25
lines changed

6 files changed

+54
-25
lines changed

.github/workflows/build-on-pull-request.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ jobs:
2424
run: ./gradlew build
2525

2626
# prepare ui test
27-
- name: Install Playwright Browsers
27+
- name: Install Playwright E2E Browsers
2828
run: npx playwright install --with-deps
2929

30-
- name: Start application in the background
31-
run: ./gradlew npm_run_start &
3230
# run ui tests
3331
- name: E2E
3432
run: ./gradlew npm_run_e2e

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ To update the mock data, run `npm run update-mocks`.
3030
## E2E tests
3131

3232
E2E tests are written with [playwright](https://playwright.dev).
33-
To run them:
34-
1. start the development server with `npm run start`
35-
2. run the tests with `npm run test`
33+
34+
Execute them with: `npm run test`
35+
(This starts the angular dev server in the background as defined in `playwright.config.ts` in the `webServer` section)
3636

3737
During development of test you might find the codegen feature useful:
3838
`npx playwright codegen localhost:4200`
39+
(This assumes that the angular dev server is running `npm run start`)
3940

4041
## Release
4142

playwright.config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const config: PlaywrightTestConfig = {
3636
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
3737
actionTimeout: 0,
3838
/* Base URL to use in actions like `await page.goto('/')`. */
39-
// baseURL: 'http://localhost:3000',
39+
baseURL: 'http://localhost:4200/',
4040

4141
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
4242
trace: 'on-first-retry',
@@ -97,11 +97,11 @@ const config: PlaywrightTestConfig = {
9797
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
9898
// outputDir: 'test-results/',
9999

100-
/* Run your local dev server before starting the tests */
101-
// webServer: {
102-
// command: 'npm run start',
103-
// port: 3000,
104-
// },
100+
/* Run your local dev server before starting the tests. Comment out if you have a server already running. */
101+
webServer: {
102+
command: 'npm run start',
103+
port: 4200,
104+
},
105105
};
106106

107107
export default config;

tests/channel.test.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,57 @@
11
import { test, expect } from '@playwright/test';
22
import asyncApiJson from '../src/app/shared/mock/mock.springwolf-kafka-example.json'
33

4-
test.describe('Channel', ()=> {
4+
test.describe('Channel section', ()=> {
55
test.beforeEach(async ({ page }, testInfo) => {
6-
console.log(`Running ${testInfo.title}`);
7-
await page.goto('http://localhost:4200/');
6+
await page.goto('/');
87
});
98

10-
test('first collapsible is rendered', async ({ page }) => {
9+
test('clicking on channel updates the url', async ({ page }) => {
10+
// when
1111
await page.locator("#channel-kafka-another-topic-publish-AnotherPayloadDto").click()
12+
13+
// then
1214
await expect(page).toHaveURL('http://localhost:4200/#channel-kafka-another-topic-publish-AnotherPayloadDto');
15+
})
16+
17+
test('(first) channel example tab is rendered', async ({ page }) => {
18+
// when
19+
await page.locator("#channel-kafka-another-topic-publish-AnotherPayloadDto").click()
1320

21+
// then
22+
await page.getByRole('tab', { name: 'Example' }).getByText('Example').click();
1423
await expect(page.getByRole('tabpanel', { name: 'Example' }).locator('textarea'))
1524
.toHaveValue(JSON.stringify(asyncApiJson.components.schemas.AnotherPayloadDto.example, null, 2))
25+
});
26+
27+
test('(first) channel schema tab is rendered', async ({ page }) => {
28+
// when
29+
await page.locator("#channel-kafka-another-topic-publish-AnotherPayloadDto").click()
1630

31+
// then
1732
await page.getByRole('tab', { name: 'Schema' }).getByText('Schema').click();
1833
await page.getByRole('heading', { name: 'AnotherPayloadDto #/components/schemas/AnotherPayloadDto' }).click();
1934
await page.getByRole('cell', { name: 'string Foo field example: "bar"' }).getByText('string').click();
2035
await page.getByRole('cell', { name: 'string Foo field example: "bar"' }).getByText('Foo field').click();
2136
await page.getByRole('cell', { name: 'string Foo field example: "bar"' }).getByText('example: "bar"').click();
37+
});
38+
39+
test('(first) channel headers tab is rendered', async ({ page }) => {
40+
// when
41+
await page.locator("#channel-kafka-another-topic-publish-AnotherPayloadDto").click()
2242

43+
// then
2344
await page.getByRole('tab', { name: 'Headers' }).getByText('Headers').click();
2445
await page.getByRole('heading', { name: 'HeadersNotDocumented #/components/schemas/HeadersNotDocumented' }).click();
2546
await expect(page.getByRole('tabpanel', { name: 'Headers' }).locator('textarea'))
2647
.toHaveValue(JSON.stringify(asyncApiJson.components.schemas.HeadersNotDocumented.example, null, 2))
48+
});
49+
50+
test('(first) channel bindings tab is rendered', async ({ page }) => {
51+
// when
52+
await page.locator("#channel-kafka-another-topic-publish-AnotherPayloadDto").click()
2753

54+
// then
2855
await page.getByRole('tab', { name: 'Bindings' }).getByText('Bindings').click();
2956
await page.getByText(/\{\s+"groupId":\s+\{\s+"type":\s+"string",\s+"enum":\s+\[\s+"example-group-id"\s+\]\s+\}\s+\}/).click();
3057
});

tests/header.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { test, expect } from '@playwright/test';
22

3-
test.describe('Header', ()=> {
3+
test.describe('Header section', ()=> {
44
test.beforeEach(async ({ page }, testInfo) => {
5-
console.log(`Running ${testInfo.title}`);
6-
await page.goto('http://localhost:4200/');
5+
await page.goto('/');
76
});
87

9-
test('github url is shown', async ({ page }) => {
8+
test('github url is shown as link', async ({ page }) => {
9+
// then
1010
await expect(page.locator("mat-toolbar a")).toHaveAttribute('href', 'https://github.com/stavshamir/springwolf')
1111
});
1212
})

tests/info.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
import { test, expect } from '@playwright/test';
22
import asyncApiJson from '../src/app/shared/mock/mock.springwolf-kafka-example.json'
33

4-
test.describe('Info', ()=> {
4+
test.describe('Info section', ()=> {
55
test.beforeEach(async ({ page }, testInfo) => {
6-
console.log(`Running ${testInfo.title}`);
7-
await page.goto('http://localhost:4200/');
6+
await page.goto('/');
87
});
98

10-
test('section is shown', async ({ page }) => {
9+
test('info is shown', async ({ page }) => {
10+
// then
1111
await expect(page.locator('app-info h1')).toHaveText('Springwolf example project - Kafka' );
1212
await expect(page.locator('app-info h5')).toHaveText('API VERSION 1.0.0 - AsyncAPI JSON file' );
1313
await expect(page.locator('app-info p')).toHaveText('Springwolf example project to demonstrate springwolfs abilities' );
1414
});
1515

16-
test('download of AsyncApi json', async ({ page }) => {
16+
test('download of AsyncApi json matches original file', async ({ page }) => {
17+
// when
1718
const [popup] = await Promise.all([
1819
page.waitForEvent('popup'),
1920
page.getByRole('link', { name: 'AsyncAPI JSON file' }).click()
2021
]);
2122
const popupContent = await popup.evaluate('document.body.textContent') as string
23+
24+
// then
2225
await expect(JSON.parse(popupContent)).toStrictEqual(asyncApiJson)
2326
});
2427
})

0 commit comments

Comments
 (0)