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);
}
}
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);
}
}
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);
}
}
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);
}
}
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;
}
Aggregations