|
| 1 | +package com.serenitydojo.playwright; |
| 2 | + |
| 3 | +import com.deque.html.axecore.playwright.AxeBuilder; |
| 4 | +import com.deque.html.axecore.results.AxeResults; |
| 5 | +import com.microsoft.playwright.*; |
| 6 | +import org.junit.jupiter.api.*; |
| 7 | + |
| 8 | +import java.util.Arrays; |
| 9 | +import java.util.List; |
| 10 | + |
| 11 | +import static org.assertj.core.api.Assertions.assertThat; |
| 12 | + |
| 13 | +public class AccessibilityTest { |
| 14 | + |
| 15 | + private static Playwright playwright; |
| 16 | + private static Browser browser; |
| 17 | + private static BrowserContext browserContext; |
| 18 | + |
| 19 | + Page page; |
| 20 | + |
| 21 | + @BeforeAll |
| 22 | + public static void setUpBrowser() { |
| 23 | + playwright = Playwright.create(); |
| 24 | + browser = playwright.chromium().launch( |
| 25 | + new BrowserType.LaunchOptions() |
| 26 | + .setHeadless(true) |
| 27 | + .setArgs(Arrays.asList("--no-sandbox","--disable-extensions","--disable-gpu")) |
| 28 | + ); |
| 29 | + browserContext = browser.newContext(); |
| 30 | + } |
| 31 | + |
| 32 | + @BeforeEach |
| 33 | + public void setUp() { |
| 34 | + page = browserContext.newPage(); |
| 35 | + } |
| 36 | + |
| 37 | + @AfterAll |
| 38 | + public static void tearDown() { |
| 39 | + browser.close(); |
| 40 | + playwright.close(); |
| 41 | + } |
| 42 | + |
| 43 | + // This test will fail |
| 44 | + @Test |
| 45 | + @Disabled |
| 46 | + void homePageShouldNotHaveAccessibilityIssues() { |
| 47 | + page.navigate("https://practicesoftwaretesting.com"); |
| 48 | + |
| 49 | + AxeResults accessibilityScanResults = new AxeBuilder(page).analyze(); |
| 50 | + |
| 51 | + assertThat(accessibilityScanResults.getViolations()).isEmpty(); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void navBarShouldNotHaveAnyAccessibilityIssues() { |
| 56 | + AxeResults accessibilityScanResults = new AxeBuilder(page) |
| 57 | + .include(List.of(".navbar-nav")) |
| 58 | + .analyze(); |
| 59 | + |
| 60 | + assertThat(accessibilityScanResults.getViolations()).isEmpty(); |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments