use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class PageObject method clickAndChangeToPage.
/**
* Click on element and creates a new PageObject of the type of following page
* @param fieldName
* @param nextPage Class of the next page
* @return
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws InstantiationException
*/
@GenericStep
public <T extends PageObject> T clickAndChangeToPage(String fieldName, Class<T> nextPage) {
Element element = getElement(fieldName);
element.click();
try {
return nextPage.getConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new ScenarioException(String.format("Cannot switch to next page %s, maybe default constructor does not exist", nextPage.getSimpleName()), e);
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class Table method getRowFromContent.
/**
* issue #306
* Returns the row from table, searching for its content by pattern. Then you can search for a specific cell using 'getRowCells(row);'
*
* Tip: returned element is a HtmlElement, but you must cast it to use its specific methods
*
* @param content pattern to search for
* @param column column where pattern should be searched
* @return
*/
@ReplayOnError
public WebElement getRowFromContent(final Pattern content, final int column) {
findTableElement();
if (rows != null && !rows.isEmpty()) {
for (WebElement row : rows) {
List<WebElement> cols = getRowCells(row);
if (cols.isEmpty()) {
throw new ScenarioException("There are no columns in this row");
}
WebElement cell = cols.get(column);
Matcher matcher = content.matcher(cell.getText());
if (matcher.matches()) {
return row;
}
}
throw new ScenarioException(String.format("Pattern %s has not been found in table", content.pattern()));
} else {
throw new ScenarioException(ERROR_NO_ROWS);
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class JiraConnector method closeIssue.
/**
* Close issue, applying all necessary transitions
* @param issueId ID of the issue
* @param closingMessage Message of closing
*/
public void closeIssue(String issueId, String closingMessage) {
logger.info(String.format("closing issue %s", issueId));
IssueRestClient issueClient = restClient.getIssueClient();
Issue issue;
try {
issue = issueClient.getIssue(issueId).claim();
} catch (RestClientException e) {
throw new ScenarioException(String.format("Jira issue %s does not exist, cannot close it", issueId));
}
Map<String, Transition> transitions = new HashMap<>();
issueClient.getTransitions(issue).claim().forEach(transition -> transitions.put(transition.getName(), transition));
List<String> closeWorkflow = Arrays.asList(closeTransition.split("/"));
int workflowPosition = -1;
for (String transitionName : transitions.keySet()) {
workflowPosition = closeWorkflow.indexOf(transitionName);
if (workflowPosition != -1) {
break;
}
}
if (workflowPosition == -1) {
throw new ConfigurationException(String.format("'bugtracker.jira.closeTransition' values [%s] are unknown for this issue, allowed transitions are %s", closeTransition, transitions.keySet()));
} else {
for (String transitionName : closeWorkflow.subList(workflowPosition, closeWorkflow.size())) {
transitionIssue(issueClient, issue, transitions, transitionName);
}
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class SoapUi method executeWithProjectString.
/**
* Start SOAP UI with a project file as string. Useful when project file is stored in test resource and we only access the stream
* @param projectString project string
* @param projectName project name
* @return
*/
public String executeWithProjectString(String projectString, String projectName) {
File tmpFile;
try {
tmpFile = File.createTempFile("project-" + projectName, ".xml");
tmpFile.deleteOnExit();
FileUtils.writeStringToFile(tmpFile, projectString);
} catch (IOException e) {
throw new ScenarioException("Cannot write project file", e);
}
return executeWithProjectFile(tmpFile);
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class SeleniumRobotGridConnector method executeCommand.
/**
* Execute command with timeout
* @param program name of the program
* @param timeout if null, default timeout will be applied
* @param args arguments of the program
*/
@Override
public String executeCommand(String program, Integer timeout, String... args) {
if (nodeUrl == null) {
throw new ScenarioException("You cannot execute a remote process before driver has been created and corresponding node instanciated");
}
logger.info("execute program: " + program);
try (UnirestInstance unirest = Unirest.spawnInstance()) {
HttpRequestWithBody req = unirest.post(String.format("%s%s", nodeUrl, NODE_TASK_SERVLET)).queryString(ACTION_FIELD, "command").queryString(NAME_FIELD, program).queryString(SESSION_FIELD, getSessionId().toString());
int i = 0;
for (String arg : args) {
req = req.queryString("arg" + i, arg);
i++;
}
if (timeout != null) {
unirest.config().socketTimeout((timeout + 5) * 1000);
req = req.queryString("timeout", timeout);
}
HttpResponse<String> response = req.asString();
return response.getBody();
} catch (UnirestException e) {
logger.warn(String.format("Could not execute process %s: %s", program, e.getMessage()));
return "";
}
}
Aggregations