All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.serenitybdd.screenplay.actions.WithDevTools Maven / Gradle / Ivy

There is a newer version: 4.2.8
Show newest version
package net.serenitybdd.screenplay.actions;

import net.serenitybdd.markers.CanBeSilent;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Performable;
import net.serenitybdd.screenplay.Question;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import org.openqa.selenium.devtools.DevTools;

import java.util.function.Consumer;
import java.util.function.Function;

/**
 * Perform an action directly using the DevTools API
 * For example:
 * 
 *     
 *         actor.attemptsTo(
 *             WithDevTools.perform(
 *                 devTools -> devTools.createSession()
 *             )
 *         );
 *     
 * 
*/ public class WithDevTools implements Performable, CanBeSilent { private final Consumer action; private boolean isSilent = false; public WithDevTools(Consumer action) { this.action = action; } public static WithDevTools perform(Consumer action) { return new WithDevTools(action); } public static Question ask(Function question) { return actor -> question.apply(BrowseTheWeb.as(actor).getDevTools()); } ; @Override public void performAs(T actor) { action.accept(BrowseTheWeb.as(actor).getDevTools()); } @Override public boolean isSilent() { return isSilent; } public Performable withNoReporting() { this.isSilent = true; return this; } }