Java e Playwright con Axe DevTools
Configurare e scrivere test di accessibilità usando Playwright con Axe DevTools per il Web per Java
Un'integrazione API concatenabile di Playwright Java per Axe DevTools.
Prerequisiti
- Playwright. Per maggiori informazioni, vedi Requisiti di sistema
- Java 8 o superiore.
Installazione
Consulta la guida all'installazione per maggiori informazioni su come ottenere l'integrazione Playwright da Deque.
Aggiungi Playwright Java al tuo pom.xml se non l'hai già fatto:
<!-- 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>
Aggiungi la dipendenza @axe-core-maven-playwright al tuo pom.xml:
<dependency>
<groupId>com.deque.html.axe-devtools</groupId>
<artifactId>playwright</artifactId>
<version>4.4.0</version>
</dependency>Sviluppo Locale
Per l'installazione iniziale, usa il seguente comando:
mvn clean installPer eseguire i test:
mvn test -qPer eseguire test individuali:
// -Dtest=<class>#<function> example:
mvn test -Dtest=PlaywrightJavaTest#shouldReturnAxeResultsEsempio
Di seguito è riportato un esempio minimo di come configurare Playwright e usarlo per controllare eventuali errori di accessibilità in una pagina:
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
}
}
}Prossimi Passi
Per ulteriori informazioni sulle API di questa integrazione, consulta il Riferimento API di Playwright.
