use of com.seleniumtests.customexception.SeleniumRobotServerException in project seleniumRobot by bhecquet.
the class SeleniumRobotServerConnector method createApplication.
public void createApplication() {
if (!active) {
return;
}
try {
JSONObject applicationJson = getJSonResponse(buildPostRequest(url + APPLICATION_API_URL).field(FIELD_NAME, SeleniumTestsContextManager.getApplicationName()));
applicationId = applicationJson.getInt("id");
} catch (UnirestException | JSONException | SeleniumRobotServerException e) {
throw new SeleniumRobotServerException("cannot create application", e);
}
}
use of com.seleniumtests.customexception.SeleniumRobotServerException in project seleniumRobot by bhecquet.
the class SeleniumRobotServerConnector method createEnvironment.
public void createEnvironment() {
if (!active) {
return;
}
try {
JSONObject envJson = getJSonResponse(buildPostRequest(url + ENVIRONMENT_API_URL).field(FIELD_NAME, SeleniumTestsContextManager.getGlobalContext().getTestEnv()));
environmentId = envJson.getInt("id");
} catch (UnirestException | JSONException | SeleniumRobotServerException e) {
throw new SeleniumRobotServerException("cannot create environment", e);
}
}
use of com.seleniumtests.customexception.SeleniumRobotServerException in project seleniumRobot by bhecquet.
the class SeleniumRobotSnapshotServerConnector method addCurrentTestStepToTestCase.
/**
* Add the current test case (should have been previously created) to this test session
*/
public void addCurrentTestStepToTestCase(Integer testStepId, Integer testCaseInSessionId) {
if (testStepId == null || testCaseInSessionId == null) {
throw new ConfigurationException("Test step and Test case in session must be previously created");
}
try {
// get list of tests associated to this session
List<String> testSteps = getStepListFromTestCase(testCaseInSessionId);
if (!testSteps.contains(testStepId.toString())) {
testSteps.add(testStepId.toString());
}
addTestStepsToTestCases(testSteps, testCaseInSessionId);
} catch (UnirestException | JSONException | SeleniumRobotServerException e) {
throw new SeleniumRobotServerException("cannot add test step to test case", e);
}
}
use of com.seleniumtests.customexception.SeleniumRobotServerException in project seleniumRobot by bhecquet.
the class SeleniumRobotSnapshotServerConnector method getReferenceSnapshot.
/**
* Get reference snapshot from server
* This is useful when a step fails and we want to get the reference to allow comparison
*/
public File getReferenceSnapshot(Integer stepResultId) {
if (!active) {
return null;
}
checkStepResult(stepResultId);
try {
File tmpFile = File.createTempFile("img", ".png");
HttpResponse<byte[]> response = buildGetRequest(url + STEP_REFERENCE_API_URL + stepResultId + "/").asBytes();
if (response.getStatus() == 200) {
Files.write(response.getBody(), tmpFile);
return tmpFile;
} else {
logger.warn("No reference found");
return null;
}
} catch (UnirestException | SeleniumRobotServerException | IOException e) {
throw new SeleniumRobotServerException("cannot get reference snapshot", e);
}
}
use of com.seleniumtests.customexception.SeleniumRobotServerException in project seleniumRobot by bhecquet.
the class SeleniumRobotSnapshotServerConnector method createSnapshot.
/**
* Create snapshot on server that will be used to show differences between 2 versions of the application
*/
public Integer createSnapshot(Snapshot snapshot, Integer sessionId, Integer testCaseInSessionId, Integer stepResultId) {
if (!active) {
return null;
}
if (sessionId == null) {
throw new ConfigurationException("Session must be previously recorded");
}
if (testCaseInSessionId == null) {
throw new ConfigurationException("TestCaseInSession must be previously recorded");
}
checkStepResult(stepResultId);
if (snapshot == null || snapshot.getScreenshot() == null || snapshot.getScreenshot().getFullImagePath() == null) {
throw new SeleniumRobotServerException("Provided snapshot does not exist");
}
String snapshotName = snapshot.getName().length() > MAX_SNAPSHOT_NAME_LENGHT ? snapshot.getName().substring(0, MAX_SNAPSHOT_NAME_LENGHT) : snapshot.getName();
try {
File pictureFile = new File(snapshot.getScreenshot().getFullImagePath());
JSONObject snapshotJson = getJSonResponse(buildPostRequest(url + SNAPSHOT_API_URL).field("stepResult", stepResultId).field("sessionId", sessionUUID).field(FIELD_TEST_CASE, testCaseInSessionId.toString()).field(FIELD_IMAGE, pictureFile).field(FIELD_NAME, snapshotName).field("compare", snapshot.getCheckSnapshot().getName()).field("diffTolerance", String.valueOf(snapshot.getCheckSnapshot().getErrorThreshold())));
return snapshotJson.getInt("id");
} catch (UnirestException | JSONException | SeleniumRobotServerException e) {
throw new SeleniumRobotServerException("cannot create test snapshot", e);
}
}
Aggregations