Search in sources :

Example 11 with CustomEventFiringWebDriver

use of com.seleniumtests.driver.CustomEventFiringWebDriver 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 12 with CustomEventFiringWebDriver

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

the class TestCustomEventFiringWebDriver method testViewPortDimensionWithoutScrollbar.

/**
 * Check standard web case where dimension comes from javascript call
 */
@Test(groups = { "ut" })
public void testViewPortDimensionWithoutScrollbar() {
    when(driver.executeScript(anyString(), eq(true))).thenReturn(120L).thenReturn(80L);
    Dimension dim = ((CustomEventFiringWebDriver) eventDriver).getViewPortDimensionWithoutScrollbar();
    // no need to switch to default content if size is correctly returned
    verify(driver, never()).switchTo();
    // check we get the window dimension
    Assert.assertEquals(dim.height, 80);
    Assert.assertEquals(dim.width, 120);
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) Dimension(org.openqa.selenium.Dimension) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with CustomEventFiringWebDriver

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

the class TestWebUIDriver method testDriverCreationWithVideoInError.

@Test(groups = { "ut" })
public void testDriverCreationWithVideoInError() throws Exception {
    SeleniumTestsContextManager.getThreadContext().setVideoCapture("true");
    SeleniumTestsContextManager.getThreadContext().setBrowser("htmlunit");
    PowerMockito.mockStatic(CustomEventFiringWebDriver.class);
    PowerMockito.doThrow(new ScenarioException("error")).when(CustomEventFiringWebDriver.class, "startVideoCapture", eq(DriverMode.LOCAL), eq(null), any(File.class), eq("videoCapture.avi"));
    WebDriver driver = WebUIDriver.getWebDriver(true);
    Assert.assertTrue(driver instanceof CustomEventFiringWebDriver);
    Assert.assertNull(WebUIDriver.getVideoRecorder().get());
}
Also used : NLWebDriver(com.neotys.selenium.proxies.NLWebDriver) WebDriver(org.openqa.selenium.WebDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) File(java.io.File) ScenarioException(com.seleniumtests.customexception.ScenarioException) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with CustomEventFiringWebDriver

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

the class TestWebUIDriver method testDriverCreationWithDefaultType.

/**
 * If BrowserType is not given, the type is taken from context parameter
 */
@Test(groups = { "ut" })
public void testDriverCreationWithDefaultType() {
    SeleniumTestsContextManager.getThreadContext().setBrowser("htmlunit");
    WebDriver driver1 = WebUIDriver.getWebDriver(true, null, "main", null);
    Assert.assertTrue(((CustomEventFiringWebDriver) driver1).getWebDriver() instanceof HtmlUnitDriver);
}
Also used : NLWebDriver(com.neotys.selenium.proxies.NLWebDriver) WebDriver(org.openqa.selenium.WebDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 15 with CustomEventFiringWebDriver

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

the class TestWebUIDriver method testDriverCreationWithNeoload.

/**
 * Check that when user requests  for neoload, it's driver is added
 */
@Test(groups = { "ut" })
public void testDriverCreationWithNeoload() {
    PowerMockito.mockStatic(NLWebDriverFactory.class);
    PowerMockito.when(NLWebDriverFactory.newNLWebDriver(any(WebDriver.class), anyString())).thenReturn(neoloadDriver);
    try {
        SeleniumTestsContextManager.getThreadContext().setNeoloadUserPath("path");
        System.setProperty("nl.selenium.proxy.mode", "Design");
        SeleniumTestsContextManager.getThreadContext().setBrowser("htmlunit");
        WebDriver driver = WebUIDriver.getWebDriver(true);
        Assert.assertTrue(driver instanceof CustomEventFiringWebDriver);
        Assert.assertNotNull(((CustomEventFiringWebDriver) driver).getNeoloadDriver());
    } finally {
        System.clearProperty("nl.selenium.proxy.mode");
    }
}
Also used : NLWebDriver(com.neotys.selenium.proxies.NLWebDriver) WebDriver(org.openqa.selenium.WebDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)77 Test (org.testng.annotations.Test)53 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)36 MockitoTest (com.seleniumtests.MockitoTest)35 Dimension (org.openqa.selenium.Dimension)26 WebDriver (org.openqa.selenium.WebDriver)14 GenericDriverTest (com.seleniumtests.GenericDriverTest)12 Point (org.openqa.selenium.Point)12 GenericTest (com.seleniumtests.GenericTest)10 ScenarioException (com.seleniumtests.customexception.ScenarioException)9 WebDriverException (org.openqa.selenium.WebDriverException)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 DriverExceptionListener (com.seleniumtests.driver.DriverExceptionListener)6 SkipException (org.testng.SkipException)6 NLWebDriver (com.neotys.selenium.proxies.NLWebDriver)5 File (java.io.File)5 IOException (java.io.IOException)5 Rectangle (org.openqa.selenium.Rectangle)5 WebElement (org.openqa.selenium.WebElement)5 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)4