Search in sources :

Example 31 with SeleniumGridConnector

use of com.seleniumtests.connectors.selenium.SeleniumGridConnector in project seleniumRobot by bhecquet.

the class TestSeleniumTestContext3 method testGridConnection.

/**
 * Test that a grid connection is created when all parameters are correct
 *
 * @param testNGCtx
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 * @throws NoSuchFieldException
 * @throws SecurityException
 * @throws NoSuchMethodException
 */
@Test(groups = "ut")
public void testGridConnection(final ITestContext testNGCtx) throws NoSuchMethodException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    SeleniumGridConnector gridConnector = spy(new SeleniumGridConnector("http://localhost:4444/hub/wd"));
    // grid connector is in use only if session Id exists
    doReturn(new SessionId("1234")).when(gridConnector).getSessionId();
    PowerMockito.mockStatic(SeleniumGridConnectorFactory.class);
    PowerMockito.when(SeleniumGridConnectorFactory.getInstances(Arrays.asList("http://localhost:4444/hub/wd"))).thenReturn(Arrays.asList(gridConnector));
    try {
        System.setProperty(SeleniumTestsContext.RUN_MODE, "grid");
        System.setProperty(SeleniumTestsContext.WEB_DRIVER_GRID, "http://localhost:4444/hub/wd");
        ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
        initThreadContext(testNGCtx, "myTest", testResult);
        Assert.assertEquals(SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector(), gridConnector);
    } finally {
        System.clearProperty(SeleniumTestsContext.RUN_MODE);
        System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
    }
}
Also used : ITestResult(org.testng.ITestResult) SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) SessionId(org.openqa.selenium.remote.SessionId) 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 32 with SeleniumGridConnector

use of com.seleniumtests.connectors.selenium.SeleniumGridConnector in project seleniumRobot by bhecquet.

the class TestSeleniumTestContext3 method testNoGridConnection.

/**
 * Local test, no grid connector
 *
 * @param testNGCtx
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 * @throws NoSuchFieldException
 * @throws SecurityException
 * @throws NoSuchMethodException
 */
@Test(groups = "ut")
public void testNoGridConnection(final ITestContext testNGCtx) throws NoSuchMethodException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    SeleniumGridConnector gridConnector = spy(new SeleniumGridConnector("http://localhost:4444/hub/wd"));
    // grid connector is in use only if session Id exists
    doReturn(new SessionId("1234")).when(gridConnector).getSessionId();
    PowerMockito.mockStatic(SeleniumGridConnectorFactory.class);
    PowerMockito.when(SeleniumGridConnectorFactory.getInstances(Arrays.asList("http://localhost:4444/hub/wd"))).thenReturn(Arrays.asList(gridConnector));
    try {
        System.setProperty(SeleniumTestsContext.RUN_MODE, "local");
        System.setProperty(SeleniumTestsContext.WEB_DRIVER_GRID, "http://localhost:4444/hub/wd");
        ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
        initThreadContext(testNGCtx, "myTest", testResult);
        Assert.assertNull(SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector());
    } finally {
        System.clearProperty(SeleniumTestsContext.RUN_MODE);
        System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
    }
}
Also used : ITestResult(org.testng.ITestResult) SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) SessionId(org.openqa.selenium.remote.SessionId) 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)

Aggregations

SeleniumGridConnector (com.seleniumtests.connectors.selenium.SeleniumGridConnector)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)28 Test (org.testng.annotations.Test)28 SeleniumRobotGridConnector (com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector)19 ConnectorsTest (com.seleniumtests.ConnectorsTest)18 GenericTest (com.seleniumtests.GenericTest)13 XmlTest (org.testng.xml.XmlTest)13 MockitoTest (com.seleniumtests.MockitoTest)10 SessionId (org.openqa.selenium.remote.SessionId)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 ScenarioException (com.seleniumtests.customexception.ScenarioException)3 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)3 ITestResult (org.testng.ITestResult)3 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 InputStream (java.io.InputStream)2 StringInputStream (org.apache.tools.ant.filters.StringInputStream)2 SessionNotCreatedException (org.openqa.selenium.SessionNotCreatedException)2 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)2 SeleniumGridNodeNotAvailable (com.seleniumtests.customexception.SeleniumGridNodeNotAvailable)1 SeleniumRobotLogger (com.seleniumtests.util.logging.SeleniumRobotLogger)1