
website.automate.jwebrobot.context.ScenarioExecutionContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jwebrobot Show documentation
Show all versions of jwebrobot Show documentation
Reference implementation of the web automation markup language (WAML).
The newest version!
package website.automate.jwebrobot.context;
import org.openqa.selenium.WebDriver;
import website.automate.waml.io.model.main.Scenario;
import website.automate.waml.io.model.main.action.Action;
import java.util.HashMap;
import java.util.Map;
public class ScenarioExecutionContext {
private Integer stepCount = -1;
private Scenario scenario;
private WebDriver driver;
private Map memory = new HashMap<>();
private ScenarioExecutionContext parent;
private GlobalExecutionContext globalContext;
public ScenarioExecutionContext(GlobalExecutionContext globalContext,
Scenario scenario,
WebDriver driver) {
this.globalContext = globalContext;
this.scenario = scenario;
this.driver = driver;
}
public ScenarioExecutionContext createChildContext(Scenario scenario){
return new ScenarioExecutionContext(getGlobalContext(), scenario, getDriver(), getMemory(), this);
}
private ScenarioExecutionContext(GlobalExecutionContext globalContext,
Scenario scenario,
WebDriver driver, Map memory,
ScenarioExecutionContext parent) {
this(globalContext, scenario, driver);
this.memory = memory;
this.parent = parent;
}
public Scenario getScenario() {
return scenario;
}
public WebDriver getDriver() {
return driver;
}
public Map getMemory() {
return memory;
}
public Map getTotalMemory(){
Map totalMemory = new HashMap<>();
totalMemory.putAll(memory);
totalMemory.putAll(getGlobalContext().getMemory());
return totalMemory;
}
public ScenarioExecutionContext getParent() {
return parent;
}
public GlobalExecutionContext getGlobalContext() {
return globalContext;
}
public String getScenarioInclusionPath(){
String result = scenario.getName();
if(parent != null){
return parent.getScenarioInclusionPath() + "/" + result;
}
return result;
}
public Scenario getRootScenario(){
return getRoot().getScenario();
}
public ScenarioExecutionContext getRoot(){
if(parent == null){
return this;
}
return parent.getRoot();
}
public boolean containsScenario(Scenario scenario){
if(this.getScenario().equals(scenario)){
return true;
}
ScenarioExecutionContext parentContext = this.getParent();
if(parentContext == null){
return false;
}
return parentContext.containsScenario(scenario);
}
public void countStep(Action action){
this.stepCount++;
if(this.getParent() != null){
this.getParent().countStep(action);
}
}
public void setScenario(Scenario scenario) {
this.scenario = scenario;
}
public Integer getStepCount() {
return stepCount;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy