Search in sources :

Example 76 with CustomEventFiringWebDriver

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

the class TestSelectList method init.

@BeforeMethod(groups = { "ut" })
private void init() throws IOException {
    SeleniumTestsContextManager.getThreadContext().setBrowser("firefox");
    SeleniumTestsContextManager.getThreadContext().setExplicitWaitTimeout(1);
    SeleniumTestsContextManager.getThreadContext().setImplicitWaitTimeout(1);
    SeleniumTestsContextManager.getThreadContext().setReplayTimeout(2);
    eventDriver = spy(new CustomEventFiringWebDriver(driver));
    when(eventDriver.switchTo()).thenReturn(target);
    // standard select
    when(driver.findElement(By.id("select"))).thenReturn(element);
    when(element.getTagName()).thenReturn("select");
    when(element.isDisplayed()).thenReturn(true);
    when(element.findElements(By.tagName("option"))).thenReturn(Arrays.asList(option1, option2));
    // the way Select class search for text and value
    when(element.findElements(By.xpath(".//option[normalize-space(.) = \"opt1\"]"))).thenReturn(Arrays.asList(option1));
    when(element.findElements(By.xpath(".//option[normalize-space(.) = \"opt2\"]"))).thenReturn(Arrays.asList(option2));
    when(element.findElements(By.xpath(".//option[@value = \"opti1\"]"))).thenReturn(Arrays.asList(option1));
    when(element.findElements(By.xpath(".//option[@value = \"opti2\"]"))).thenReturn(Arrays.asList(option2));
    when(option1.getText()).thenReturn("opt1");
    when(option2.getText()).thenReturn("opt2");
    when(option1.getAttribute("value")).thenReturn("opti1");
    when(option2.getAttribute("value")).thenReturn("opti2");
    when(option1.getAttribute("index")).thenReturn("1");
    when(option2.getAttribute("index")).thenReturn("2");
    // when(driver.getCurrentUrl()).thenReturn("http://foo");
    // when(element.getSize()).thenReturn(new Dimension(10, 10));
    // when(element.getLocation()).thenReturn(new Point(5, 5));
    PowerMockito.mockStatic(WebUIDriver.class);
    when(WebUIDriver.getCurrentWebUiDriverName()).thenReturn("main");
    when(WebUIDriver.getWebDriver(anyBoolean(), eq(BrowserType.FIREFOX), eq("main"), isNull())).thenReturn(eventDriver);
    when(WebUIDriver.getWebDriver(anyBoolean())).thenReturn(eventDriver);
    when(eventDriver.executeScript("if (document.readyState === \"complete\") { return \"ok\"; }")).thenReturn("ok");
    when(eventDriver.getBrowserInfo()).thenReturn(new BrowserInfo(BrowserType.FIREFOX, "78.0"));
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 77 with CustomEventFiringWebDriver

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

the class TestPageObject2 method init.

@BeforeMethod(groups = { "ut" })
private void init() throws IOException {
    SeleniumTestsContextManager.getGlobalContext().setCucumberImplementationPackage("com.seleniumtests.ut.core.runner.cucumber");
    SeleniumTestsContextManager.getThreadContext().setBrowser("firefox");
    SeleniumTestsContextManager.getThreadContext().setExplicitWaitTimeout(1);
    SeleniumTestsContextManager.getThreadContext().setImplicitWaitTimeout(1);
    SeleniumTestsContextManager.getThreadContext().setReplayTimeout(2);
    eventDriver = spy(new CustomEventFiringWebDriver(driver));
    when(eventDriver.switchTo()).thenReturn(target);
    when(driver.findElement(By.id("el"))).thenReturn(element);
    when(driver.navigate()).thenReturn(navigation);
    when(driver.getCurrentUrl()).thenReturn("http://foo");
    when(driver.manage()).thenReturn(driverOptions);
    when(driverOptions.timeouts()).thenReturn(timeouts);
    when(element.getSize()).thenReturn(new Dimension(10, 10));
    when(element.getLocation()).thenReturn(new Point(5, 5));
    when(targetLocator.alert()).thenReturn(alert);
    when(alert.getText()).thenReturn("alert text");
    when(driver.switchTo()).thenReturn(targetLocator);
    PowerMockito.mockStatic(WebUIDriver.class);
    when(WebUIDriver.getCurrentWebUiDriverName()).thenReturn("main");
    when(WebUIDriver.getWebDriver(anyBoolean(), eq(BrowserType.FIREFOX), eq("main"), isNull())).thenReturn(eventDriver);
    when(WebUIDriver.getWebDriver(anyBoolean())).thenReturn(eventDriver);
    when(eventDriver.executeScript("if (document.readyState === \"complete\") { return \"ok\"; }")).thenReturn("ok");
    when(eventDriver.getBrowserInfo()).thenReturn(new BrowserInfo(BrowserType.FIREFOX, "78.0"));
    when(screenshotUtil.capture(any(SnapshotTarget.class), ArgumentMatchers.<Class<ScreenShot>>any())).thenReturn(screenshot);
    when(screenshotUtil.capture(any(SnapshotTarget.class), ArgumentMatchers.<Class<ScreenShot>>any(), anyInt())).thenReturn(screenshot);
    when(screenshot.getHtmlSourcePath()).thenReturn("foo");
    when(screenshot.getImagePath()).thenReturn("image");
    page = new PageForActions();
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) SnapshotTarget(com.seleniumtests.driver.screenshots.SnapshotTarget) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) Dimension(org.openqa.selenium.Dimension) Point(org.openqa.selenium.Point) PageForActions(com.seleniumtests.ut.core.runner.cucumber.PageForActions) BeforeMethod(org.testng.annotations.BeforeMethod)

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