Skip to content

Commit 7be6e6f

Browse files
committed
test(playwright): refactored files, add mobile test, all tests passing
1 parent 7ffdc89 commit 7be6e6f

17 files changed

Lines changed: 410 additions & 192 deletions

docker-compose.test.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ services:
44
nginx:
55
container_name: server_nginx
66
restart: 'no'
7-
build: ./nginx/tests
7+
build:
8+
context: .
9+
dockerfile: ./nginx/tests/Dockerfile
810
ports:
911
- 3000:80
10-
volumes:
11-
- /out:/www/data/out
1212
networks:
1313
- running-tests
1414

nginx/tests/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ RUN mkdir /var/cache/nginx -p
77
RUN rm /etc/nginx/mime.types
88
RUN rm /etc/nginx/conf.d/default.conf
99

10-
COPY ./nginx.conf /etc/nginx/
11-
COPY ./mime.types /etc/nginx/conf/
10+
COPY ./nginx/tests/nginx.conf /etc/nginx/
11+
COPY ./nginx/tests/mime.types /etc/nginx/conf/
12+
COPY ./out /www/data/out
1213

1314
EXPOSE 80

playwright.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export default defineConfig({
1818
name: 'chromium',
1919
use: { ...devices['Desktop Chrome'] },
2020
},
21+
{
22+
name: 'Mobile Chrome',
23+
use: { ...devices['Galaxy S9+'] },
24+
},
2125
],
2226

