
com.infotel.seleniumrobot.grid.tasks.CommandTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of seleniumRobot-grid4 Show documentation
Show all versions of seleniumRobot-grid4 Show documentation
Selenium grid extension for mobile testing
The newest version!
package com.infotel.seleniumrobot.grid.tasks;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.infotel.seleniumrobot.grid.config.LaunchConfig;
import com.infotel.seleniumrobot.grid.exceptions.TaskException;
import com.seleniumtests.util.osutility.OSCommand;
public class CommandTask implements Task {
private static final Logger logger = LogManager.getLogger(CommandTask.class);
private static final int DEFAULT_TIMEOUT = 30;
private String command = "";
private String result = "";
private int timeout = 30;
private List args = new ArrayList();
public static CommandTask getInstance() {
return new CommandTask();
}
public void setCommand(String command, List args) {
setCommand(command, args, null);
}
public void setCommand(String command, List args, Integer timeout) {
this.command = command;
this.args = args;
if (timeout == null) {
this.timeout = DEFAULT_TIMEOUT;
} else {
this.timeout = timeout;
}
}
@SuppressWarnings("unchecked")
@Override
public CommandTask execute() {
result = "";
if (command == null || command.isEmpty()) {
throw new TaskException("No command provided");
}
String realCommand = command.replace(OSCommand.USE_PATH, "");
if (LaunchConfig.getCurrentLaunchConfig().getExternalProgramWhiteList().contains(realCommand)) {
logger.error(String.format("Executing command %s", realCommand));
args.add(0, command);
result = OSCommand.executeCommandAndWait(args.toArray(new String[] {}), timeout, null);
} else {
throw new TaskException(String.format("Command %s is not supported", command));
}
return this;
}
public String getResult() {
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy