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