Search in sources :

Example 46 with ScenarioException

use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.

the class CampaignFolder method getAll.

public static List<CampaignFolder> getAll() {
    try {
        JSONObject json = getPagedJSonResponse(buildGetRequest(apiRootUrl + CAMPAIGN_FOLDER_URL));
        List<CampaignFolder> campaignFolders = new ArrayList<>();
        if (json.has("_embedded")) {
            for (JSONObject folderJson : (List<JSONObject>) json.getJSONObject(FIELD_EMBEDDED).getJSONArray(FIELD_CAMPAIGN_FOLDERS).toList()) {
                campaignFolders.add(CampaignFolder.fromJson(folderJson));
            }
        }
        return campaignFolders;
    } catch (UnirestException e) {
        throw new ScenarioException("Cannot get all campaign folders", e);
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) ArrayList(java.util.ArrayList) UnirestException(kong.unirest.UnirestException) List(java.util.List) ArrayList(java.util.ArrayList) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 47 with ScenarioException

use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.

the class IterationTestPlanItem method create.

public static IterationTestPlanItem create(Iteration iteration, TestCase testCase) {
    try {
        JSONObject body = new JSONObject();
        body.put(FIELD_TYPE, "iteration-test-plan-item");
        JSONObject testCaseJson = new JSONObject();
        testCaseJson.put(FIELD_ID, testCase.id);
        testCaseJson.put(FIELD_TYPE, "test-case");
        body.put("test_case", testCaseJson);
        JSONObject json = getJSonResponse(buildPostRequest(apiRootUrl + String.format(TEST_PLAN_ITEM_URL, iteration.id)).body(body));
        return IterationTestPlanItem.fromJson(json);
    } catch (UnirestException e) {
        throw new ScenarioException(String.format("Cannot create Iteration test plan for iteration %s and test case %d", iteration.name, testCase.id), e);
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) UnirestException(kong.unirest.UnirestException) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 48 with ScenarioException

use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.

the class Project method getAll.

/**
 * Returns the list of projects accessible to this user
 * @return
 */
public static List<Project> getAll() {
    try {
        JSONObject json = getPagedJSonResponse(buildGetRequest(apiRootUrl + PROJECTS_URL));
        List<Project> projects = new ArrayList<>();
        if (json.has(FIELD_EMBEDDED)) {
            for (JSONObject projectJson : (List<JSONObject>) json.getJSONObject(FIELD_EMBEDDED).getJSONArray(FIELD_PROJECTS).toList()) {
                projects.add(Project.fromJson(projectJson));
            }
        }
        return projects;
    } catch (UnirestException e) {
        throw new ScenarioException("Cannot get all projects", e);
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) ArrayList(java.util.ArrayList) UnirestException(kong.unirest.UnirestException) List(java.util.List) ArrayList(java.util.ArrayList) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 49 with ScenarioException

use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.

the class ReporterControler method changeTestResultWithSnapshotComparison.

/**
 * @param suiteResult
 * @param testResult
 * @param snapshotComparisonResult
 */
private void changeTestResultWithSnapshotComparison(ISuiteResult suiteResult, ITestResult testResult, int snapshotComparisonResult) {
    // based on snapshot comparison flag, change test result only if comparison is KO
    if (SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshotBehaviour() == SnapshotComparisonBehaviour.CHANGE_TEST_RESULT && snapshotComparisonResult == ITestResult.FAILURE) {
        testResult.setStatus(ITestResult.FAILURE);
        testResult.setThrowable(new ScenarioException("Snapshot comparison failed"));
    } else if (SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshotBehaviour() == SnapshotComparisonBehaviour.ADD_TEST_RESULT) {
        ITestResult newTestResult;
        try {
            newTestResult = TestNGResultUtils.copy(testResult, "snapshots-" + testResult.getName(), TestNGResultUtils.getTestDescription(testResult) + " FOR SNAPSHOT COMPARISON");
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
            throw new ScenarioException(e.getMessage(), e);
        }
        // add the test result
        newTestResult.setStatus(snapshotComparisonResult);
        if (snapshotComparisonResult == ITestResult.SUCCESS) {
            suiteResult.getTestContext().getPassedTests().addResult(newTestResult, newTestResult.getMethod());
        } else if (snapshotComparisonResult == ITestResult.FAILURE) {
            newTestResult.setThrowable(new ScenarioException("Snapshot comparison failed"));
            suiteResult.getTestContext().getFailedTests().addResult(newTestResult, newTestResult.getMethod());
        } else if (snapshotComparisonResult == ITestResult.SKIP) {
            suiteResult.getTestContext().getSkippedTests().addResult(newTestResult, newTestResult.getMethod());
        }
        // add a snapshot comparison result for the newly created test result (which correspond to snapshot comparison)
        TestNGResultUtils.setSnapshotComparisonResult(newTestResult, snapshotComparisonResult);
    }
}
Also used : ITestResult(org.testng.ITestResult) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 50 with ScenarioException

use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.

the class PageObject method assertForMatchingValue.

@GenericStep
public <T extends PageObject> T assertForMatchingValue(String fieldName, String regex) {
    Element element = getElement(fieldName);
    if (element instanceof HtmlElement) {
        Assert.assertTrue(((HtmlElement) element).isElementPresent(0), String.format(ERROR_ELEMENT_NOT_PRESENT, fieldName));
        Assert.assertTrue(Pattern.compile(regex).matcher(((HtmlElement) element).getText()).find() || Pattern.compile(regex).matcher(((HtmlElement) element).getValue()).find(), String.format("Value of Element %s does not match %s ", fieldName, regex));
    } else {
        throw new ScenarioException(String.format(ELEMENT_S_IS_NOT_AN_HTML_ELEMENT_SUBCLASS, fieldName));
    }
    return (T) this;
}
Also used : HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) 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) ScenarioException(com.seleniumtests.customexception.ScenarioException)

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