Search in sources :

Example 61 with TestVariable

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

the class TestSeleniumTestContext3 method testVariablesAreGetOnlyOnce.

/**
 * Check that if we request variable configuration several times, seleniumRobot
 * server is called only once to avoid problems with variable reservation
 *
 * @param testNGCtx
 * @param xmlTest
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testVariablesAreGetOnlyOnce(final ITestContext testNGCtx, final XmlTest xmlTest) throws Exception {
    Map<String, TestVariable> variables = new HashMap<>();
    variables.put("key", new TestVariable("key", "val1"));
    try {
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:1234");
        PowerMockito.whenNew(SeleniumRobotVariableServerConnector.class).withArguments(eq(true), eq("http://localhost:1234"), anyString(), eq(null)).thenReturn(variableServer);
        when(variableServer.isAlive()).thenReturn(true);
        when(variableServer.getVariables(0)).thenReturn(variables);
        ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
        initThreadContext(testNGCtx, "myTest", testResult);
        SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
        // do a second parameter retrieving
        seleniumTestsCtx.setTestConfiguration();
        Assert.assertEquals(seleniumTestsCtx.getConfiguration().get("key").getValue(), "val1");
        verify(variableServer).getVariables(0);
    } finally {
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
    }
}
Also used : SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) ITestResult(org.testng.ITestResult) 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) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest)

Example 62 with TestVariable

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

the class TestSeleniumTestContext3 method testVariablesAreGetOnlyOnceWithContextCopy.

/**
 * Check that when copying context, it's possible to prevent it to retrieve
 * variables from server
 *
 * @param testNGCtx
 * @param xmlTest
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testVariablesAreGetOnlyOnceWithContextCopy(final ITestContext testNGCtx, final XmlTest xmlTest) throws Exception {
    Map<String, TestVariable> variables = new HashMap<>();
    variables.put("key", new TestVariable("key", "val1"));
    try {
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:1234");
        PowerMockito.whenNew(SeleniumRobotVariableServerConnector.class).withArguments(eq(true), eq("http://localhost:1234"), anyString(), eq(null)).thenReturn(variableServer);
        when(variableServer.isAlive()).thenReturn(true);
        when(variableServer.getVariables(0)).thenReturn(variables);
        ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
        initThreadContext(testNGCtx, "myTest", testResult);
        SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
        // do a parameter retrieving for copied context
        SeleniumTestsContext seleniumTestsCtx2 = new SeleniumTestsContext(seleniumTestsCtx, false);
        seleniumTestsCtx2.configureContext(testResult);
        // check that variables are kept even if variable server has not been re-called
        Assert.assertEquals(seleniumTestsCtx2.getConfiguration().get("key").getValue(), "val1");
        // only one call, done by first context init, further retrieving is forbidden
        verify(variableServer).getVariables(0);
    } finally {
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
    }
}
Also used : SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) ITestResult(org.testng.ITestResult) 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) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest)

Example 63 with TestVariable

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

the class TestSeleniumTestContext method testBugtrackerPasswordFromVariable.

@Test(groups = "ut context")
public void testBugtrackerPasswordFromVariable(final ITestContext testNGCtx, final XmlTest xmlTest) {
    initThreadContext(testNGCtx);
    SeleniumTestsContextManager.getThreadContext().getConfiguration().put("bugtrackerPassword", new TestVariable("bugtrackerPassword", "pwd"));
    Assert.assertEquals(SeleniumTestsContextManager.getThreadContext().getBugtrackerPassword(), "pwd");
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest)

Example 64 with TestVariable

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

the class TestSeleniumTestContext method testBugtrackerProjectFromVariable.

@Test(groups = "ut context")
public void testBugtrackerProjectFromVariable(final ITestContext testNGCtx, final XmlTest xmlTest) {
    initThreadContext(testNGCtx);
    SeleniumTestsContextManager.getThreadContext().getConfiguration().put("bugtrackerProject", new TestVariable("bugtrackerProject", "project"));
    Assert.assertEquals(SeleniumTestsContextManager.getThreadContext().getBugtrackerProject(), "project");
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest)

Example 65 with TestVariable

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

the class TestSeleniumTestContext method testBugtrackerUserFromVariable.

@Test(groups = "ut context")
public void testBugtrackerUserFromVariable(final ITestContext testNGCtx, final XmlTest xmlTest) {
    initThreadContext(testNGCtx);
    SeleniumTestsContextManager.getThreadContext().getConfiguration().put("bugtrackerUser", new TestVariable("bugtrackerUser", "user"));
    Assert.assertEquals(SeleniumTestsContextManager.getThreadContext().getBugtrackerUser(), "user");
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) XmlTest(org.testng.xml.XmlTest) 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