Search in sources :

Example 6 with SeleniumRobotServerException

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

the class SeleniumRobotSnapshotServerConnector method createStepReferenceSnapshot.

/**
 * Create snapshot that shows the status of a step
 */
public void createStepReferenceSnapshot(Snapshot snapshot, Integer stepResultId) {
    if (!active) {
        return;
    }
    checkStepResult(stepResultId);
    if (snapshot == null || snapshot.getScreenshot() == null || snapshot.getScreenshot().getFullImagePath() == null) {
        throw new SeleniumRobotServerException("Provided snapshot does not exist");
    }
    try {
        File pictureFile = new File(snapshot.getScreenshot().getFullImagePath());
        getJSonResponse(buildPostRequest(url + STEP_REFERENCE_API_URL).field("stepResult", stepResultId).field(FIELD_IMAGE, pictureFile));
    } catch (UnirestException | JSONException | SeleniumRobotServerException e) {
        throw new SeleniumRobotServerException("cannot create step reference snapshot", e);
    }
}
Also used : UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) File(java.io.File) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 7 with SeleniumRobotServerException

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

the class SeleniumRobotSnapshotServerConnector method createTestStep.

/**
 * Create test step and add it to the current test case
 * @param testStep				name of the test step
 * @param testCaseInSessionId	id of the test case in session, so that we can add this step to the test case
 * @return	id of the created teststep
 */
public Integer createTestStep(String testStep, Integer testCaseInSessionId) {
    if (!active) {
        return null;
    }
    String strippedName = getTestStepName(testStep);
    try {
        JSONObject stepJson = getJSonResponse(buildPostRequest(url + TESTSTEP_API_URL).field(FIELD_NAME, strippedName));
        Integer testStepId = stepJson.getInt("id");
        addCurrentTestStepToTestCase(testStepId, testCaseInSessionId);
        return testStepId;
    } catch (UnirestException | JSONException | SeleniumRobotServerException e) {
        throw new SeleniumRobotServerException("cannot create test step", e);
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 8 with SeleniumRobotServerException

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

the class SeleniumRobotSnapshotServerConnector method createSession.

/**
 * Create a test session
 * @return
 */
public Integer createSession(String sessionName) {
    if (!active) {
        return null;
    }
    if (applicationId == null) {
        throw new SeleniumRobotServerException(String.format("Application %s has not been created", SeleniumTestsContextManager.getApplicationName()));
    }
    if (environmentId == null) {
        throw new SeleniumRobotServerException(String.format("Environment %s has not been created", SeleniumTestsContextManager.getGlobalContext().getTestEnv()));
    }
    if (versionId == null) {
        createVersion();
    }
    String strippedSessionName = sessionName.length() > MAX_TESTSESSION_NAME_LENGHT ? sessionName.substring(0, MAX_TESTSESSION_NAME_LENGHT) : sessionName;
    try {
        BrowserType browser = SeleniumTestsContextManager.getGlobalContext().getBrowser();
        browser = browser == null ? BrowserType.NONE : browser;
        // for uniqueness of the session
        sessionUUID = UUID.randomUUID().toString();
        JSONObject sessionJson = getJSonResponse(buildPostRequest(url + SESSION_API_URL).field("sessionId", sessionUUID).field("date", LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)).field("browser", browser.getBrowserType()).field("environment", SeleniumTestsContextManager.getGlobalContext().getTestEnv()).field("version", versionId.toString()).field(FIELD_NAME, strippedSessionName).field("compareSnapshot", String.valueOf(SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshot())).field("ttl", // format is 'x days' as this is the way Django expect a duration in days
        String.format("%d days", SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshotTtl())));
        return sessionJson.getInt("id");
    } catch (UnirestException | JSONException | SeleniumRobotServerException e) {
        throw new SeleniumRobotServerException("cannot create session", e);
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) BrowserType(com.seleniumtests.driver.BrowserType) UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 9 with SeleniumRobotServerException

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

the class SeleniumRobotVariableServerConnector method getVariables.

/**
 * Retrieve all variables from the server
 * Display a warning when a custom variable prefix "custom.test.variable." overwrites or is overwritten by a regular one
 *
 * @param variablesOlderThanDays 	number of days since this variable should be created before it can be returned. This only applies to variables which have a time to live (a.k.a: where destroyAfterDays parameter is > 0)
 * @param name						name of the variables to retrieve. If given, only one variable will be get because server only returns one variable for each name
 * @param value						value of the variables to retrieve
 * @param reserve					if true, reserve the reservable variables, else, only return searched variables
 * @return
 */
public Map<String, TestVariable> getVariables(Integer variablesOlderThanDays, String name, String value, boolean reserve) {
    if (!active) {
        throw new SeleniumRobotServerException("Server is not active");
    }
    try {
        List<String> varNames = new ArrayList<>();
        GetRequest request = buildGetRequest(url + VARIABLE_API_URL).queryString(FIELD_VERSION, versionId).queryString(FIELD_ENVIRONMENT, environmentId).queryString(FIELD_TEST, testCaseId).queryString(FIELD_OLDER_THAN, variablesOlderThanDays).queryString("reserve", reserve).queryString("format", "json");
        if (name != null) {
            request = request.queryString(FIELD_NAME, name);
        }
        if (value != null) {
            request = request.queryString(FIELD_VALUE, value);
        }
        JSONArray variablesJson = getJSonArray(request);
        Map<String, TestVariable> variables = new HashMap<>();
        for (int i = 0; i < variablesJson.length(); i++) {
            TestVariable variable = TestVariable.fromJsonObject(variablesJson.getJSONObject(i));
            if (varNames.contains(variable.getName())) {
                logger.warn(String.format("variable %s has already been get. Check no custom (added by test script) variable has the same name as a regular one", variable.getName()));
            } else {
                variables.put(variable.getName(), variable);
                varNames.add(variable.getName());
            }
        }
        return variables;
    } catch (UnirestException | JSONException | SeleniumRobotServerException e) {
        throw new SeleniumRobotServerException("cannot get variables", e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(kong.unirest.json.JSONArray) UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) TestVariable(com.seleniumtests.core.TestVariable) GetRequest(kong.unirest.GetRequest) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 10 with SeleniumRobotServerException

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

the class SeleniumRobotElementInfoServerConnector method getElementInfos.

/**
 * Retrieve all element information from the server
 * @return
 */
public List<ElementInfo> getElementInfos() {
    if (!active) {
        throw new SeleniumRobotServerException("Server is not active");
    }
    try {
        GetRequest request = buildGetRequest(url + LIST_ELEMENT_INFO_API_URL).queryString("application", applicationId).queryString("version", versionId).queryString("format", "json");
        JSONArray eiJson = getJSonArray(request);
        List<ElementInfo> elementInfos = new ArrayList<>();
        for (int i = 0; i < eiJson.length(); i++) {
            ElementInfo ei = ElementInfo.readFromJson(eiJson.getJSONObject(i).toString());
            elementInfos.add(ei);
        }
        return elementInfos;
    } catch (UnirestException | JSONException e) {
        throw new SeleniumRobotServerException("cannot get element infos", e);
    }
}
Also used : ElementInfo(com.seleniumtests.uipage.htmlelements.ElementInfo) GetRequest(kong.unirest.GetRequest) JSONArray(kong.unirest.json.JSONArray) ArrayList(java.util.ArrayList) UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) 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