java.lang.Object
net.serenitybdd.screenplay.playwright.questions.JavaScript<T>
All Implemented Interfaces:
net.serenitybdd.screenplay.Question<T>

public class JavaScript<T> extends Object implements net.serenitybdd.screenplay.Question<T>
Evaluate JavaScript and return the result.

Playwright's evaluate method passes arguments directly to the expression. For multiple arguments, use an arrow function with array destructuring:

Sample usage:

     // No arguments
     String title = actor.asksFor(JavaScript.evaluate("document.title"));

     // Single argument
     String value = actor.asksFor(JavaScript.evaluate("arg => document.getElementById(arg).value")
         .withArguments("email"));

     // Multiple arguments (use array destructuring)
     Object result = actor.asksFor(JavaScript.evaluate("([a, b]) => a * b")
         .withArguments(6, 7));
 
  • Method Details

    • evaluate

      public static <T> JavaScript<T> evaluate(String script)
      Evaluate JavaScript and return the result.
    • withArguments

      public JavaScript<T> withArguments(Object... args)
      Provide arguments to the script. Single argument is available directly, multiple arguments are passed as an array.
    • answeredBy

      public T answeredBy(net.serenitybdd.screenplay.Actor actor)
      Specified by:
      answeredBy in interface net.serenitybdd.screenplay.Question<T>
    • toString

      public String toString()
      Overrides:
      toString in class Object