Java et Playwright avec axe DevTools
Not for use with personal data
Une intégration d'API chaînable Playwright Java pour axe DevTools.
Prérequis
- Playwright. Pour plus d'informations, voir Configuration requise
- Java 8 ou supérieur.
Configuration
Consultez le guide d'installation pour plus d'informations sur l'obtention de l'intégration Playwright à partir de Deque.
Ajoutez Playwright Java à votre pom.xml
si vous ne l'avez pas déjà fait :
<!-- Latest Version: https://mvnrepository.com/artifact/com.microsoft.playwright/playwright -->
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.17.1</version>
</dependency>
Add @axe-core-maven-playwright
dependency to your pom.xml
:
<dependency>
<groupId>com.deque.html.axe-devtools</groupId>
<artifactId>playwright</artifactId>
<version>4.4.0</version>
</dependency>
Local Development
For first time installation, use the following:
mvn clean install
To run the tests:
Mvn test -q
To run individual tests:
// -Dtest=<class>#<function> exemple :
Mvn test -Dtest=PlaywrightJavaTest#shouldReturnAxeResults
Example
The following shows a minimal example of how to set up Playwright and use it to check a page for accessibility errors:
import com.deque.html.maven.axedevtools.playwright.AxePlaywrightBuilder;
import com.deque.html.maven.axedevtools.utility.axeresults.AxeResults;
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Page ;
import com.microsoft.playwright.Playwright ;
import org.junit.Test;
public class MyPlaywrightTestSuite {
@Test
public void testMyWebPage() {
Playwright playwright = Playwright.create();
Browser browser = playwright.chromium()
.launch(new BrowserType.LaunchOptions().setHeadless(true));
Page page = browser.newPage();
page.navigate("https://dequeuniversity.com/demo/mars/");
AxePlaywrightBuilder axePlaywrightBuilder = new AxePlaywrightBuilder(page);
try {
AxeResults axeResults = axePlaywrightBuilder.analyze();
// Do something with axeResults
} catch (RuntimeException e) {
// Do something with the error
}
}
}
Prochaines étapes
Pour plus d'informations sur les API de cette intégration, consultez la Référence API Playwright.