Search in sources :

Example 21 with ScenarioException

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);
    }
}
Also used : WebElement(org.openqa.selenium.WebElement) HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) GenericPictureElement(com.seleniumtests.uipage.htmlelements.GenericPictureElement) RadioButtonElement(com.seleniumtests.uipage.htmlelements.RadioButtonElement) Element(com.seleniumtests.uipage.htmlelements.Element) CheckBoxElement(com.seleniumtests.uipage.htmlelements.CheckBoxElement) LinkElement(com.seleniumtests.uipage.htmlelements.LinkElement) InvocationTargetException(java.lang.reflect.InvocationTargetException) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 22 with ScenarioException

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);
    }
}
Also used : Matcher(java.util.regex.Matcher) WebElement(org.openqa.selenium.WebElement) ScenarioException(com.seleniumtests.customexception.ScenarioException) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Example 23 with ScenarioException

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);
        }
    }
}
Also used : Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) HashMap(java.util.HashMap) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) Transition(com.atlassian.jira.rest.client.api.domain.Transition) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 24 with ScenarioException

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);
}
Also used : IOException(java.io.IOException) File(java.io.File) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 25 with ScenarioException

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 "";
    }
}
Also used : UnirestInstance(kong.unirest.UnirestInstance) HttpRequestWithBody(kong.unirest.HttpRequestWithBody) UnirestException(kong.unirest.UnirestException) ScenarioException(com.seleniumtests.customexception.ScenarioException) Point(java.awt.Point)

Aggregations

ScenarioException (com.seleniumtests.customexception.ScenarioException)68 ArrayList (java.util.ArrayList)17 WebElement (org.openqa.selenium.WebElement)14 UnirestException (kong.unirest.UnirestException)13 GenericPictureElement (com.seleniumtests.uipage.htmlelements.GenericPictureElement)12 IOException (java.io.IOException)12 JSONObject (kong.unirest.json.JSONObject)12 CheckBoxElement (com.seleniumtests.uipage.htmlelements.CheckBoxElement)11 Element (com.seleniumtests.uipage.htmlelements.Element)11 HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)11 LinkElement (com.seleniumtests.uipage.htmlelements.LinkElement)11 RadioButtonElement (com.seleniumtests.uipage.htmlelements.RadioButtonElement)11 File (java.io.File)10 List (java.util.List)9 HashMap (java.util.HashMap)8 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)7 AWTException (java.awt.AWTException)7 Robot (java.awt.Robot)6 Map (java.util.Map)5 TestStep (com.seleniumtests.reporter.logger.TestStep)4