Search in sources :

Example 36 with TestVariable

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)));
}
Also used : TestVariable(com.seleniumtests.core.TestVariable)

Example 37 with TestVariable

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;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) TestVariable(com.seleniumtests.core.TestVariable)

Example 38 with TestVariable

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);
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 39 with TestVariable

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");
}
Also used : HashMap(java.util.HashMap) TestVariable(com.seleniumtests.core.TestVariable) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 40 with TestVariable

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)));
}
Also used : ArrayList(java.util.ArrayList) TestVariable(com.seleniumtests.core.TestVariable) SeleniumRobotVariableServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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