Search in sources :

Example 1 with PictureElement

use of com.seleniumtests.uipage.htmlelements.PictureElement in project seleniumRobot by bhecquet.

the class TestPictureElement method testPictureNotVisibleWithReplay.

@Test(groups = { "ut" })
public void testPictureNotVisibleWithReplay() throws AWTException {
    PictureElement picElement = spy(pictureElement);
    picElement.setObjectPictureFile(new File(""));
    doReturn(screenshotUtil).when(picElement).getScreenshotUtil();
    when(screenshotUtil.capture(SnapshotTarget.PAGE, File.class, true)).thenReturn(new File(""));
    doThrow(ImageSearchException.class).when(imageDetector).detectExactZoneWithScale();
    Assert.assertFalse(picElement.isElementPresent(350));
    verify(picElement, times(2)).findElement();
}
Also used : PictureElement(com.seleniumtests.uipage.htmlelements.PictureElement) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 2 with PictureElement

use of com.seleniumtests.uipage.htmlelements.PictureElement in project seleniumRobot by bhecquet.

the class TestPictureElement method testClickOtherPixelRatio.

@Test(groups = { "ut" })
public void testClickOtherPixelRatio() {
    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.5);
    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.5);
    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();
    // as pixel ratio changed, real rectangle is different
    verify(picElement).moveAndClick(intoElement, -78, -81);
}
Also used : PictureElement(com.seleniumtests.uipage.htmlelements.PictureElement) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) Rectangle(org.openqa.selenium.Rectangle) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 3 with PictureElement

use of com.seleniumtests.uipage.htmlelements.PictureElement in project seleniumRobot by bhecquet.

the class TestPictureElement method testPictureNotVisible.

@Test(groups = { "ut" })
public void testPictureNotVisible() throws AWTException {
    PictureElement picElement = spy(pictureElement);
    picElement.setObjectPictureFile(new File(""));
    when(screenshotUtil.capture(SnapshotTarget.PAGE, File.class, true)).thenReturn(new File(""));
    doReturn(screenshotUtil).when(picElement).getScreenshotUtil();
    doThrow(ImageSearchException.class).when(imageDetector).detectExactZoneWithScale();
    Assert.assertFalse(picElement.isElementPresent());
    verify(picElement).findElement();
}
Also used : PictureElement(com.seleniumtests.uipage.htmlelements.PictureElement) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 4 with PictureElement

use of com.seleniumtests.uipage.htmlelements.PictureElement 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();
}
Also used : PictureElement(com.seleniumtests.uipage.htmlelements.PictureElement) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) Rectangle(org.openqa.selenium.Rectangle) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 5 with PictureElement

use of com.seleniumtests.uipage.htmlelements.PictureElement 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);
}
Also used : PictureElement(com.seleniumtests.uipage.htmlelements.PictureElement) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) Rectangle(org.openqa.selenium.Rectangle) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

MockitoTest (com.seleniumtests.MockitoTest)5 PictureElement (com.seleniumtests.uipage.htmlelements.PictureElement)5 File (java.io.File)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Test (org.testng.annotations.Test)5 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)3 Rectangle (org.openqa.selenium.Rectangle)3 Dimension (org.openqa.selenium.Dimension)2 Point (org.openqa.selenium.Point)2