use of com.seleniumtests.driver.CustomEventFiringWebDriver in project seleniumRobot by bhecquet.
the class TestHtmlElement method testGetCenter.
@Test(groups = { "ut" })
public void testGetCenter() throws Exception {
SeleniumTestsContextManager.getThreadContext().setTestType(TestType.APPIUM_WEB_ANDROID);
SeleniumTestsContextManager.getThreadContext().setPlatform("android");
when(WebUIDriver.getWebDriver(anyBoolean())).thenReturn(new CustomEventFiringWebDriver(mobileDriver));
doNothing().when(el).findElement(anyBoolean(), anyBoolean());
el.setElement(mobileElement);
el.getCenter();
PowerMockito.verifyPrivate(el, atLeastOnce()).invoke("checkForMobile");
}
use of com.seleniumtests.driver.CustomEventFiringWebDriver in project seleniumRobot by bhecquet.
the class TestHtmlElement method testSwipe1.
@Test(groups = { "ut" })
public void testSwipe1() throws Exception {
SeleniumTestsContextManager.getThreadContext().setTestType(TestType.APPIUM_WEB_ANDROID);
SeleniumTestsContextManager.getThreadContext().setPlatform("android");
when(WebUIDriver.getWebDriver(anyBoolean())).thenReturn(new CustomEventFiringWebDriver(mobileDriver));
doNothing().when(el).findElement(anyBoolean(), anyBoolean());
el.setElement(mobileElement);
el.swipe(0, 0, 0, 10);
PowerMockito.verifyPrivate(el, atLeastOnce()).invoke("checkForMobile");
}
use of com.seleniumtests.driver.CustomEventFiringWebDriver in project seleniumRobot by bhecquet.
the class TestHtmlElement method init.
@BeforeMethod(groups = { "ut" })
private void init() throws WebDriverException, IOException {
// mimic sub elements of the HtmlElement
List<WebElement> subElList = new ArrayList<WebElement>();
subElList.add(subElement1);
subElList.add(subElement2);
// list of elements correspond
List<WebElement> elList = new ArrayList<WebElement>();
elList.add(element);
// add DriverExceptionListener to reproduce driver behavior
eventDriver = spy(new CustomEventFiringWebDriver(driver).register(new DriverExceptionListener()));
PowerMockito.mockStatic(WebUIDriver.class);
when(WebUIDriver.getWebDriver(anyBoolean())).thenReturn(eventDriver);
when(WebUIDriver.getWebUIDriver(anyBoolean())).thenReturn(uiDriver);
when(driver.findElement(By.id("el"))).thenReturn(element);
when(driver.findElement(By.id("frame"))).thenReturn(frameElement);
when(driver.findElements(By.id("frame"))).thenReturn(Arrays.asList(frameElement));
when(driver.findElements(By.name("subEl"))).thenReturn(subElList);
when(driver.findElement(By.name("subEl"))).thenReturn(subElement1);
when(driver.findElements(By.id("el"))).thenReturn(elList);
when(driver.getKeyboard()).thenReturn(keyboard);
when(driver.getMouse()).thenReturn(mouse);
when(driver.switchTo()).thenReturn(locator);
when(driver.manage()).thenReturn(options);
when(options.timeouts()).thenReturn(timeouts);
when(driver.executeScript(anyString())).thenReturn(Arrays.asList(100, 100));
when(uiDriver.getConfig()).thenReturn(driverConfig);
when(driverConfig.getBrowserType()).thenReturn(BrowserType.HTMLUNIT);
when(driverConfig.getMajorBrowserVersion()).thenReturn(1);
when(element.findElement(By.name("subEl"))).thenReturn(subElement1);
when(element.findElements(By.name("subEl"))).thenReturn(subElList);
when(element.getAttribute(anyString())).thenReturn("attribute");
when(element.getSize()).thenReturn(new Dimension(10, 10));
when(element.getLocation()).thenReturn(new Point(5, 5));
when(frame.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);
when(subElement1.isDisplayed()).thenReturn(true);
when(subElement2.isDisplayed()).thenReturn(true);
when(subElement1.getLocation()).thenReturn(new Point(5, 5));
when(subElement2.getLocation()).thenReturn(new Point(5, 5));
when(mobileElement.getCenter()).thenReturn(new Point(2, 2));
when(mobileElement.getLocation()).thenReturn(new Point(1, 1));
when(mobileElement.isDisplayed()).thenReturn(true);
when(mobileElement.getId()).thenReturn("12");
// init for mobile tests
AppiumCommandExecutor ce = Mockito.mock(AppiumCommandExecutor.class);
Response response = new Response(new SessionId("1"));
response.setValue(new HashMap<String, Object>());
Response findResponse = new Response(new SessionId("1"));
findResponse.setValue(mobileElement);
when(ce.execute(any())).thenReturn(response, response, response, findResponse);
doReturn(response).when(ce).execute(argThat(command -> DriverCommand.NEW_SESSION.equals(command.getName())));
doReturn(response).when(ce).execute(argThat(command -> DriverCommand.FIND_ELEMENT.equals(command.getName())));
doReturn(response).when(ce).execute(argThat(command -> "getSession".equals(command.getName())));
// newSession, getSession, getSession, findElement
mobileDriver = Mockito.spy(new AppiumDriver<>(ce, new DesiredCapabilities()));
SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
SeleniumTestsContextManager.getThreadContext().setBrowser("htmlunit");
}
use of com.seleniumtests.driver.CustomEventFiringWebDriver in project seleniumRobot by bhecquet.
the class TestPictureElement method testPictureVisible.
@Test(groups = { "ut" })
public void testPictureVisible() throws AWTException {
PictureElement picElement = spy(pictureElement);
PowerMockito.mockStatic(WebUIDriver.class);
when(WebUIDriver.getWebDriver(anyBoolean())).thenReturn(driver);
when(WebUIDriver.getWebUIDriver(anyBoolean())).thenReturn(uiDriver);
when(uiDriver.getDriver()).thenReturn(driver);
when(((CustomEventFiringWebDriver) driver).getDeviceAspectRatio()).thenReturn(1.0);
picElement.setObjectPictureFile(new File(""));
doReturn(screenshotUtil).when(picElement).getScreenshotUtil();
when(screenshotUtil.capture(SnapshotTarget.PAGE, File.class, true)).thenReturn(new File(""));
when(imageDetector.getDetectedRectangle()).thenReturn(new Rectangle(10, 10, 100, 50));
when(imageDetector.getSizeRatio()).thenReturn(1.0);
Assert.assertTrue(picElement.isElementPresent(2000));
verify(picElement).findElement();
}
use of com.seleniumtests.driver.CustomEventFiringWebDriver in project seleniumRobot by bhecquet.
the class TestPictureElement method testClick.
@Test(groups = { "ut" })
public void testClick() {
PictureElement picElement = spy(pictureElement);
picElement.setObjectPictureFile(new File(""));
PowerMockito.mockStatic(WebUIDriver.class);
when(WebUIDriver.getWebDriver(anyBoolean())).thenReturn(driver);
when(WebUIDriver.getWebUIDriver(anyBoolean())).thenReturn(uiDriver);
when(uiDriver.getDriver()).thenReturn(driver);
when(uiDriver.getConfig()).thenReturn(driverConfig);
when(driverConfig.getBrowserType()).thenReturn(BrowserType.FIREFOX);
when(driver.getMouse()).thenReturn(mouse);
when(driver.getKeyboard()).thenReturn(keyboard);
when(driver.getBrowserInfo()).thenReturn(browserInfo);
when(((CustomEventFiringWebDriver) driver).getDeviceAspectRatio()).thenReturn(1.0);
when(browserInfo.getBrowser()).thenReturn(BrowserType.FIREFOX);
when(screenshotUtil.capture(SnapshotTarget.PAGE, File.class, true)).thenReturn(new File(""));
when(imageDetector.getDetectedRectangle()).thenReturn(new Rectangle(10, 10, 100, 50));
when(imageDetector.getSizeRatio()).thenReturn(1.0);
when(coordinates.inViewPort()).thenReturn(new Point(100, 120));
when(coordinates.onPage()).thenReturn(new Point(100, 120));
when(intoElement.getCoordinates()).thenReturn(coordinates);
when(intoElement.getSize()).thenReturn(new Dimension(200, 200));
doReturn(screenshotUtil).when(picElement).getScreenshotUtil();
picElement.click();
verify(picElement).moveAndClick(intoElement, -65, -60);
}
Aggregations