Instructions pour Java et Selenium
Configurer vos tests avec Java et Selenium
Not for use with personal data
-
Ajoutez une nouvelle dépendance pour le package Java Watcher à votre section de dépendances (pour Maven) (le package Java Watcher est disponible sur Maven Central) :
pom.xml
<dependencies> <!-- Add this dependency: --> <dependency> <groupId>com.deque.axe_core</groupId> <artifactId>observateur</artifactId> <version>3.10.1</version> <!-- Update this as needed --> </dependency> </dependencies>
-
Add imports for Java Watcher to your testing code:
import com.deque.axe_core.commons.AxeWatcherOptions ; import com.deque.axe_core.selenium.AxeWatcher ; import com.deque.axe_core.selenium.AxeWatcherDriver ;
-
Add setup code for Java Watcher, including your project's API key (obtained from the environment as
API_KEY
):AxeWatcherOptions options = new AxeWatcherOptions() .setApiKey(System.getenv("API_KEY")); AxeWatcher watcher = new AxeWatcher(options); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions = watcher.configure(chromeOptions) ; WebDriver wrappedDriver = watcher.wrapDriver(new ChromeDriver(chromeOptions)) ;
This code snippet creates a new
WebDriver
instance calledwrappedDriver
that you need to cast to use the axe controller methods. -
At the end of your testing session, call
flush()
:((AxeWatcherDriver) wrappedDriver).axeWatcher().flush() ;
L'appel
flush()
indique que l'exécution du test est terminée et que les résultats peuvent être traités et présentés à l'utilisateur.