Search in sources :

Example 11 with SeleniumTestsContext

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

the class TestSeleniumTestContext3 method testUserDefinedParamOverridesVariableServer.

/**
 * If parameter is defined in variable server and as JVM parameter (user
 * defined), the user defined parameter must be used
 *
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testUserDefinedParamOverridesVariableServer(final ITestContext testNGCtx, final XmlTest xmlTest) throws Exception {
    Map<String, TestVariable> variables = new HashMap<>();
    variables.put("key1", new TestVariable("key1", "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);
        System.setProperty("key1", "userValue");
        ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
        initThreadContext(testNGCtx, "myTest", testResult);
        SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
        Assert.assertEquals(seleniumTestsCtx.getConfiguration().get("key1").getValue(), "userValue");
    } finally {
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
        System.clearProperty("key1");
    }
}
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 12 with SeleniumTestsContext

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

the class TestSeleniumTestContext3 method testVariablesAreGetMultipleTimesWithContextCopy.

/**
 * Check that when copying context, it's possible to allow it to retrieve
 * variables from server
 *
 * @param testNGCtx
 * @param xmlTest
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testVariablesAreGetMultipleTimesWithContextCopy(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. Context is copied with
        // permitting calls to variable server
        SeleniumTestsContext seleniumTestsCtx2 = new SeleniumTestsContext(seleniumTestsCtx);
        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");
        // 2 calls, one for each context because we allow variable retrieving when
        // copying
        verify(variableServer, times(2)).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 13 with SeleniumTestsContext

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

the class TestSeleniumTestContext method testProxyPreset.

@Test(groups = "ut context")
public void testProxyPreset(final ITestContext testNGCtx, final XmlTest xmlTest) {
    SeleniumTestsContextManager.generateApplicationPath(testNGCtx.getCurrentXmlTest().getSuite());
    SeleniumTestsContext seleniumContext = new SeleniumTestsContext();
    seleniumContext.setCaptureNetwork(false);
    seleniumContext.setConfiguration(new HashMap<>());
    seleniumContext.setTestConfiguration();
    seleniumContext.updateProxyConfig();
    Assert.assertEquals(seleniumContext.getWebProxyType(), ProxyType.DIRECT);
}
Also used : SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) Test(org.testng.annotations.Test) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest)

Example 14 with SeleniumTestsContext

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

the class TestSeleniumTestContext method testPlatformParsingForIOSWithoutVersion.

@Test(groups = { "ut context" })
public void testPlatformParsingForIOSWithoutVersion(final ITestContext testNGCtx, final XmlTest xmlTest) {
    try {
        System.setProperty("platform", "iOS");
        System.setProperty("deviceName", "");
        initThreadContext(testNGCtx);
        SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
        Assert.assertEquals(seleniumTestsCtx.getPlatform(), "iOS");
        Assert.assertEquals(seleniumTestsCtx.getMobilePlatformVersion(), null);
    } finally {
        System.clearProperty("platform");
        System.clearProperty("deviceName");
    }
}
Also used : SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) Test(org.testng.annotations.Test) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest)

Example 15 with SeleniumTestsContext

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

the class TestSeleniumTestContext method testTestLevelParam2.

/**
 * If parameter is defined in test suite and test, the test parameter must override suite parameter
 * Here, we check that it's the right test parameter which is get (same parameter defined in several tests with different
 * values
 */
@Test(groups = { "ut context" })
public void testTestLevelParam2(final ITestContext testNGCtx, final XmlTest xmlTest) {
    initThreadContext(testNGCtx);
    SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
    Assert.assertEquals(seleniumTestsCtx.getConfiguration().get("variable1").getValue(), "value1");
}
Also used : SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) Test(org.testng.annotations.Test) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest)

Aggregations

SeleniumTestsContext (com.seleniumtests.core.SeleniumTestsContext)54 Test (org.testng.annotations.Test)44 GenericTest (com.seleniumtests.GenericTest)43 XmlTest (org.testng.xml.XmlTest)32 ITestResult (org.testng.ITestResult)12 AndroidCapabilitiesFactory (com.seleniumtests.browserfactory.AndroidCapabilitiesFactory)11 DriverConfig (com.seleniumtests.driver.DriverConfig)11 MutableCapabilities (org.openqa.selenium.MutableCapabilities)11 HashMap (java.util.HashMap)9 TestVariable (com.seleniumtests.core.TestVariable)7 ConnectorsTest (com.seleniumtests.ConnectorsTest)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 TestStep (com.seleniumtests.reporter.logger.TestStep)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Set (java.util.Set)4 ITestContext (org.testng.ITestContext)4 IOException (java.io.IOException)3 Map (java.util.Map)3