mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
remove driver-web to be replaced with a fresh impl
This commit is contained in:
parent
bec448bcc0
commit
ade9cae769
@ -1,79 +0,0 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>driver-web</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<artifactId>mvn-defaults</artifactId>
|
|
||||||
<groupId>io.nosqlbench</groupId>
|
|
||||||
<version>4.17.5-SNAPSHOT</version>
|
|
||||||
<relativePath>../mvn-defaults</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<name>${project.artifactId}</name>
|
|
||||||
<description>
|
|
||||||
A nosqlbench driver module;
|
|
||||||
Provides the ability to drive steps through the webdriver API.
|
|
||||||
</description>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.nosqlbench</groupId>
|
|
||||||
<artifactId>engine-api</artifactId>
|
|
||||||
<version>4.17.5-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.nosqlbench</groupId>
|
|
||||||
<artifactId>drivers-api</artifactId>
|
|
||||||
<version>4.17.5-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.seleniumhq.selenium</groupId>
|
|
||||||
<artifactId>htmlunit-driver</artifactId>
|
|
||||||
<version>2.39.0</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.seleniumhq.selenium</groupId>
|
|
||||||
<artifactId>selenium-api</artifactId>
|
|
||||||
<version>3.141.59</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.seleniumhq.selenium</groupId>
|
|
||||||
<artifactId>selenium-remote-driver</artifactId>
|
|
||||||
<version>3.141.59</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.seleniumhq.selenium</groupId>
|
|
||||||
<artifactId>selenium-java</artifactId>
|
|
||||||
<version>3.141.59</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.seleniumhq.selenium</groupId>
|
|
||||||
<artifactId>selenium-chrome-driver</artifactId>
|
|
||||||
<version>3.141.59</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.seleniumhq.selenium</groupId>
|
|
||||||
<artifactId>selenium-htmlunit-driver</artifactId>
|
|
||||||
<version>2.52.0</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
|
||||||
<artifactId>httpclient</artifactId>
|
|
||||||
<version>4.5.13</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,93 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver;
|
|
||||||
|
|
||||||
import org.openqa.selenium.*;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class WebContext {
|
|
||||||
private final static Logger logger = LogManager.getLogger(WebContext.class);
|
|
||||||
|
|
||||||
private final WebDriver rootwindow;
|
|
||||||
WebDriver focus;
|
|
||||||
|
|
||||||
LinkedList<WebElement> elements = new LinkedList<>();
|
|
||||||
private final LinkedList<Cookie> cookies = new LinkedList<>();
|
|
||||||
private final HashMap<String,Object> vars = new HashMap<>();
|
|
||||||
private Alert alert;
|
|
||||||
|
|
||||||
public WebContext(WebDriver initial) {
|
|
||||||
this.focus = initial;
|
|
||||||
this.rootwindow = initial;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pushElement(WebElement element) {
|
|
||||||
elements.push(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WebElement peekElement() {
|
|
||||||
return elements.peek();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LinkedList<Cookie> getCookies() {
|
|
||||||
return cookies;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LinkedList<WebElement> getElements() {
|
|
||||||
return elements;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setElements(List<WebElement> elements) {
|
|
||||||
this.elements.clear();
|
|
||||||
this.elements.addAll(elements);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pushCookie(Cookie cookie) {
|
|
||||||
this.cookies.push(cookie);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCookies(Collection<Cookie> cookies) {
|
|
||||||
this.cookies.clear();
|
|
||||||
this.cookies.addAll(cookies);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAlert(Alert alert) {
|
|
||||||
this.alert = alert;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Alert getAlert() {
|
|
||||||
return alert;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WebDriver driver() {
|
|
||||||
return focus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFocus(WebDriver driver) {
|
|
||||||
this.focus =driver;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearAlert() {
|
|
||||||
this.alert=null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVar(String key, Object value) {
|
|
||||||
this.vars.put(key,value);
|
|
||||||
logger.debug("context vars: '" + key + "'='" + value.toString() + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> T getVar(String name, Class<? extends T> type) {
|
|
||||||
Object o = this.vars.get(name);
|
|
||||||
if (o==null) { return null; }
|
|
||||||
|
|
||||||
if (type.isAssignableFrom(o.getClass())) {
|
|
||||||
return type.cast(o);
|
|
||||||
}
|
|
||||||
throw new RuntimeException("Could not cast named var '" + name + "' to a " + type.getCanonicalName());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.verbs.WebDriverVerbs;
|
|
||||||
import io.nosqlbench.engine.api.activityapi.core.ActivityDefObserver;
|
|
||||||
import io.nosqlbench.engine.api.activityapi.core.SyncAction;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
|
|
||||||
import io.nosqlbench.engine.api.templating.CommandTemplate;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds the definition and tracking state for a web driver command.
|
|
||||||
*/
|
|
||||||
public class WebDriverAction implements SyncAction, ActivityDefObserver {
|
|
||||||
private final static Logger logger = LogManager.getLogger(WebDriverAction.class);
|
|
||||||
|
|
||||||
private final WebDriverActivity activity;
|
|
||||||
private final int slot;
|
|
||||||
// warn or count, or stop
|
|
||||||
private String errors;
|
|
||||||
private boolean dryrun;
|
|
||||||
private WebContext context;
|
|
||||||
|
|
||||||
public WebDriverAction(WebDriverActivity activity, int slot) {
|
|
||||||
super();
|
|
||||||
this.activity = activity;
|
|
||||||
this.slot = slot;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init() {
|
|
||||||
onActivityDefUpdate(activity.getActivityDef());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityDefUpdate(ActivityDef activityDef) {
|
|
||||||
this.errors = activityDef.getParams().getOptionalString("errors").orElse("stop");
|
|
||||||
this.dryrun = activityDef.getParams().getOptionalBoolean("dryrun").orElse(false);
|
|
||||||
this.context = activity.getWebContext(slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: resolve inner templates early, perhaps optionally
|
|
||||||
// As it is right now, all commands are resolved dynamically, which is still not going to be the limiting
|
|
||||||
// factor.
|
|
||||||
@Override
|
|
||||||
public int runCycle(long cycle) {
|
|
||||||
|
|
||||||
CommandTemplate commandTemplate = activity.getOpSequence().apply(cycle);
|
|
||||||
try {
|
|
||||||
WebDriverVerbs.execute(cycle, commandTemplate, context, dryrun);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Error with cycle(" + cycle + "), statement(" + commandTemplate.getName() + "): " + e.getMessage());
|
|
||||||
if (errors.equals("stop")) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,229 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import io.nosqlbench.driver.webdriver.side.Command;
|
|
||||||
import io.nosqlbench.driver.webdriver.side.SideConfig;
|
|
||||||
import io.nosqlbench.driver.webdriver.side.Test;
|
|
||||||
import io.nosqlbench.engine.api.activityapi.planning.OpSequence;
|
|
||||||
import io.nosqlbench.engine.api.activityapi.planning.SequencePlanner;
|
|
||||||
import io.nosqlbench.engine.api.activityapi.planning.SequencerType;
|
|
||||||
import io.nosqlbench.engine.api.activityconfig.StatementsLoader;
|
|
||||||
import io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate;
|
|
||||||
import io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.SimpleActivity;
|
|
||||||
import io.nosqlbench.engine.api.templating.CommandTemplate;
|
|
||||||
import io.nosqlbench.engine.api.templating.StrInterpolator;
|
|
||||||
import io.nosqlbench.nb.api.content.NBIO;
|
|
||||||
import io.nosqlbench.nb.api.errors.BasicError;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
import org.openqa.selenium.chrome.ChromeDriver;
|
|
||||||
import org.openqa.selenium.chrome.ChromeOptions;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class WebDriverActivity extends SimpleActivity {
|
|
||||||
|
|
||||||
private final static Logger logger = LogManager.getLogger(WebDriverActivity.class);
|
|
||||||
|
|
||||||
// private final StmtsDocList stmtsDocList;
|
|
||||||
private OpSequence<CommandTemplate> opSequence;
|
|
||||||
|
|
||||||
private final ConcurrentHashMap<Integer,WebContext> contexts = new ConcurrentHashMap<>();
|
|
||||||
// private static ThreadLocal<WebContext> TL_WebContext = new ThreadLocal<>();
|
|
||||||
|
|
||||||
public WebDriverActivity(ActivityDef activityDef) {
|
|
||||||
super(activityDef);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initActivity() {
|
|
||||||
super.initActivity();
|
|
||||||
this.opSequence = initOpSequence();
|
|
||||||
onActivityDefUpdate(activityDef);
|
|
||||||
setDefaultsFromOpSequence(opSequence);
|
|
||||||
int threads = getActivityDef().getThreads();
|
|
||||||
logger.info("pre-initializing web browsers");
|
|
||||||
for (int i = 0; i < threads; i++) {
|
|
||||||
getWebContext(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private OpSequence<CommandTemplate> initOpSequence() {
|
|
||||||
OpSequence<CommandTemplate> sequence;
|
|
||||||
|
|
||||||
String yaml_loc = getParams().getOptionalString("yaml","workload").orElse(null);
|
|
||||||
String side_loc = getParams().getOptionalString("side").orElse(null);
|
|
||||||
|
|
||||||
if (yaml_loc == null && side_loc == null) {
|
|
||||||
throw new BasicError("You must provide yaml= or side=, but neither was found");
|
|
||||||
}
|
|
||||||
if (yaml_loc != null && side_loc != null) {
|
|
||||||
throw new BasicError("You must provide either yaml= or side=, but not both.");
|
|
||||||
}
|
|
||||||
if (yaml_loc != null) {
|
|
||||||
sequence=initOpSequenceFromYaml();
|
|
||||||
} else {
|
|
||||||
sequence=initOpSequenceFromSide();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sequence.getSequence().length==0) {
|
|
||||||
logger.warn("The sequence contains zero operations.");
|
|
||||||
}
|
|
||||||
return sequence;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private OpSequence<CommandTemplate> initOpSequenceFromSide() {
|
|
||||||
|
|
||||||
Optional<String> sideFile = activityDef.getParams().getOptionalString("side");
|
|
||||||
String sideToImport = sideFile.get();
|
|
||||||
String side = NBIO.all().name(sideToImport).extension("side").one().asString();
|
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
||||||
SideConfig sc = gson.fromJson(side, SideConfig.class);
|
|
||||||
String sideName = sc.getName();
|
|
||||||
String sideUrl = sc.getUrl();
|
|
||||||
|
|
||||||
LinkedHashMap<String,String> commands = new LinkedHashMap<>();
|
|
||||||
for (Test test : sc.getTests()) {
|
|
||||||
int idx=0;
|
|
||||||
StringBuilder testBuilder = new StringBuilder();
|
|
||||||
for (Command command : test.getCommands()) {
|
|
||||||
StringBuilder cmdBuilder = new StringBuilder();
|
|
||||||
String cmd = command.getCommand();
|
|
||||||
cmdBuilder.append(cmd);
|
|
||||||
if (command.getCommand().equals("open")) {
|
|
||||||
cmdBuilder.append(" url='").append(sideUrl.replaceAll("'","\\\\'")).append("'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command.getTarget() != null && !command.getTarget().isEmpty()) {
|
|
||||||
String tg=null;
|
|
||||||
if (command.getTargets().size()>0) {
|
|
||||||
for (int i = 0; i < command.getTargets().size(); i++) {
|
|
||||||
List<String> strings = command.getTargets().get(i);
|
|
||||||
if (strings.get(1).equals("xpath:idRelative")) {
|
|
||||||
logger.debug("favoring xpath form of selector:" + strings.get(0));
|
|
||||||
tg=strings.get(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tg==null) {
|
|
||||||
tg = command.getTarget();
|
|
||||||
}
|
|
||||||
cmdBuilder.append(" target='").append(tg.replaceAll("'","\\\\'")).append("'");
|
|
||||||
|
|
||||||
}
|
|
||||||
if (command.getValue() != null && !command.getValue().isEmpty()) {
|
|
||||||
cmdBuilder.append(" value='").append(command.getValue().replaceAll("'","\\\\'")).append("'");
|
|
||||||
}
|
|
||||||
cmdBuilder.append("\n");
|
|
||||||
logger.debug("build cmd: '" + testBuilder + "'");
|
|
||||||
String cmdName = sideName+"_"+String.format("%s_%03d", sideName, ++idx);
|
|
||||||
commands.put(cmdName,cmdBuilder.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String export = activityDef.getParams().getOptionalString("export").orElse(null);
|
|
||||||
if (export!=null) {
|
|
||||||
Path exportTo = Path.of(export);
|
|
||||||
if (Files.exists(exportTo)) {
|
|
||||||
throw new BasicError("File exists: " + exportTo + ", remove it first.");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringBuilder stmts = new StringBuilder();
|
|
||||||
stmts.append("statements:\n");
|
|
||||||
commands.forEach((name, cmd)-> {
|
|
||||||
System.out.println("name: " + name);
|
|
||||||
System.out.println("cmd: " + cmd);
|
|
||||||
stmts.append(" - ").append(name).append(": ").append(cmd);
|
|
||||||
});
|
|
||||||
Files.writeString(exportTo,stmts.toString());
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
logger.info("completed importing from " + sideFile + " to " + exportTo);
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
SequencerType sequencerType = getParams()
|
|
||||||
.getOptionalString("seq")
|
|
||||||
.map(SequencerType::valueOf)
|
|
||||||
.orElse(SequencerType.bucket);
|
|
||||||
SequencePlanner<CommandTemplate> planner = new SequencePlanner<>(sequencerType);
|
|
||||||
commands.forEach((name,cmd) -> {
|
|
||||||
CommandTemplate commandTemplate = new CommandTemplate(name, cmd, Map.of(), Map.of(),List.of());
|
|
||||||
planner.addOp(commandTemplate,(c) -> 1L);
|
|
||||||
});
|
|
||||||
OpSequence<CommandTemplate> sequence = planner.resolve();
|
|
||||||
return sequence;
|
|
||||||
}
|
|
||||||
|
|
||||||
private OpSequence<CommandTemplate> initOpSequenceFromYaml() {
|
|
||||||
StrInterpolator interp = new StrInterpolator(activityDef);
|
|
||||||
String yaml_loc = activityDef.getParams().getOptionalString("yaml", "workload").orElse("default");
|
|
||||||
StmtsDocList stmtsDocList = StatementsLoader.loadPath(logger, yaml_loc, interp, "activities");
|
|
||||||
|
|
||||||
SequencerType sequencerType = getParams()
|
|
||||||
.getOptionalString("seq")
|
|
||||||
.map(SequencerType::valueOf)
|
|
||||||
.orElse(SequencerType.bucket);
|
|
||||||
SequencePlanner<CommandTemplate> planner = new SequencePlanner<>(sequencerType);
|
|
||||||
|
|
||||||
String tagfilter = activityDef.getParams().getOptionalString("tags").orElse("");
|
|
||||||
List<OpTemplate> stmts = stmtsDocList.getStmts(tagfilter);
|
|
||||||
|
|
||||||
if (stmts.size() == 0) {
|
|
||||||
throw new BasicError("There were no active statements with tag filter '" + tagfilter + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (OpTemplate optpl : stmts) {
|
|
||||||
long ratio = optpl.getParamOrDefault("ratio", 1);
|
|
||||||
CommandTemplate cmd = new CommandTemplate(optpl);
|
|
||||||
planner.addOp(cmd, ratio);
|
|
||||||
}
|
|
||||||
return planner.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
public OpSequence<CommandTemplate> getOpSequence() {
|
|
||||||
return opSequence;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public synchronized WebContext getWebContext(int slot) {
|
|
||||||
try {
|
|
||||||
WebContext context = contexts.get(slot);
|
|
||||||
if (context == null) {
|
|
||||||
logger.info("initializing chromedriver for thread " + slot);
|
|
||||||
System.setProperty("webdriver.http.factory", "okhttp");
|
|
||||||
ChromeOptions chromeOptions = new ChromeOptions();
|
|
||||||
chromeOptions.setHeadless(activityDef.getParams().getOptionalBoolean("headless").orElse(false));
|
|
||||||
WebDriver webdriver = new ChromeDriver(chromeOptions);
|
|
||||||
context = new WebContext(webdriver);
|
|
||||||
contexts.put(slot, context);
|
|
||||||
} else {
|
|
||||||
logger.info("using cached chromedriver for thread " + slot);
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void shutdownActivity() {
|
|
||||||
contexts.forEach((s, d) -> {
|
|
||||||
logger.debug("closing driver for thread " + s);
|
|
||||||
d.driver().close();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver;
|
|
||||||
|
|
||||||
import io.nosqlbench.engine.api.activityapi.core.Action;
|
|
||||||
import io.nosqlbench.engine.api.activityapi.core.ActionDispenser;
|
|
||||||
import io.nosqlbench.engine.api.activityapi.core.Activity;
|
|
||||||
import io.nosqlbench.engine.api.activityapi.core.ActivityType;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
|
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
|
||||||
|
|
||||||
@Service(value= ActivityType.class, selector="webdriver")
|
|
||||||
public class WebDriverActivityType implements ActivityType<WebDriverActivity> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public WebDriverActivity getActivity(ActivityDef activityDef) {
|
|
||||||
return new WebDriverActivity(activityDef);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ActionDispenser getActionDispenser(WebDriverActivity activity) {
|
|
||||||
return new WebDriverActionDispenser(activity);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class WebDriverActionDispenser implements ActionDispenser {
|
|
||||||
|
|
||||||
private final Activity activity;
|
|
||||||
|
|
||||||
private WebDriverActionDispenser(Activity activity) {
|
|
||||||
this.activity = activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Action getAction(int slot) {
|
|
||||||
return new WebDriverAction((WebDriverActivity) activity, slot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver;
|
|
||||||
|
|
||||||
public class WebDriverCmdState {
|
|
||||||
|
|
||||||
private final WebDriverAction action;
|
|
||||||
private final long cycle;
|
|
||||||
|
|
||||||
public WebDriverCmdState(WebDriverAction action, long cycle) {
|
|
||||||
|
|
||||||
this.action = action;
|
|
||||||
this.cycle = cycle;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.side;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Command {
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getComment() {
|
|
||||||
return comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setComment(String comment) {
|
|
||||||
this.comment = comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCommand() {
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommand(String command) {
|
|
||||||
this.command = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTarget() {
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTarget(String target) {
|
|
||||||
this.target = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<List<String>> getTargets() {
|
|
||||||
return targets;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTargets(List<List<String>> targets) {
|
|
||||||
this.targets = targets;
|
|
||||||
}
|
|
||||||
|
|
||||||
String id;
|
|
||||||
String comment;
|
|
||||||
String command;
|
|
||||||
String target;
|
|
||||||
String value;
|
|
||||||
List<List<String>> targets;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Command{" +
|
|
||||||
"id='" + id + '\'' +
|
|
||||||
", comment='" + comment + '\'' +
|
|
||||||
", command='" + command + '\'' +
|
|
||||||
", target='" + target + '\'' +
|
|
||||||
", value='" + value + '\'' +
|
|
||||||
", targets=" + targets +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.side;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SideConfig {
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(String version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Test> getTests() {
|
|
||||||
return tests;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTests(List<Test> tests) {
|
|
||||||
this.tests = tests;
|
|
||||||
}
|
|
||||||
|
|
||||||
String id;
|
|
||||||
String name;
|
|
||||||
String version;
|
|
||||||
String url;
|
|
||||||
List<Test> tests;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "SideConfig{" +
|
|
||||||
"id='" + id + '\'' +
|
|
||||||
", name='" + name + '\'' +
|
|
||||||
", version='" + version + '\'' +
|
|
||||||
", url='" + url + '\'' +
|
|
||||||
", tests=" + tests +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.side;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Test {
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Command> getCommands() {
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommands(List<Command> commands) {
|
|
||||||
this.commands = commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
String id;
|
|
||||||
String name;
|
|
||||||
List<Command> commands;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Test{" +
|
|
||||||
"id='" + id + '\'' +
|
|
||||||
", name='" + name + '\'' +
|
|
||||||
", commands=" + commands +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Alert;
|
|
||||||
|
|
||||||
import java.security.InvalidParameterException;
|
|
||||||
|
|
||||||
public class AcceptAlert implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
Alert alert = context.getAlert();
|
|
||||||
if (alert==null) {
|
|
||||||
alert = context.driver().switchTo().alert();
|
|
||||||
}
|
|
||||||
if (alert==null) {
|
|
||||||
throw new InvalidParameterException("Alert is not present");
|
|
||||||
}
|
|
||||||
alert.accept();
|
|
||||||
context.clearAlert();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Cookie;
|
|
||||||
|
|
||||||
public class AddCookie implements WebDriverVerb {
|
|
||||||
|
|
||||||
private final Cookie cookie;
|
|
||||||
|
|
||||||
public AddCookie(Cookie cookie) {
|
|
||||||
this.cookie = cookie;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().manage().addCookie(this.cookie);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
|
|
||||||
public class AssertElement implements WebDriverVerb {
|
|
||||||
private final static Logger logger = LogManager.getLogger(AssertElement.class);
|
|
||||||
private final By by;
|
|
||||||
|
|
||||||
public AssertElement(By by) {
|
|
||||||
this.by = by;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
WebElement element = context.driver().findElement(by);
|
|
||||||
context.pushElement(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public enum Bys {
|
|
||||||
id(By::id),
|
|
||||||
linkText(By::linkText),
|
|
||||||
name(By::name),
|
|
||||||
css(By::cssSelector),
|
|
||||||
xpath(By::xpath),
|
|
||||||
classname(By::className);
|
|
||||||
|
|
||||||
private Function<String, By> initializer;
|
|
||||||
|
|
||||||
Bys(Function<String,By> initializer) {
|
|
||||||
this.initializer = initializer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static By get(String by) {
|
|
||||||
Bys bys =classname;
|
|
||||||
String[] parts = by.split("=", 2);
|
|
||||||
if (parts.length==2) {
|
|
||||||
bys= Bys.valueOf(parts[0]);
|
|
||||||
by = parts[1];
|
|
||||||
}
|
|
||||||
return bys.initializer.apply(by);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class ClearElement implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.peekElement().clear();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
|
|
||||||
public class ClearElementBy implements WebDriverVerb {
|
|
||||||
private final By by;
|
|
||||||
|
|
||||||
public ClearElementBy(By by) {
|
|
||||||
this.by = by;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.peekElement().findElement(by).clear();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
|
|
||||||
public class ClickElementBy implements WebDriverVerb {
|
|
||||||
|
|
||||||
private final By by;
|
|
||||||
|
|
||||||
public ClickElementBy(By by){
|
|
||||||
this.by = by;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().findElement(by).click();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import org.openqa.selenium.Cookie;
|
|
||||||
|
|
||||||
import java.sql.Date;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class CookieJar {
|
|
||||||
public static Cookie cookie(Map<String,String> props) {
|
|
||||||
String name = props.get("name");
|
|
||||||
String value = props.getOrDefault("value","");
|
|
||||||
Cookie.Builder builder = new Cookie.Builder(name, value);
|
|
||||||
Optional.ofNullable(props.get("domain")).ifPresent(builder::domain);
|
|
||||||
Optional.ofNullable(props.get("expiry")).map(Date::valueOf).ifPresent(builder::expiresOn);
|
|
||||||
Optional.ofNullable(props.get("ishttponly")).map(Boolean::valueOf).ifPresent(builder::isHttpOnly);
|
|
||||||
Optional.ofNullable(props.get("issecure")).map(Boolean::valueOf).ifPresent(builder::isSecure);
|
|
||||||
Optional.ofNullable(props.get("path")).ifPresent(builder::path);
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class DeleteAllCookies implements WebDriverVerb {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().manage().deleteAllCookies();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Cookie;
|
|
||||||
|
|
||||||
public class DeleteCookie implements WebDriverVerb {
|
|
||||||
|
|
||||||
private final Cookie cookie;
|
|
||||||
|
|
||||||
public DeleteCookie(Cookie cookie) {
|
|
||||||
this.cookie = cookie;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().manage().deleteCookie(cookie);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class DeleteCookieNamed implements WebDriverVerb {
|
|
||||||
|
|
||||||
private final String cookieName;
|
|
||||||
|
|
||||||
public DeleteCookieNamed(String cookieName) {
|
|
||||||
this.cookieName = cookieName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().manage().deleteCookieNamed(cookieName);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Alert;
|
|
||||||
|
|
||||||
import java.security.InvalidParameterException;
|
|
||||||
|
|
||||||
public class DismissAlert implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
Alert alert = context.getAlert();
|
|
||||||
if (alert==null) {
|
|
||||||
alert = context.driver().switchTo().alert();
|
|
||||||
}
|
|
||||||
if (alert==null) {
|
|
||||||
throw new InvalidParameterException("Alert is not present");
|
|
||||||
}
|
|
||||||
alert.dismiss();
|
|
||||||
context.clearAlert();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.OutputType;
|
|
||||||
|
|
||||||
public class ElementScreenShot implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
String screenshotAs = context.peekElement().getScreenshotAs(OutputType.BASE64);
|
|
||||||
// This needs more work
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class ElementSendKeys implements WebDriverVerb {
|
|
||||||
private final CharSequence keys;
|
|
||||||
|
|
||||||
public ElementSendKeys(CharSequence keys) {
|
|
||||||
this.keys = keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.peekElement().sendKeys(keys);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class ElementSubmit implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.peekElement().submit();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import org.openqa.selenium.NoSuchElementException;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
|
|
||||||
public class FindElement implements WebDriverVerb {
|
|
||||||
private final static Logger logger = LogManager.getLogger(FindElement.class);
|
|
||||||
|
|
||||||
private final By by;
|
|
||||||
|
|
||||||
public FindElement(String by) {
|
|
||||||
this.by = Bys.get(by);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
try {
|
|
||||||
WebElement element = context.driver().findElement(by);
|
|
||||||
context.pushElement(element);
|
|
||||||
} catch (NoSuchElementException nsee) {
|
|
||||||
context.pushElement(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
|
|
||||||
public class FindElementInElementBy implements WebDriverVerb {
|
|
||||||
private final By by;
|
|
||||||
|
|
||||||
public FindElementInElementBy(By by) {
|
|
||||||
this.by = by;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
WebElement element = context.peekElement().findElement(by);
|
|
||||||
context.pushElement(element);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import org.openqa.selenium.NoSuchElementException;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class FindElements implements WebDriverVerb {
|
|
||||||
private final static Logger logger = LogManager.getLogger(FindElements.class);
|
|
||||||
|
|
||||||
private final By by;
|
|
||||||
|
|
||||||
public FindElements(String by) {
|
|
||||||
this.by = Bys.get(by);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
try {
|
|
||||||
List<WebElement> elements = context.driver().findElements(by);
|
|
||||||
context.setElements(elements);
|
|
||||||
} catch (NoSuchElementException nsee) {
|
|
||||||
context.pushElement(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class FindElementsInElementBy implements WebDriverVerb {
|
|
||||||
|
|
||||||
private final By by;
|
|
||||||
|
|
||||||
public FindElementsInElementBy(By by) {
|
|
||||||
this.by = by;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
List<WebElement> elements = context.peekElement().findElements(by);
|
|
||||||
context.setElements(elements);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class FullScreen implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().manage().window().fullscreen();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
public class Get implements WebDriverVerb {
|
|
||||||
private final static Logger logger = LogManager.getLogger(Get.class);
|
|
||||||
|
|
||||||
private final String target;
|
|
||||||
|
|
||||||
public Get(String target) {
|
|
||||||
this.target = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().get(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Cookie;
|
|
||||||
|
|
||||||
public class GetCookieNamed implements WebDriverVerb {
|
|
||||||
private final String cookieName;
|
|
||||||
|
|
||||||
public GetCookieNamed(String cookieName) {
|
|
||||||
this.cookieName = cookieName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
Cookie cookie = context.driver().manage().getCookieNamed(cookieName);
|
|
||||||
context.pushCookie(cookie);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Cookie;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class GetCookies implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
Set<Cookie> cookies = context.driver().manage().getCookies();
|
|
||||||
context.setCookies(cookies);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class GetElementAttribute implements WebDriverVerb {
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
public GetElementAttribute(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
String attribute = context.peekElement().getAttribute(name);
|
|
||||||
context.setVar("element.attribute",attribute);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
class GetElementCssValue implements WebDriverVerb {
|
|
||||||
|
|
||||||
private final String propname;
|
|
||||||
public GetElementCssValue(String propname) {
|
|
||||||
this.propname = propname;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
String cssValue = context.peekElement().getCssValue(propname);
|
|
||||||
context.setVar("element.cssvalue",cssValue);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Point;
|
|
||||||
|
|
||||||
public class GetElementLocation implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
Point location = context.peekElement().getLocation();
|
|
||||||
context.setVar("element.location",location);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Rectangle;
|
|
||||||
|
|
||||||
public class GetElementRect implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
Rectangle rect = context.peekElement().getRect();
|
|
||||||
context.setVar("element.rect",rect);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Dimension;
|
|
||||||
|
|
||||||
public class GetElementSize implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
Dimension size = context.peekElement().getSize();
|
|
||||||
context.setVar("element.size",size);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class GetElementTagname implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
String tagName = context.peekElement().getTagName();
|
|
||||||
context.setVar("element.tagname",tagName);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class GetElementText implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
String text = context.peekElement().getText();
|
|
||||||
context.setVar("element.text",text);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class IsElementDisplayed implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
boolean displayed = context.peekElement().isDisplayed();
|
|
||||||
context.setVar("element.displayed",displayed);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class IsElementEnabled implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
boolean enabled = context.peekElement().isEnabled();
|
|
||||||
context.setVar("element.enabled",enabled);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class IsElementSelected implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
boolean selected = context.peekElement().isSelected();
|
|
||||||
context.setVar("element.selected",selected);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
import org.openqa.selenium.interactions.Actions;
|
|
||||||
|
|
||||||
public class MouseOut implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
WebDriver driver = context.driver();
|
|
||||||
WebElement element = driver.findElement(By.tagName("body"));
|
|
||||||
Actions actions = new Actions(driver);
|
|
||||||
actions.moveToElement(element, 0, 0).perform();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
import org.openqa.selenium.interactions.Actions;
|
|
||||||
|
|
||||||
public class MouseOver implements WebDriverVerb {
|
|
||||||
private final By by;
|
|
||||||
|
|
||||||
public MouseOver(By by) {
|
|
||||||
this.by = by;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
WebDriver driver = context.driver();
|
|
||||||
WebElement mouseOverElement = driver.findElement(by);
|
|
||||||
Actions actions = new Actions(driver);
|
|
||||||
actions.moveToElement(mouseOverElement);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class NavigateBack implements WebDriverVerb {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().navigate().back();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class NavigateForward implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().navigate().forward();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class NavigateRefresh implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().navigate().refresh();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class NavigateTo implements WebDriverVerb {
|
|
||||||
|
|
||||||
private final URL url;
|
|
||||||
|
|
||||||
public NavigateTo(String to) {
|
|
||||||
try {
|
|
||||||
this.url = new URL(to);
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().navigate().to(url);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class Open implements WebDriverVerb {
|
|
||||||
private final String url;
|
|
||||||
private final String target;
|
|
||||||
|
|
||||||
public Open(String url, String target) {
|
|
||||||
this.url = url;
|
|
||||||
this.target = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().get(url+target);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Alert;
|
|
||||||
|
|
||||||
import java.security.InvalidParameterException;
|
|
||||||
|
|
||||||
public class SendKeysToAlert implements WebDriverVerb {
|
|
||||||
private final String keys;
|
|
||||||
|
|
||||||
public SendKeysToAlert(String keys) {
|
|
||||||
this.keys = keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
Alert alert = context.getAlert();
|
|
||||||
if (alert==null) {
|
|
||||||
alert = context.driver().switchTo().alert();
|
|
||||||
}
|
|
||||||
if (alert==null) {
|
|
||||||
throw new InvalidParameterException("Alert is not present");
|
|
||||||
}
|
|
||||||
alert.sendKeys(keys);
|
|
||||||
context.clearAlert();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Dimension;
|
|
||||||
|
|
||||||
public class SetWindowSize implements WebDriverVerb {
|
|
||||||
private final int width;
|
|
||||||
private final int height;
|
|
||||||
|
|
||||||
public SetWindowSize(int width, int height) {
|
|
||||||
this.width = width;
|
|
||||||
this.height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetWindowSize(String size) {
|
|
||||||
String[] xes = size.split("x");
|
|
||||||
this.width = Integer.parseInt(xes[0]);
|
|
||||||
this.height = Integer.parseInt(xes[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().manage().window().setSize(new Dimension(width, height));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
|
|
||||||
public class SwitchToActiveElement implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
WebElement webElement = context.driver().switchTo().activeElement();
|
|
||||||
context.pushElement(webElement);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Alert;
|
|
||||||
|
|
||||||
public class SwitchToAlert implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
Alert alert = context.driver().switchTo().alert();
|
|
||||||
context.setAlert(alert);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
|
|
||||||
public class SwitchToDefaultContent implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
WebDriver driver = context.driver().switchTo().defaultContent();
|
|
||||||
context.setFocus(driver);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
|
|
||||||
public class SwitchToFrameByName implements WebDriverVerb {
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public SwitchToFrameByName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
WebDriver frame = context.driver().switchTo().frame(this.name);
|
|
||||||
context.setFocus(frame);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
|
|
||||||
import java.security.InvalidParameterException;
|
|
||||||
|
|
||||||
public class SwitchToFrameElement implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
WebElement webElement = context.peekElement();
|
|
||||||
if (webElement==null) {
|
|
||||||
throw new InvalidParameterException("There was no previously found element to switch to.");
|
|
||||||
}
|
|
||||||
WebDriver frame = context.driver().switchTo().frame(webElement);
|
|
||||||
context.setFocus(frame);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
|
|
||||||
public class SwitchToFrameElementBy implements WebDriverVerb {
|
|
||||||
|
|
||||||
private final By by;
|
|
||||||
|
|
||||||
public SwitchToFrameElementBy(String by) {
|
|
||||||
this.by = Bys.get(by);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
WebElement element = context.driver().findElement(by);
|
|
||||||
WebDriver frame = context.driver().switchTo().frame(element);
|
|
||||||
context.setFocus(frame);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
|
|
||||||
public class SwitchToFrameIdx implements WebDriverVerb {
|
|
||||||
private final int index;
|
|
||||||
|
|
||||||
public SwitchToFrameIdx(int index) {
|
|
||||||
this.index = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
WebDriver frame = context.driver().switchTo().frame(index);
|
|
||||||
context.setFocus(frame);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
|
|
||||||
public class SwitchToParentFrame implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
WebDriver webDriver = context.driver().switchTo().parentFrame();
|
|
||||||
context.setFocus(webDriver);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
|
|
||||||
public class SwitchToWindow implements WebDriverVerb {
|
|
||||||
private final String windowName;
|
|
||||||
|
|
||||||
public SwitchToWindow(String windowName) {
|
|
||||||
this.windowName = windowName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
WebDriver window = context.driver().switchTo().window(this.windowName);
|
|
||||||
context.setFocus(window);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All WebDriverVerb implementations are executable commands.
|
|
||||||
*/
|
|
||||||
public interface WebDriverVerb {
|
|
||||||
/**
|
|
||||||
* Execute the command.
|
|
||||||
*
|
|
||||||
* @param context The context object allows verbs to do have state from one command to the next. It is a
|
|
||||||
* {@link ThreadLocal} object which can be modified by any verb.
|
|
||||||
*/
|
|
||||||
void execute(WebContext context);
|
|
||||||
}
|
|
@ -1,146 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import io.nosqlbench.engine.api.templating.CommandTemplate;
|
|
||||||
import io.nosqlbench.nb.api.errors.BasicError;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.security.InvalidParameterException;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inspiration for how to make this work consistently with the exporter logic
|
|
||||||
* is found at
|
|
||||||
*
|
|
||||||
* <a href="https://github.com/SeleniumHQ/selenium-ide/blob/code-export-java/packages/code-export-java-junit/src/command.js">
|
|
||||||
* The JUnit exporter command generator</a>
|
|
||||||
*/
|
|
||||||
public class WebDriverVerbs {
|
|
||||||
private final static Logger logger = LogManager.getLogger(WebDriverVerbs.class);
|
|
||||||
public final static String COMMAND = "command";
|
|
||||||
|
|
||||||
public enum Verb {
|
|
||||||
|
|
||||||
open(Open.class, (m) -> new Open(m.get("url"),m.get("target"))),
|
|
||||||
get(Get.class, (m) -> new Get(m.get("target"))),
|
|
||||||
mouseOver(MouseOver.class, (m) -> new MouseOver(Bys.get(m.get("target")))),
|
|
||||||
mouseOut(MouseOut.class,(m) -> new MouseOut()),
|
|
||||||
setWindowSize(SetWindowSize.class,(m) -> new SetWindowSize(m.get("target"))),
|
|
||||||
|
|
||||||
// find_element(FindElement.class, (m) -> new FindElement(m.get("by"))),
|
|
||||||
// find_elements(FindElements.class, (m) -> new FindElements(m.get("by"))),
|
|
||||||
//
|
|
||||||
// // navigation
|
|
||||||
// back(NavigateBack.class, (m) -> new NavigateBack()),
|
|
||||||
// forward(NavigateForward.class, (m) -> new NavigateForward()),
|
|
||||||
// refresh(NavigateRefresh.class, (m) -> new NavigateRefresh()),
|
|
||||||
// to(NavigateTo.class, (m) -> new NavigateTo(m.get("to"))),
|
|
||||||
//
|
|
||||||
// // options
|
|
||||||
// add_cookie(AddCookie.class, (m) -> new AddCookie(CookieJar.cookie(m))),
|
|
||||||
// delete_cookie(DeleteCookie.class, (m) -> new DeleteCookie(CookieJar.cookie(m))),
|
|
||||||
// delete_all_cookies(DeleteAllCookies.class, (m) -> new DeleteAllCookies()),
|
|
||||||
// delete_cookie_named(DeleteCookieNamed.class, (m) -> new DeleteCookieNamed(m.get("name"))),
|
|
||||||
// get_cookie_named(GetCookieNamed.class, (m) -> new GetCookieNamed(m.get("name"))),
|
|
||||||
// get_cookies(GetCookies.class, (m) -> new GetCookies()),
|
|
||||||
//
|
|
||||||
// // TargetLocator (switchTo)
|
|
||||||
// switchto_active_element(SwitchToActiveElement.class, (m) -> new SwitchToActiveElement()),
|
|
||||||
// switchto_alert(SwitchToAlert.class, (m) -> new SwitchToAlert()),
|
|
||||||
// switchto_default_content(SwitchToDefaultContent.class, (m) -> new SwitchToDefaultContent()),
|
|
||||||
// switchto_frame_idx(SwitchToFrameIdx.class, (m) -> new SwitchToFrameIdx(Integer.parseInt(m.get("index")))),
|
|
||||||
// switchto_frame_elem_by(SwitchToFrameElementBy.class, (m) -> new SwitchToFrameElementBy(m.get("by"))),
|
|
||||||
// switchto_frame_elem(SwitchToFrameElement.class, (m) -> new SwitchToFrameElement()),
|
|
||||||
// switchto_frame_name(SwitchToFrameByName.class, (m) -> new SwitchToFrameByName(m.get("name"))),
|
|
||||||
// switchto_parent_frame(SwitchToParentFrame.class, (m) -> new SwitchToParentFrame()),
|
|
||||||
// switchto_window(SwitchToWindow.class, (m) -> new SwitchToWindow(m.get("name"))),
|
|
||||||
//
|
|
||||||
// // Alert
|
|
||||||
// dismiss_alert(DismissAlert.class, (m) -> new DismissAlert()),
|
|
||||||
// accept_alert(AcceptAlert.class, (m) -> new AcceptAlert()),
|
|
||||||
// send_keys_to_alert(SendKeysToAlert.class, (m) -> new SendKeysToAlert(m.get("keys"))),
|
|
||||||
//
|
|
||||||
// // Window
|
|
||||||
// window_full_screen(FullScreen.class, (m) -> new FullScreen()),
|
|
||||||
// window_get_size(WindowGetSize.class, (m) -> new WindowGetSize()),
|
|
||||||
// setWindowSize(WindowSetSize.class, (m) -> new WindowSetSize(m.get("target"))),
|
|
||||||
// window_maximize(WindowMaximize.class, (m) -> new WindowMaximize()),
|
|
||||||
// window_set_position(WindowSetPosition.class, (m) -> new WindowSetPosition(m.get("x"),m.get("y"))),
|
|
||||||
// window_get_position(WindowGetPosition.class, (m) -> new WindowGetPosition()),
|
|
||||||
//
|
|
||||||
// // Elements
|
|
||||||
// click(ClickElementBy.class, (m) -> new ClickElementBy(Bys.get(m.get("target")))),
|
|
||||||
// clearElement(ClearElement.class, (m) -> new ClearElement()),
|
|
||||||
// clearElement_by(ClearElementBy.class, (m) -> new ClearElementBy(Bys.get(m.get("by")))),
|
|
||||||
// element_find_element_by(FindElementInElementBy.class, (m) -> new FindElementInElementBy(Bys.get(m.get("by")))),
|
|
||||||
// element_find_elements_by(FindElementsInElementBy.class, (m)->new FindElementsInElementBy(Bys.get(m.get("by")))),
|
|
||||||
// element_find_elements(FindElementsInElementBy.class, (m)->new FindElementsInElementBy(Bys.get(m.get("by")))),
|
|
||||||
// element_get_attribute(GetElementAttribute.class, (m) -> new GetElementAttribute(m.get("name"))),
|
|
||||||
// element_get_css_value(GetElementCssValue.class, (m) -> new GetElementCssValue(m.get("name"))),
|
|
||||||
// element_get_location(GetElementLocation.class, (m) -> new GetElementLocation()),
|
|
||||||
// element_get_rect(GetElementRect.class, (m) ->new GetElementRect()),
|
|
||||||
// element_get_size(GetElementSize.class, (m) -> new GetElementSize()),
|
|
||||||
// element_get_tagname(GetElementTagname.class, (m) -> new GetElementTagname()),
|
|
||||||
// element_get_text(GetElementText.class, (m) -> new GetElementText()),
|
|
||||||
// is_element_displayed(IsElementDisplayed.class, (m) -> new IsElementDisplayed()),
|
|
||||||
// is_element_enabled(IsElementEnabled.class, (m) -> new IsElementEnabled()),
|
|
||||||
// is_element_selected(IsElementSelected.class, (m) -> new IsElementSelected()),
|
|
||||||
// element_send_keys(ElementSendKeys.class, (m) -> new ElementSendKeys(m.get("keys"))),
|
|
||||||
// element_submit(ElementSubmit.class, (m) -> new ElementSubmit()),
|
|
||||||
// element_get_screenshot(ElementScreenShot.class, (m) -> new ElementScreenShot()),
|
|
||||||
|
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
private final Class<? extends WebDriverVerb> verbClass;
|
|
||||||
private final Function<Map<String, String>, WebDriverVerb> initializer;
|
|
||||||
|
|
||||||
Verb(Class<? extends WebDriverVerb> verbClass, Function<Map<String, String>, WebDriverVerb> initializer) {
|
|
||||||
this.verbClass = verbClass;
|
|
||||||
this.initializer = initializer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Optional<Verb> find(String command) {
|
|
||||||
try {
|
|
||||||
return Optional.of(valueOf(command));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public WebDriverVerb resolve(Map<String, String> commandProps) {
|
|
||||||
String cmd = commandProps.get(COMMAND);
|
|
||||||
if (cmd == null) {
|
|
||||||
throw new InvalidParameterException("command properties must always contain a 'command' entry'");
|
|
||||||
}
|
|
||||||
Verb verb = valueOf(cmd);
|
|
||||||
return verb.initializer.apply(commandProps);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void execute(
|
|
||||||
long cycle,
|
|
||||||
CommandTemplate commandTemplate,
|
|
||||||
WebContext context,
|
|
||||||
boolean dryrun
|
|
||||||
) {
|
|
||||||
Map<String, String> cmdprops = commandTemplate.getCommand(cycle);
|
|
||||||
logger.debug("cycle:" + cmdprops + " command:" + cmdprops);
|
|
||||||
String command = cmdprops.get("command");
|
|
||||||
Optional<Verb> oVerb = Verb.find(command);
|
|
||||||
Verb verb = oVerb.orElseThrow(
|
|
||||||
() -> new BasicError("I don't know how to '" + command + "'")
|
|
||||||
);
|
|
||||||
WebDriverVerb resolve = verb.resolve(cmdprops);
|
|
||||||
if (dryrun) {
|
|
||||||
logger.info("skipping cycle " + cycle + " because dryrun is set to true");
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
logger.info("running cycle " + cycle + " because dryrun is set to false");
|
|
||||||
}
|
|
||||||
resolve.execute(context);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Point;
|
|
||||||
|
|
||||||
public class WindowGetPosition implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
Point position = context.driver().manage().window().getPosition();
|
|
||||||
context.setVar("window.position", position);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Dimension;
|
|
||||||
|
|
||||||
public class WindowGetSize implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
Dimension size = context.driver().manage().window().getSize();
|
|
||||||
context.setVar("window.size",size);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
|
|
||||||
public class WindowMaximize implements WebDriverVerb {
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().manage().window().maximize();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver.verbs;
|
|
||||||
|
|
||||||
import io.nosqlbench.driver.webdriver.WebContext;
|
|
||||||
import org.openqa.selenium.Point;
|
|
||||||
|
|
||||||
public class WindowSetPosition implements WebDriverVerb {
|
|
||||||
private final int x;
|
|
||||||
private final int y;
|
|
||||||
|
|
||||||
public WindowSetPosition(String x, String y) {
|
|
||||||
this.x = Integer.parseInt(x);
|
|
||||||
this.y = Integer.parseInt(y);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(WebContext context) {
|
|
||||||
context.driver().manage().window().setPosition(new Point(x, y));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
# WebDriver Driver
|
|
||||||
|
|
||||||
welcome to the experimental webdriver prototype for nosqlbench.
|
|
@ -1,61 +0,0 @@
|
|||||||
package io.nosqlbench.driver.webdriver;
|
|
||||||
|
|
||||||
import io.nosqlbench.nb.api.testutils.Perf;
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
import org.openqa.selenium.chrome.ChromeDriver;
|
|
||||||
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* References:
|
|
||||||
* <UL>
|
|
||||||
* <LI>https://www.guru99.com/selenium-with-htmlunit-driver-phantomjs.html</LI>
|
|
||||||
* <LI></LI>
|
|
||||||
* </UL>
|
|
||||||
*/
|
|
||||||
public class ExampleWebScript {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Disabled
|
|
||||||
public void getDocsSiteChromeDriver() {
|
|
||||||
System.setProperty("webdriver.http.factory", "okhttp");
|
|
||||||
WebDriver driver = new ChromeDriver();
|
|
||||||
Perf perf = new Perf("chrome");
|
|
||||||
int ops = 100;
|
|
||||||
try (Perf.Time time = perf.start("chrome",ops)) {
|
|
||||||
for (int i = 1; i <= ops; i++) {
|
|
||||||
System.out.print(".");
|
|
||||||
if ((i%10)==0) { System.out.println(i); }
|
|
||||||
driver.get("http://localhost:6081");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println("!");
|
|
||||||
|
|
||||||
System.out.println(perf);
|
|
||||||
// driver.get("http://docs.nosqlbench.io/");
|
|
||||||
driver.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Disabled
|
|
||||||
public void getDocSiteWebHtml() {
|
|
||||||
// System.setProperty("webdriver.http.factory", "okhttp");
|
|
||||||
WebDriver driver = new HtmlUnitDriver(false);
|
|
||||||
Perf perf = new Perf("htmlunit");
|
|
||||||
int ops = 100;
|
|
||||||
try (Perf.Time time = perf.start("htmlunit",ops)) {
|
|
||||||
for (int i = 1; i <= ops; i++) {
|
|
||||||
System.out.print(".");
|
|
||||||
if ((i%10)==0) { System.out.println(i); }
|
|
||||||
driver.get("http://localhost:6081");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println("!");
|
|
||||||
|
|
||||||
System.out.println(perf);
|
|
||||||
// driver.get("http://docs.nosqlbench.io/");
|
|
||||||
driver.close();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user