-
-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the Evaluate action and the JavaScript question to perform Java…
…Script queries.
- Loading branch information
Showing
22 changed files
with
125 additions
and
42 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
browse-the-web/src/main/java/net/serenitybdd/screenplay/actions/Evaluate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package net.serenitybdd.screenplay.actions; | ||
|
||
import net.serenitybdd.core.steps.Instrumented; | ||
import net.serenitybdd.screenplay.Action; | ||
import net.serenitybdd.screenplay.Actor; | ||
import net.serenitybdd.screenplay.abilities.BrowseTheWeb; | ||
import net.thucydides.core.annotations.Step; | ||
|
||
public class Evaluate implements Action { | ||
|
||
private final String expression; | ||
private Object[] parameters; | ||
|
||
public Evaluate(String expression) { | ||
this.expression = expression; | ||
} | ||
|
||
public Evaluate withParameters(Object... parameters) { | ||
this.parameters = parameters; | ||
return this; | ||
} | ||
|
||
@Step("Execute JavaScript #expression") | ||
public <T extends Actor> void performAs(T theUser) { | ||
BrowseTheWeb.as(theUser).evaluateJavascript(expression, parameters); | ||
} | ||
|
||
public static Evaluate javascript(String expression, Object... parameters) { | ||
Evaluate evaluate = Instrumented.instanceOf(Evaluate.class).withProperties(expression); | ||
return evaluate.withParameters(parameters); | ||
} | ||
|
||
|
||
} |
12 changes: 0 additions & 12 deletions
12
browse-the-web/src/main/java/net/serenitybdd/screenplay/actions/WebAction.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
browse-the-web/src/main/java/net/serenitybdd/screenplay/questions/JavaScript.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package net.serenitybdd.screenplay.questions; | ||
|
||
import net.serenitybdd.screenplay.Actor; | ||
import net.serenitybdd.screenplay.abilities.BrowseTheWeb; | ||
|
||
public class JavaScript extends UIState<String> { | ||
|
||
private final String expression; | ||
private final Object[] parameters; | ||
|
||
public JavaScript(String expression, Object[] parameters, Actor actor) { | ||
super(actor); | ||
this.expression = expression; | ||
this.parameters = parameters; | ||
} | ||
|
||
public static JavaScriptBuilder evaluate(String expression) { | ||
return new JavaScriptBuilder(expression); | ||
} | ||
|
||
@Override | ||
public String resolve() { | ||
return BrowseTheWeb.as(actor).evaluateJavascript(expression, parameters).toString(); | ||
} | ||
|
||
public static final class JavaScriptBuilder { | ||
private final String expression; | ||
private Object[] parameters = new Object[]{}; | ||
|
||
public JavaScriptBuilder(String expression, Object... parameters) { | ||
this.expression = expression; | ||
this.parameters = parameters; | ||
} | ||
|
||
public JavaScriptBuilder withParameters(Object... parameters) { | ||
this.parameters = parameters; | ||
return this; | ||
} | ||
|
||
public JavaScript onTheScreenOf(Actor actor) { | ||
return new JavaScript(expression, parameters, actor); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
browse-the-web/src/main/java/net/serenitybdd/screenplay/questions/TargetedUIState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.serenitybdd.screenplay.questions; | ||
|
||
import net.serenitybdd.screenplay.Actor; | ||
import net.serenitybdd.screenplay.targets.Target; | ||
|
||
import java.util.List; | ||
|
||
public abstract class TargetedUIState<T> extends UIState<T>{ | ||
|
||
protected final Target target; | ||
|
||
protected TargetedUIState(Target target, Actor actor) { | ||
super(actor); | ||
this.target = target; | ||
} | ||
|
||
public abstract List<T> resolveAll(); | ||
|
||
public List<T> asList() { | ||
return resolveAll(); | ||
} | ||
|
||
public <T> List<T> asListOf(Class<T> type) { | ||
return convertToEnums(type, asList()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters