Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/semantic-pr-footer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ on:

jobs:
semantic-pr-footer:
if: ${{ github.event.pull_request.body != '' }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be touched in a PR like this. All PRs should have descriptions.

runs-on: ubuntu-latest
timeout-minutes: 1
permissions:
pull-requests: read
steps:
- uses: dequelabs/axe-api-team-public/.github/actions/semantic-pr-footer-v1@main
79 changes: 79 additions & 0 deletions java/playwright/basic/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.deque.watcher_examples.playwright</groupId>
<artifactId>basic</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skip.browser.install>false</skip.browser.install>
</properties>
Comment on lines +11 to +16

<dependencies>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.49.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.deque.axe_core</groupId>
<artifactId>watcher</artifactId>
<version>4.4.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.4</version>
</plugin>
<!-- Install Playwright browsers before tests (forked so the CLI's System.exit() won't kill Maven) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>install-playwright-browsers</id>
<phase>process-test-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target unless="skip.browser.install">
<java classname="com.microsoft.playwright.CLI"
classpathref="maven.test.classpath"
fork="true"
failonerror="true">
<arg value="install"/>
<arg value="chromium"/>
</java>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.deque.watcher_examples.playwright;

public class Basic {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.deque.watcher_examples.playwright;

import java.nio.file.Paths;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import com.deque.axe_core.commons.AxeWatcherOptions;
import com.deque.axe_core.playwright.AxeWatcherPage;
import com.deque.axe_core.playwright.AxeWatcherPlaywright;
import com.microsoft.playwright.BrowserContext;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.ElementHandle;
import com.microsoft.playwright.Playwright;


@DisplayName("My Login Application")
class BasicTest {

String apiKey = "test-api-key";
String projectId = "test-project-id";
String serverUrl = "https://axe.deque.com";

Playwright playwright;
BrowserContext browserContext;
AxeWatcherPage page;

@BeforeEach
void setUp() {
AxeWatcherPlaywright axeWatcher =
new AxeWatcherPlaywright(
new AxeWatcherOptions().setApiKey(apiKey).setProjectId(projectId).setServerUrl(serverUrl))
.enableDebugLogger();

BrowserType.LaunchPersistentContextOptions launchOptions =
axeWatcher.configure(
new BrowserType.LaunchPersistentContextOptions()
.setHeadless(true)
.setChannel("chromium")
.setArgs(List.of("--no-sandbox", "--disable-dev-shm-usage")));

playwright = Playwright.create();
// An empty user-data dir lets Playwright create a fresh temporary profile.
browserContext = playwright.chromium().launchPersistentContext(Paths.get(""), launchOptions);
Comment on lines +49 to +50
page = axeWatcher.wrapPage(browserContext.newPage());
}

@AfterEach
void tearDown() {
page.axeWatcher().flush();
browserContext.close();
playwright.close();
}

@Nested
@DisplayName("Login")
class LoginTests {
@Nested
@DisplayName("with valid credentials")
class ShouldLoginTests {
@Test
@DisplayName("should login")
void shouldLoginTest() {
page.navigate("https://the-internet.herokuapp.com/login");

page.locator("#username").fill("tomsmith");
page.locator("#password").fill("SuperSecretPassword!");

page.locator("button[type='submit']").click();

ElementHandle element = page.waitForSelector("#flash");
assertNotNull(element);
}
}
}
}
80 changes: 80 additions & 0 deletions java/playwright/manual-mode/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.deque.watcher_examples.playwright</groupId>
<artifactId>manual-mode</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skip.browser.install>false</skip.browser.install>
</properties>
Comment on lines +11 to +16


<dependencies>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.49.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.deque.axe_core</groupId>
<artifactId>watcher</artifactId>
<version>4.4.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.4</version>
</plugin>
<!-- Install Playwright browsers before tests (forked so the CLI's System.exit() won't kill Maven) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>install-playwright-browsers</id>
<phase>process-test-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target unless="skip.browser.install">
<java classname="com.microsoft.playwright.CLI"
classpathref="maven.test.classpath"
fork="true"
failonerror="true">
<arg value="install"/>
<arg value="chromium"/>
</java>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.deque.watcher_examples.playwright;

public class ManualMode {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.deque.watcher_examples.playwright;

import java.nio.file.Paths;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import com.deque.axe_core.commons.AxeWatcherOptions;
import com.deque.axe_core.playwright.AxeWatcherPage;
import com.deque.axe_core.playwright.AxeWatcherPlaywright;
import com.microsoft.playwright.BrowserContext;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.ElementHandle;
import com.microsoft.playwright.Playwright;


@DisplayName("My Login Application")
class ManualModeTest {

String apiKey = "test-api-key";
String projectId = "test-project-id";
String serverUrl = "https://axe.deque.com";

Playwright playwright;
BrowserContext browserContext;
AxeWatcherPage page;

@BeforeEach
void setUp() {
AxeWatcherPlaywright axeWatcher =
new AxeWatcherPlaywright(
new AxeWatcherOptions()
.setApiKey(apiKey)
.setProjectId(projectId)
.setServerUrl(serverUrl)
// Disable automatic analysis.
.setAutoAnalyze(false))
.enableDebugLogger();

BrowserType.LaunchPersistentContextOptions launchOptions =
axeWatcher.configure(
new BrowserType.LaunchPersistentContextOptions()
.setHeadless(true)
.setChannel("chromium")
.setArgs(List.of("--no-sandbox", "--disable-dev-shm-usage")));

playwright = Playwright.create();
browserContext = playwright.chromium().launchPersistentContext(Paths.get(""), launchOptions);
page = axeWatcher.wrapPage(browserContext.newPage());
}

@AfterEach
void tearDown() {
// Flush axe-watcher results after each test.
page.axeWatcher().flush();
browserContext.close();
playwright.close();
}

@Nested
@DisplayName("Login")
class LoginTests {
@Nested
@DisplayName("with valid credentials")
class ShouldLoginTests {
@Test
@DisplayName("should login")
void shouldLoginTest() {
/*
Let's calculate the number of page states.
Auto-analyze is false, so it will not analyze automatically.

We navigate to the page,
then manually analyze it. (+1)
We fill out the form,
then turn on auto-analysis.
We click the button,
causing an auto-analysis (+1),
then assure the element appears.
We turn off auto-analysis,
then analyze manually (+1).

So, we expect the total number of page states to be 3.
*/
page.navigate("https://the-internet.herokuapp.com/login");
// Analyze after navigating to the page.
page.axeWatcher().analyze();

page.locator("#username").fill("tomsmith");
page.locator("#password").fill("SuperSecretPassword!");
// Start automatic axe analysis.
page.axeWatcher().start();

page.locator("button[type='submit']").click();

ElementHandle element = page.waitForSelector("#flash");
assertNotNull(element);

// Stop automatic axe analysis.
page.axeWatcher().stop();
// Analyze after logging in.
page.axeWatcher().analyze();
}
}
}
}
Loading