Java y Playwright con Axe DevTools

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard

Configuración y escritura de pruebas de accesibilidad usando Playwright con Axe DevTools para Web en Java

Not for use with personal data

Una integración de la API encadenable de Playwright Java para Axe DevTools.

Requisitos previos

Configuración

Consulte la guía de instalación para más información sobre cómo obtener la integración de Playwright de Deque.

Agregue Playwright Java a su pom.xml si aún no lo ha hecho:

<!-- 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>

Agregue la dependencia @axe-core-maven-playwright a su pom.xml:

<dependency>
    <groupId>com.deque.html.axe-devtools</groupId>
    <artifactId>playwright</artifactId>
    <version>4.4.0</version>
</dependency>

Desarrollo local

Para la instalación por primera vez, use lo siguiente:

mvn clean install

Para ejecutar las pruebas:

mvn test -q

Para ejecutar pruebas individuales:

// -Dtest=<class>#<function> example:
mvn test -Dtest=PlaywrightJavaTest#shouldReturnAxeResults

Ejemplo

Lo siguiente muestra un ejemplo mínimo de cómo configurar Playwright y usarlo para verificar errores de accesibilidad en una página:

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
        }
    }
}

Próximos pasos

Para más información sobre las APIs de esta integración, consulte la Referencia de API de Playwright.