Search in sources :

Example 11 with SeleniumRobotServerException

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);
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 12 with SeleniumRobotServerException

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);
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 13 with SeleniumRobotServerException

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);
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 14 with SeleniumRobotServerException

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

Example 15 with SeleniumRobotServerException

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);
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) File(java.io.File) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Aggregations

SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)19 UnirestException (kong.unirest.UnirestException)14 JSONException (kong.unirest.json.JSONException)11 JSONObject (kong.unirest.json.JSONObject)9 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)7 File (java.io.File)7 ArrayList (java.util.ArrayList)4 TestStep (com.seleniumtests.reporter.logger.TestStep)3 SeleniumRobotSnapshotServerConnector (com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector)2 BrowserType (com.seleniumtests.driver.BrowserType)2 Snapshot (com.seleniumtests.reporter.logger.Snapshot)2 IOException (java.io.IOException)2 GetRequest (kong.unirest.GetRequest)2 JSONArray (kong.unirest.json.JSONArray)2 GenericTest (com.seleniumtests.GenericTest)1 MockitoTest (com.seleniumtests.MockitoTest)1 SnapshotComparisonResult (com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult)1 TestVariable (com.seleniumtests.core.TestVariable)1 ErrorCause (com.seleniumtests.core.testanalysis.ErrorCause)1 ErrorCauseFinder (com.seleniumtests.core.testanalysis.ErrorCauseFinder)1