Java e Playwright com 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

Configurando e escrevendo testes de acessibilidade usando Playwright com Axe DevTools para Web em Java

Not for use with personal data

Uma integração da API encadeável do Playwright Java para Axe DevTools.

Pré-requisitos

Configuração

Veja o guia de instalação para mais informações sobre como obter a integração Playwright da Deque.

Adicione o Playwright Java ao seu pom.xml se ainda não tiver feito isso:

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

Adicione a dependência @axe-core-maven-playwright ao seu pom.xml:

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

Desenvolvimento Local

Para instalação pela primeira vez, use o seguinte:

mvn clean install

Para executar os testes:

mvn test -q

Para executar testes individuais:

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

Exemplo

O seguinte mostra um exemplo mínimo de como configurar o Playwright e usá-lo para verificar uma página em busca de erros de acessibilidade:

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 Passos

Para mais informações sobre as APIs desta integração, veja a Referência da API Playwright.