Search in sources :

Example 1 with DriverExceptionListener

use of com.seleniumtests.driver.DriverExceptionListener in project seleniumRobot by bhecquet.

the class TestCustomEventFiringWebDriver method testContentDimensionWithoutScrollbarNonWebTest.

/**
 * For non web test, dimension is returned from driver call, not javascript
 */
@Test(groups = { "ut" })
public void testContentDimensionWithoutScrollbarNonWebTest() {
    eventDriver = spy(new CustomEventFiringWebDriver(driver, null, null, false, DriverMode.LOCAL, null, null).register(new DriverExceptionListener()));
    when(driver.executeScript(anyString(), eq(true))).thenReturn(120L).thenReturn(80L);
    Dimension dim = ((CustomEventFiringWebDriver) eventDriver).getViewPortDimensionWithoutScrollbar();
    // check we get the window dimension
    Assert.assertEquals(dim.height, 100);
    Assert.assertEquals(dim.width, 100);
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) DriverExceptionListener(com.seleniumtests.driver.DriverExceptionListener) Dimension(org.openqa.selenium.Dimension) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with DriverExceptionListener

use of com.seleniumtests.driver.DriverExceptionListener in project seleniumRobot by bhecquet.

the class TestCustomEventFiringWebDriver method testScrollPositionNonWebTest.

/**
 * For non web test, dimension is returned from driver call, not javascript
 */
@Test(groups = { "ut" }, expectedExceptions = WebDriverException.class)
public void testScrollPositionNonWebTest() {
    eventDriver = spy(new CustomEventFiringWebDriver(driver, null, null, false, DriverMode.LOCAL, null, null).register(new DriverExceptionListener()));
    when(driver.executeScript(anyString())).thenReturn(Arrays.asList(120L, 80L));
    ((CustomEventFiringWebDriver) eventDriver).getScrollPosition();
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) DriverExceptionListener(com.seleniumtests.driver.DriverExceptionListener) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with DriverExceptionListener

use of com.seleniumtests.driver.DriverExceptionListener in project seleniumRobot by bhecquet.

the class TestCustomEventFiringWebDriver method init.

@BeforeMethod(groups = { "ut" })
private void init() throws Exception {
    PowerMockito.spy(CustomEventFiringWebDriver.class);
    // add DriverExceptionListener to reproduce driver behavior
    eventDriver = spy(new CustomEventFiringWebDriver(driver, null, browserInfo, true, DriverMode.LOCAL, null, null).register(new DriverExceptionListener()));
    attachedEventDriver = spy(new CustomEventFiringWebDriver(driver, null, browserInfo, true, DriverMode.LOCAL, null, null, 12345).register(new DriverExceptionListener()));
    when(driver.manage()).thenReturn(options);
    when(driver.getCapabilities()).thenReturn(capabilities);
    when(driver.switchTo()).thenReturn(target);
    when(driver.getSessionId()).thenReturn(new SessionId("1234"));
    when(driver.getPageSource()).thenReturn("<html></html>");
    when(options.window()).thenReturn(window);
    when(window.getSize()).thenReturn(new Dimension(100, 100));
    PowerMockito.mockStatic(OSUtilityFactory.class);
    when(OSUtilityFactory.getInstance()).thenReturn(osUtility);
    PowerMockito.whenNew(Robot.class).withNoArguments().thenReturn(robot);
    PowerMockito.whenNew(VideoRecorder.class).withAnyArguments().thenReturn(videoRecorder);
    PowerMockito.whenNew(Keyboard.class).withNoArguments().thenReturn(keyboard);
    PowerMockito.doReturn(new Rectangle(1900, 1000)).when(CustomEventFiringWebDriver.class, "getScreensRectangle");
    PowerMockito.mockStatic(MouseInfo.class);
    PowerMockito.when(MouseInfo.getPointerInfo()).thenReturn(pointerInfo);
    when(pointerInfo.getLocation()).thenReturn(new java.awt.Point(2, 3));
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) DriverExceptionListener(com.seleniumtests.driver.DriverExceptionListener) Rectangle(java.awt.Rectangle) Dimension(org.openqa.selenium.Dimension) SessionId(org.openqa.selenium.remote.SessionId) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with DriverExceptionListener

use of com.seleniumtests.driver.DriverExceptionListener in project seleniumRobot by bhecquet.

the class TestActions method init.

@BeforeMethod(groups = { "ut" })
private void init() throws WebDriverException, IOException {
    SeleniumTestsContextManager.getGlobalContext().setCucumberImplementationPackage("com.seleniumtests.ut.core.runner.cucumber");
    // 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.getWebDriver(anyBoolean(), any(BrowserType.class), isNull(), isNull())).thenReturn(eventDriver);
    when(WebUIDriver.getWebUIDriver(anyBoolean())).thenReturn(uiDriver);
    when(driver.navigate()).thenReturn(navigation);
    when(driver.switchTo()).thenReturn(locator);
    when(eventDriver.switchTo()).thenReturn(locator);
    SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
    SeleniumTestsContextManager.getThreadContext().setBrowser("htmlunit");
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) DriverExceptionListener(com.seleniumtests.driver.DriverExceptionListener) BrowserType(com.seleniumtests.driver.BrowserType) ArrayList(java.util.ArrayList) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with DriverExceptionListener

use of com.seleniumtests.driver.DriverExceptionListener in project seleniumRobot by bhecquet.

the class TestCustomEventFiringWebDriver method testContentDimensionNonWebTest.

/**
 * For non web test, dimension is returned from driver call, not javascript
 */
@Test(groups = { "ut" })
public void testContentDimensionNonWebTest() {
    eventDriver = spy(new CustomEventFiringWebDriver(driver, null, null, false, DriverMode.LOCAL, null, null).register(new DriverExceptionListener()));
    when(driver.executeScript(anyString())).thenReturn(Arrays.asList(120L, 80L));
    Dimension dim = ((CustomEventFiringWebDriver) eventDriver).getContentDimension();
    // check we get the window dimension
    Assert.assertEquals(dim.height, 100);
    Assert.assertEquals(dim.width, 100);
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) DriverExceptionListener(com.seleniumtests.driver.DriverExceptionListener) Dimension(org.openqa.selenium.Dimension) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)6 DriverExceptionListener (com.seleniumtests.driver.DriverExceptionListener)6 MockitoTest (com.seleniumtests.MockitoTest)4 Dimension (org.openqa.selenium.Dimension)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Test (org.testng.annotations.Test)4 BrowserType (com.seleniumtests.driver.BrowserType)2 ArrayList (java.util.ArrayList)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 SeleniumTestsContextManager (com.seleniumtests.core.SeleniumTestsContextManager)1 TestStepManager (com.seleniumtests.core.TestStepManager)1 ScenarioException (com.seleniumtests.customexception.ScenarioException)1 DriverConfig (com.seleniumtests.driver.DriverConfig)1 TestType (com.seleniumtests.driver.TestType)1 WebUIDriver (com.seleniumtests.driver.WebUIDriver)1 TestStep (com.seleniumtests.reporter.logger.TestStep)1 StepStatus (com.seleniumtests.reporter.logger.TestStep.StepStatus)1 FrameElement (com.seleniumtests.uipage.htmlelements.FrameElement)1 HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)1 AppiumDriver (io.appium.java_client.AppiumDriver)1