use of com.seleniumtests.connectors.selenium.SeleniumGridConnector in project seleniumRobot by bhecquet.
the class TestTestTasks method testExecuteCommandGrid.
@Test(groups = { "ut" })
public void testExecuteCommandGrid(final ITestContext testNGCtx) {
SeleniumGridConnector gridConnector = spy(new SeleniumRobotGridConnector("http://localhost:4444/hub/wd"));
gridConnector.setNodeUrl("http://localhost:5555/hub/wd");
doReturn("hello guys").when(gridConnector).executeCommand("echo", -1, "hello");
// 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");
initThreadContext(testNGCtx);
SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnectors();
String response = TestTasks.executeCommand("echo", "hello");
Assert.assertEquals(response, "hello guys");
} finally {
System.clearProperty(SeleniumTestsContext.RUN_MODE);
System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
}
}
use of com.seleniumtests.connectors.selenium.SeleniumGridConnector in project seleniumRobot by bhecquet.
the class TestTestTasks method testKillProcessGrid.
@Test(groups = { "ut" })
public void testKillProcessGrid(final ITestContext testNGCtx) {
SeleniumGridConnector gridConnector = spy(new SeleniumRobotGridConnector("http://localhost:4444/hub/wd"));
doNothing().when(gridConnector).killProcess("some_process");
// 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");
initThreadContext(testNGCtx);
SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnectors();
TestTasks.killProcess("some_process");
verify(gridConnector).killProcess("some_process");
} finally {
System.clearProperty(SeleniumTestsContext.RUN_MODE);
System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
}
}
use of com.seleniumtests.connectors.selenium.SeleniumGridConnector in project seleniumRobot by bhecquet.
the class TestTestTasks method testGetProcessListGridNotUsed.
/**
* Test when the grid connector is not initialized
* When grid connector does not return any sessionId, it's not active
* @param testNGCtx
*/
@Test(groups = { "ut" }, expectedExceptions = ScenarioException.class)
public void testGetProcessListGridNotUsed(final ITestContext testNGCtx) {
SeleniumGridConnector gridConnector = spy(new SeleniumRobotGridConnector("http://localhost:4444/hub/wd"));
doReturn(Arrays.asList(10, 20)).when(gridConnector).getProcessList("some_process");
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");
initThreadContext(testNGCtx);
SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnectors();
TestTasks.getProcessList("some_process");
verify(gridConnector).getProcessList("some_process");
} finally {
System.clearProperty(SeleniumTestsContext.RUN_MODE);
System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
}
}
use of com.seleniumtests.connectors.selenium.SeleniumGridConnector in project seleniumRobot by bhecquet.
the class SeleniumGridDriverFactory method createWebDriver.
@Override
public WebDriver createWebDriver() {
// create capabilities, specific to OS
MutableCapabilities capabilities = createSpecificGridCapabilities(webDriverConfig);
capabilities.merge(driverOptions);
// upload file on all available grids as we don't know which one will be chosen before driver has been created
for (SeleniumGridConnector gridConnector : gridConnectors) {
gridConnector.uploadMobileApp(capabilities);
}
// connection to grid is made here
for (int i = 0; i < 3; i++) {
long start = new Date().getTime();
driver = getDriver(capabilities);
long duration = new Date().getTime() - start;
setImplicitWaitTimeout(webDriverConfig.getImplicitWaitTimeout());
if (webDriverConfig.getPageLoadTimeout() >= 0 && SeleniumTestsContextManager.isWebTest()) {
setPageLoadTimeout(webDriverConfig.getPageLoadTimeout());
}
this.setWebDriver(driver);
// if session has not been really created, we retry
try {
activeGridConnector.getSessionInformationFromGrid((RemoteWebDriver) driver, duration);
} catch (SessionNotCreatedException e) {
logger.error(e.getMessage());
continue;
}
// sets a file detector. This is only useful for remote drivers
((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
// create a BrowserInfo based on information get from grid hub
selectedBrowserInfo = new BrowserInfo(BrowserType.getBrowserTypeFromSeleniumBrowserType(((RemoteWebDriver) driver).getCapabilities().getBrowserName()), ((RemoteWebDriver) driver).getCapabilities().getVersion());
return driver;
}
throw new SessionNotCreatedException("Session not created on any grid hub, after 3 tries");
}
use of com.seleniumtests.connectors.selenium.SeleniumGridConnector in project seleniumRobot by bhecquet.
the class TestSeleniumGridConnector method testDoNothing.
/**
* With simple selenium grid, upload is not available
* @throws ClientProtocolException
* @throws UnsupportedOperationException
* @throws IOException
*/
@Test(groups = { "ut" })
public void testDoNothing() throws ClientProtocolException, IOException {
SeleniumGridConnector connector = new SeleniumGridConnector("http://localhost:6666");
connector.uploadMobileApp(new DesiredCapabilities());
verify(client, never()).execute((HttpHost) any(HttpHost.class), any(HttpRequest.class));
}
Aggregations