2327
webServer: {

tests/accessibility.spec.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
import AxeBuilder from '@axe-core/playwright'
22
import { expect, test } from '@playwright/test'
33

4+
const HOME = '/'
5+
46
test.describe('Accessibility', () => {
7+
test.beforeEach(async ({ page }) => {
8+
try {
9+
await page.waitForLoadState()
10+
} catch (error) {
11+
console.error(error)
12+
}
13+
})
514
test('Should not have any automatically detectable accessibility issues', async ({
615
page,
716
}) => {
8-
await page.goto('/')
17+
try {
18+
await page.goto(HOME)
919

10-
const accessibilityScanResults = await new AxeBuilder({ page }).analyze()
20+
const accessibilityScanResults = await new AxeBuilder({ page }).analyze()
1121

12-
expect(accessibilityScanResults.violations).toEqual([])
22+
expect(accessibilityScanResults.violations).toEqual([])
23+
} catch (error) {
24+
console.error(error)
25+
}
1326
})
1427
})

tests/components.spec.ts

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,28 @@ import { expect, test } from '@playwright/test'
33
const HOME = '/'
44

55
test.describe('Component - Dev tools', () => {
6-
const DEV_TOOLS = 'tailwind-indicator'
6+
test.beforeEach(async ({ page }) => {
7+
try {
8+
await page.waitForLoadState()
9+
} catch (error) {
10+
console.error(error)
11+
}
12+
})
13+
try {
14+
const DEV_TOOLS = 'tailwind-indicator'
715

8-
test('Expected - Tailwind indicator to not be rendered', async ({ page }) => {
9-
await page.goto(HOME)
16+
test('Expected - Tailwind indicator to not be rendered', async ({
17+
page,
18+
}) => {
19+
await page.goto(HOME)
1020

11-
const twIndicator = await page.getByTestId(DEV_TOOLS).count()
21+
const twIndicator = await page.getByTestId(DEV_TOOLS).count()
1222

13-
expect(twIndicator).toBe(0)
14-
})
23+
expect(twIndicator).toBe(0)
24+
})
25+
} catch (error) {
26+
console.error(error)
27+
}
1528
})
1629

1730
test.describe('Component - Marquee', () => {
@@ -30,50 +43,73 @@ test.describe('Component - Marquee', () => {
3043
'AWS',
3144
]
3245

46+
test.beforeEach(async ({ page }) => {
47+
try {
48+
await page.waitForLoadState()
49+
} catch (error) {
50+
console.error(error)
51+
}
52+
})
53+
3354
test('Expected - Marquee to be visible', async ({ page }) => {
34-
await page.goto(HOME)
55+
try {
56+
await page.goto(HOME)
3557

36-
const PAGE_LOCATOR = page.locator('div').filter({ hasText: MARQUEE_SPAN })
58+
const PAGE_LOCATOR = page.locator('div').filter({ hasText: MARQUEE_SPAN })
3759

38-
await expect(PAGE_LOCATOR).toBeVisible()
60+
await expect(PAGE_LOCATOR).toBeVisible()
61+
} catch (error) {
62+
console.log(error)
63+
}
3964
})
4065
test('Expected - Correct height and width, 70px 100vw', async ({ page }) => {
41-
await page.goto(HOME)
66+
try {
67+
await page.goto(HOME)
4268

43-
const PAGE_LOCATOR = page.locator('div').filter({ hasText: MARQUEE_SPAN })
69+
const PAGE_LOCATOR = page.locator('div').filter({ hasText: MARQUEE_SPAN })
4470

45-
const marquee = await PAGE_LOCATOR.boundingBox()
71+
const marquee = await PAGE_LOCATOR.boundingBox()
4672

47-
const viewPort = page.viewportSize()
73+
const viewPort = page.viewportSize()
4874

49-
if (viewPort === null) throw new Error('Viewport is null')
75+
if (viewPort === null) throw new Error('Viewport is null')
5076

51-
const { width } = viewPort
77+
const { width } = viewPort
5278

53-
expect(marquee?.width).toBe(width)
54-
expect(marquee?.height).toBe(MARQUEE_HEIGHT)
79+
expect(marquee?.width).toBe(width)
80+
expect(marquee?.height).toBe(MARQUEE_HEIGHT)
81+
} catch (error) {
82+
console.error(error)
83+
}
5584
})
5685

5786
test('Expected - Total images number', async ({ page }) => {
58-
await page.goto(HOME)
87+
try {
88+
await page.goto(HOME)
5989

60-
const PAGE_LOCATOR = page.locator('div').filter({ hasText: MARQUEE_SPAN })
61-
const marqueeImages = PAGE_LOCATOR.locator('img')
90+
const PAGE_LOCATOR = page.locator('div').filter({ hasText: MARQUEE_SPAN })
91+
const marqueeImages = PAGE_LOCATOR.locator('img')
6292

63-
expect(await marqueeImages.count()).toBe(TOTAL_IMAGES)
93+
expect(await marqueeImages.count()).toBe(TOTAL_IMAGES)
94+
} catch (error) {
95+
console.error(error)
96+
}
6497
})
6598

6699
test('Expected - All images to be visible', async ({ page }) => {
67-
await page.goto(HOME)
68-
69-
const PAGE_LOCATOR = page.locator('div').filter({ hasText: MARQUEE_SPAN })
70-
71-
const marqueeImages = await PAGE_LOCATOR.locator('img').all()
72-
73-
for (const image of marqueeImages) {
74-
const alt = await image.getAttribute('alt')
75-
expect(image).toBeVisible()
76-
expect(MARQUEE_IMAGES).toContain(alt)
100+
try {
101+
await page.goto(HOME)
102+
const PAGE_LOCATOR = page.locator('div').filter({ hasText: MARQUEE_SPAN })
103+
104+
const marqueeImages = await PAGE_LOCATOR.locator('img').all()
105+
106+
for (const image of marqueeImages) {
107+
const alt = await image.getAttribute('alt')
108+
await expect(image).toBeVisible()
109+
expect(MARQUEE_IMAGES).toContain(alt)
110+
}
111+
} catch (error) {
112+
console.error(error)
77113
}
78114
})
79115
})

tests/screenshot.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { expect, test } from '@playwright/test'
22

3+
const HOME = '/'
4+
35
test('Full page', async ({ page }) => {
4-
await page.goto('/')
6+
try {
7+
await page.goto(HOME)
58

6-
await expect(page).toHaveScreenshot({ fullPage: true })
9+
await expect(page).toHaveScreenshot({ fullPage: true })
10+
} catch (error) {
11+
console.error(error)
12+
}
713
})
Binary file not shown.
-31.3 KB
Loading
-1.27 KB
Loading
-471 KB
Binary file not shown.

0 commit comments

Comments
 (0)