Java et Playwright avec 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

Configurer et écrire des tests d'accessibilité en utilisant Playwright avec Axe DevTools pour le Web sur Java

Not for use with personal data

Une intégration de l'API chainable Playwright Java pour Axe DevTools.

Prérequis

Installation

Consultez le guide d'installation pour plus d'informations sur l'obtention de l'intégration Playwright de Deque.

Ajoutez Playwright Java à votre pom.xml si ce n'est 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>

Ajoutez la dépendance @axe-core-maven-playwright à votre pom.xml :

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

Développement local

Pour une première installation, utilisez ce qui suit :

mvn clean install

Pour exécuter les tests :

mvn test -q

Pour exécuter des tests individuels :

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

Exemple

Voici un exemple minimal de configuration de Playwright et d'utilisation pour vérifier une page pour les erreurs d'accessibilité :

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 APIs de cette intégration, voir la Référence de l'API Playwright.