use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestNGResultUtils method setTestDescription.
/**
* Set description interpolating variables
* @param testNGResult
*/
public static void setTestDescription(ITestResult testNGResult) {
int i = 0;
for (Object parameter : testNGResult.getParameters()) {
String key = String.format("arg%d", i++);
getSeleniumRobotTestContext(testNGResult).getConfiguration().put(key, new TestVariable(key, parameter.toString()));
}
testNGResult.setAttribute(DESCRIPTION, StringUtility.interpolateString(testNGResult.getMethod().getDescription(), getSeleniumRobotTestContext(testNGResult)));
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class StringUtility method interpolateString.
/**
* Do interpolation like groovy language, using context variables
* ex: provided the 'url' variable is present in test configuration with value 'http://my.site',
* 'connect to ${url}' => 'connect to http://my.site
*
* @param initialString the string to interpolate
* @return
*/
public static String interpolateString(String initialString, SeleniumTestsContext testContext, Boolean maskPassword) {
if (initialString == null) {
return null;
}
String interpolatedString = initialString;
if (testContext == null || testContext.getConfiguration() == null) {
return initialString;
}
Map<String, TestVariable> variables = testContext.getConfiguration();
List<String> unknownKeys = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Matcher matcher = PLACEHOLDER_PATTERN.matcher(interpolatedString);
boolean processed = false;
while (matcher.find()) {
processed = true;
String key = matcher.group(1);
if (Boolean.TRUE.equals(maskPassword) && (key.toLowerCase().contains("password") || key.toLowerCase().contains("pwd") || key.toLowerCase().contains("passwd"))) {
interpolatedString = interpolatedString.replace(String.format("${%s}", key), "****");
} else if (variables.containsKey(key)) {
interpolatedString = interpolatedString.replace(String.format("${%s}", key), variables.get(key).getValueNoInterpolation());
} else if (!unknownKeys.contains(key)) {
unknownKeys.add(key);
logger.warn(String.format("Error while interpolating '%s', key '%s' not found in configuration", interpolatedString, key));
}
}
if (!processed) {
break;
}
}
return interpolatedString;
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestSeleniumRobotVariableServerConnector method testUpsert.
@Test(groups = { "it" }, enabled = true)
public void testUpsert() {
TestVariable variable = new TestVariable("key.test", "value");
variable.setReservable(true);
// variable.setTimeToLive(3);
// TestVariable variable = new TestVariable(16, "key.test", "value", false, "custom.test.variable.key.test");
variable = connector.upsertVariable(variable, false);
// variable.setValue("newValue");
// variable = connector.upsertVariable(variable);
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestSeleniumRobotVariableServerConnector method testRawVariablesConversion.
@Test(groups = { "ut" })
public void testRawVariablesConversion() {
Map<String, TestVariable> rawVariables = new HashMap<>();
rawVariables.put("key1", new TestVariable(1, "key1", "value1", false, "key1"));
rawVariables.put("key2", new TestVariable(1, "key2", "value2", false, "key2"));
Map<String, String> variables = SeleniumRobotVariableServerConnector.convertRawTestVariableMapToKeyValuePairs(rawVariables);
Assert.assertEquals(variables.get("key1"), "value1");
Assert.assertEquals(variables.get("key2"), "value2");
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestSeleniumRobotVariableServerConnector method testVariableDereservation.
@Test(groups = { "ut" })
public void testVariableDereservation() throws UnirestException {
configureMockedVariableServerConnection();
SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(true, SERVER_URL, "Test1", null);
List<TestVariable> variables = new ArrayList<>(connector.getVariables().values());
connector.unreserveVariables(variables);
// only one dereservation should be called
PowerMockito.verifyStatic(Unirest.class);
Unirest.patch(ArgumentMatchers.contains(String.format(SeleniumRobotVariableServerConnector.EXISTING_VARIABLE_API_URL, 2)));
}
Aggregations