use of com.seleniumtests.driver.WebUIDriver in project seleniumRobot by bhecquet.
the class SeleniumNativeActions method setCurrentFrame.
private void setCurrentFrame(FrameElement frame) {
WebUIDriver uiDriver = WebUIDriver.getWebUIDriver(false);
if (uiDriver == null) {
return;
}
currentFrame.put(uiDriver, frame);
}
use of com.seleniumtests.driver.WebUIDriver in project seleniumRobot by bhecquet.
the class TestSeleniumGridDriverFactory method testTestsAreNotSkippedIfOneNodeIsGet.
/**
* issue #311: Check that after 3 tests that cannot get there node, we skip all the remaining tests
* @param testContext
* @throws Exception
*/
@Test(groups = { "it" })
public void testTestsAreNotSkippedIfOneNodeIsGet(ITestContext testContext) throws Exception {
try {
SeleniumGridDriverFactory.setRetryTimeout(1);
System.setProperty(SeleniumTestsContext.RUN_MODE, "grid");
System.setProperty(SeleniumTestsContext.WEB_DRIVER_GRID, SERVER_URL + "/wd/hub");
WebUIDriver uiDriver = createMockedWebDriver();
// grid is there
createServerMock("GET", SeleniumGridConnector.CONSOLE_SERVLET, 200, "Console");
createServerMock("GET", SeleniumRobotGridConnector.NODE_TASK_SERVLET, 200, "ABC");
createServerMock("POST", SeleniumRobotGridConnector.NODE_TASK_SERVLET, 200, "ABC");
createServerMock("GET", SeleniumRobotGridConnector.GUI_SERVLET, 200, "Gui");
createJsonServerMock("GET", SeleniumRobotGridConnector.STATUS_SERVLET, 200, // node is not there 2 times
"{" + " \"hub\": {" + " \"version\": \"4.6.1\"," + " \"status\": \"ACTIVE\"" + " }," + " \"success\": true" + "}", "{" + " \"hub\": {" + " \"version\": \"4.6.1\"," + " \"status\": \"ACTIVE\"" + " }," + " \"success\": true" + "}", // node is finally here
"{\"http://localhost:4321\": {" + " \"busy\": false," + " \"lastSessionStart\": \"never\"," + " \"version\": \"4.6.0\"," + " \"usedTestSlots\": 0,\n" + " \"testSlots\": 1," + " \"status\": \"ACTIVE\"" + " }," + " \"hub\": {" + " \"version\": \"4.6.1\"," + " \"status\": \"ACTIVE\"" + " }," + " \"success\": true" + "}");
createJsonServerMock("GET", SeleniumRobotGridConnector.API_TEST_SESSSION, 200, // session found
"{" + " \"inactivityTime\": 409," + " \"internalKey\": \"fef800fc-941d-4f76-9590-711da6443e00\"," + " \"msg\": \"slot found !\"," + " \"proxyId\": \"http://localhost:4321\"," + " \"session\": \"7ef50edc-ce51-40dd-98b6-0a369bff38b1\"," + " \"success\": true" + "}");
ReporterTest.executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForDriverTest" }, ParallelMode.NONE, new String[] { "testDriverShort", "testDriverShort2", "testDriverShort3", "testDriverShort4" });
String logs = ReporterTest.readSeleniumRobotLogFile();
// check that testDriverShort3 and testDriverShort4 are executed because now, we find nodes
Assert.assertTrue(logs.contains("Cannot create driver on grid, it may be fully used [0 times]"));
Assert.assertTrue(logs.contains("Cannot create driver on grid, it may be fully used [1 times]"));
Assert.assertFalse(logs.contains("Cannot create driver on grid, it may be fully used [2 times]"));
// 2 tests KO (the first ones)
Assert.assertEquals(StringUtils.countMatches(logs, "Test is KO with error: class com.seleniumtests.customexception.SeleniumGridNodeNotAvailable: Cannot create driver"), 2);
// 2 tests OK because we got nodes
Assert.assertEquals(StringUtils.countMatches(logs, "Test is OK"), 2);
Assert.assertFalse(logs.contains("Skipping as the 3 previous tests could not get any matching node"));
Assert.assertEquals(SeleniumGridDriverFactory.getCounter(), 0);
} finally {
SeleniumGridDriverFactory.setRetryTimeout(SeleniumGridDriverFactory.DEFAULT_RETRY_TIMEOUT);
System.clearProperty(SeleniumTestsContext.RUN_MODE);
System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
}
}
use of com.seleniumtests.driver.WebUIDriver in project seleniumRobot by bhecquet.
the class TestSeleniumGridDriverFactory method testTestsAreSkippedIfNodeIsNeverAvailable.
/**
* issue #311: Check that after 3 tests that cannot get there node, we skip all the remaining tests
* @param testContext
* @throws Exception
*/
@Test(groups = { "it" })
public void testTestsAreSkippedIfNodeIsNeverAvailable(ITestContext testContext) throws Exception {
try {
SeleniumGridDriverFactory.setRetryTimeout(1);
System.setProperty(SeleniumTestsContext.RUN_MODE, "grid");
System.setProperty(SeleniumTestsContext.WEB_DRIVER_GRID, SERVER_URL + "/wd/hub");
WebUIDriver uiDriver = createMockedWebDriver();
// grid is there but we cannot get any matching node
createServerMock("GET", SeleniumGridConnector.CONSOLE_SERVLET, 200, "Console");
createServerMock("GET", SeleniumRobotGridConnector.GUI_SERVLET, 200, "Gui");
createServerMock("GET", SeleniumRobotGridConnector.STATUS_SERVLET, 500, "{}");
ReporterTest.executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForDriverTest" }, ParallelMode.NONE, new String[] { "testDriverShort", "testDriverShort2", "testDriverShort3", "testDriverShort4" });
// check the test is not retried when
String logs = ReporterTest.readSeleniumRobotLogFile();
Assert.assertFalse(logs.contains("Retrying 1 time"));
// check the 4th test is skipped but other are not
Assert.assertTrue(logs.contains("Cannot create driver on grid, it may be fully used [0 times]"));
Assert.assertTrue(logs.contains("Cannot create driver on grid, it may be fully used [1 times]"));
Assert.assertTrue(logs.contains("Cannot create driver on grid, it may be fully used [2 times]"));
Assert.assertFalse(logs.contains("Cannot create driver on grid, it may be fully used [3 times]"));
Assert.assertTrue(logs.contains("Skipping as the 3 previous tests could not get any matching node"));
} finally {
SeleniumGridDriverFactory.setRetryTimeout(SeleniumGridDriverFactory.DEFAULT_RETRY_TIMEOUT);
System.clearProperty(SeleniumTestsContext.RUN_MODE);
System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
}
}
use of com.seleniumtests.driver.WebUIDriver in project seleniumRobot by bhecquet.
the class TestSeleniumGridDriverFactory method testSessionNotGet.
/**
* issue #287: check the real behavior of the bug (for now, this cannot be corrected because of https://github.com/cbeust/testng/issues/2148)
* When the AfterMethod fails, test is not retried and this is a bug in testNG
* @param testContext
* @throws Exception
*/
@Test(groups = { "it" })
public void testSessionNotGet(ITestContext testContext) throws Exception {
try {
System.setProperty(SeleniumTestsContext.TEST_RETRY_COUNT, "1");
System.setProperty(SeleniumTestsContext.RUN_MODE, "grid");
System.setProperty(SeleniumTestsContext.WEB_DRIVER_GRID, SERVER_URL + "/wd/hub");
WebUIDriver uiDriver = createMockedWebDriver();
createServerMock("GET", SeleniumGridConnector.CONSOLE_SERVLET, 200, "Console");
createServerMock("GET", SeleniumRobotGridConnector.GUI_SERVLET, 200, "Gui");
createServerMock("GET", SeleniumRobotGridConnector.STATUS_SERVLET, 200, "{\"http://localhost:5555\": {" + " \"busy\": false," + " \"lastSessionStart\": \"never\"," + " \"version\": \"4.6.0\"," + " \"usedTestSlots\": 0,\n" + " \"testSlots\": 1," + " \"status\": \"ACTIVE\"" + " }," + " \"hub\": {" + " \"version\": \"4.6.1\"," + " \"status\": \"ACTIVE\"" + " }," + " \"success\": true" + "}");
// // session is found (kept here for information)
// createServerMock("GET", SeleniumRobotGridConnector.API_TEST_SESSSION, 200, "{" +
// " \"inactivityTime\": 409," +
// " \"internalKey\": \"fef800fc-941d-4f76-9590-711da6443e00\"," +
// " \"msg\": \"slot found !\"," +
// " \"proxyId\": \"http://localhost:5555\"," +
// " \"session\": \"7ef50edc-ce51-40dd-98b6-0a369bff38b1\"," +
// " \"success\": true" +
// "}");
// session not found
createServerMock("GET", SeleniumRobotGridConnector.API_TEST_SESSSION, 200, "{" + " \"msg\": \"Cannot find test slot running session 7ef50edc-ce51-40dd-98b6-0a369bff38b in the registry.\"," + " \"success\": false" + "}");
ReporterTest.executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForDriverTest" }, ParallelMode.METHODS, new String[] { "testDriverShort" });
// check that we tried to create the driver twice (the bug is based on the fact that we create it only once)
verify(uiDriver, times(2)).createWebDriver();
String logs = ReporterTest.readSeleniumRobotLogFile();
Assert.assertEquals(StringUtils.countMatches(logs, "Start creating *chrome driver"), 2);
} finally {
System.clearProperty(SeleniumTestsContext.TEST_RETRY_COUNT);
System.clearProperty(SeleniumTestsContext.RUN_MODE);
System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
}
}
use of com.seleniumtests.driver.WebUIDriver in project seleniumRobot by bhecquet.
the class ConnectorsTest method createMockedWebDriver.
protected WebUIDriver createMockedWebDriver() throws Exception {
WebUIDriver uiDriver = spy(new WebUIDriver("main"));
PowerMockito.whenNew(WebUIDriver.class).withArguments(any()).thenReturn(uiDriver);
PowerMockito.whenNew(RemoteWebDriver.class).withAnyArguments().thenReturn(driver);
when(driver.manage()).thenReturn(options);
when(options.timeouts()).thenReturn(timeouts);
when(driver.getSessionId()).thenReturn(new SessionId("abcdef"));
when(driver.navigate()).thenReturn(navigation);
when(driver.switchTo()).thenReturn(targetLocator);
when(driver.getCapabilities()).thenReturn(new DesiredCapabilities("chrome", "75.0", Platform.WINDOWS));
when(driver.findElement(By.id("text2"))).thenReturn(element);
when(element.getAttribute(anyString())).thenReturn("attribute");
when(element.getSize()).thenReturn(new Dimension(10, 10));
when(element.getLocation()).thenReturn(new Point(5, 5));
when(element.getTagName()).thenReturn("h1");
when(element.getText()).thenReturn("text");
when(element.isDisplayed()).thenReturn(true);
when(element.isEnabled()).thenReturn(true);
return uiDriver;
}
Aggregations