Search in sources :

Example 16 with TestVariable

use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.

the class TestStringUtility method testInterpolateVariableDoesNotExist.

@Test(groups = { "ut" })
public void testInterpolateVariableDoesNotExist() {
    SeleniumTestsContextManager.getThreadContext().getConfiguration().put("url", new TestVariable("url", "http://mysite${path}"));
    SeleniumTestsContextManager.getThreadContext().getConfiguration().put("path", new TestVariable("path", "/foo/bar${param}"));
    Assert.assertEquals(StringUtility.interpolateString("connect to ${url}", SeleniumTestsContextManager.getThreadContext()), "connect to http://mysite/foo/bar${param}");
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 17 with TestVariable

use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.

the class TestStringUtility method testInterpolateStringMaskPassword1.

@Test(groups = { "ut" })
public void testInterpolateStringMaskPassword1() {
    SeleniumTestsContextManager.getThreadContext().setMaskPassword(true);
    SeleniumTestsContextManager.getThreadContext().getConfiguration().put("password", new TestVariable("password", "abc"));
    Assert.assertEquals(StringUtility.interpolateString("connect with ${password}", SeleniumTestsContextManager.getThreadContext()), "connect with ****");
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 18 with TestVariable

use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.

the class TestStringUtility method testInterpolateStringWithLoops.

/**
 * Check no looping occurs when a variable reference itself
 */
@Test(groups = { "ut" })
public void testInterpolateStringWithLoops() {
    SeleniumTestsContextManager.getThreadContext().getConfiguration().put("url", new TestVariable("url", "http://mysite${path}"));
    SeleniumTestsContextManager.getThreadContext().getConfiguration().put("path", new TestVariable("path", "/foo/bar${url}"));
    Assert.assertEquals(StringUtility.interpolateString("connect to ${url}", SeleniumTestsContextManager.getThreadContext()), "connect to http://mysite/foo/barhttp://mysite/foo/barhttp://mysite/foo/barhttp://mysite/foo/barhttp://mysite/foo/bar${url}");
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 19 with TestVariable

use of com.seleniumtests.core.TestVariable 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 20 with TestVariable

use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.

the class TestBrowserExtension method testCreateExtensionFromOptions.

/**
 * Test standard case where extension and options are defined
 */
@Test(groups = "ut")
public void testCreateExtensionFromOptions() {
    Map<String, TestVariable> options = new HashMap<>();
    options.put("extension0.path", new TestVariable("extension0.path", "/home/test/ext.crx"));
    options.put("extension0.options", new TestVariable("extension0.options", "key1=value1;key2=value2"));
    List<BrowserExtension> extensions = BrowserExtension.getExtensions(options);
    Assert.assertEquals(extensions.size(), 1);
    Assert.assertEquals(extensions.get(0).getExtensionPath(), new File("/home/test/ext.crx"));
    Assert.assertEquals(extensions.get(0).getOptions().size(), 2);
    Assert.assertEquals(extensions.get(0).getOptions().get("key1"), "value1");
    Assert.assertEquals(extensions.get(0).getOptions().get("key2"), "value2");
}
Also used : HashMap(java.util.HashMap) BrowserExtension(com.seleniumtests.browserfactory.BrowserExtension) TestVariable(com.seleniumtests.core.TestVariable) File(java.io.File) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Aggregations

TestVariable (com.seleniumtests.core.TestVariable)72 Test (org.testng.annotations.Test)66 GenericTest (com.seleniumtests.GenericTest)53 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)38 XmlTest (org.testng.xml.XmlTest)34 ConnectorsTest (com.seleniumtests.ConnectorsTest)19 MockitoTest (com.seleniumtests.MockitoTest)19 ITestResult (org.testng.ITestResult)14 HashMap (java.util.HashMap)13 SeleniumRobotVariableServerConnector (com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 SeleniumTestsContext (com.seleniumtests.core.SeleniumTestsContext)7 File (java.io.File)3 ArrayList (java.util.ArrayList)3 JSONObject (kong.unirest.json.JSONObject)3 BrowserExtension (com.seleniumtests.browserfactory.BrowserExtension)2 ConfigReader (com.seleniumtests.core.config.ConfigReader)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 IOException (java.io.IOException)2 HttpRequest (kong.unirest.HttpRequest)2