Search in sources :

Example 16 with CustomEventFiringWebDriver

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

the class TestWebUIDriver method testDriverCreationWithBrowserMob.

@Test(groups = { "ut" })
public void testDriverCreationWithBrowserMob() {
    SeleniumTestsContextManager.getThreadContext().setCaptureNetwork(true);
    SeleniumTestsContextManager.getThreadContext().setBrowser("htmlunit");
    WebDriver driver = WebUIDriver.getWebDriver(true);
    Assert.assertTrue(driver instanceof CustomEventFiringWebDriver);
    WebUIDriver uiDriver = WebUIDriver.getWebUIDriver(false);
    Assert.assertNotNull(uiDriver.getConfig().getBrowserMobProxy());
}
Also used : NLWebDriver(com.neotys.selenium.proxies.NLWebDriver) WebDriver(org.openqa.selenium.WebDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) WebUIDriver(com.seleniumtests.driver.WebUIDriver) 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)

Example 17 with CustomEventFiringWebDriver

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

the class TestWebUIDriver method testDriverCreation.

/**
 * When driver is created, no Neoload driver is instanciated if neoload parameters are not set
 */
@Test(groups = { "ut" })
public void testDriverCreation() {
    SeleniumTestsContextManager.getThreadContext().setBrowser("htmlunit");
    WebDriver driver = WebUIDriver.getWebDriver(true);
    Assert.assertTrue(driver instanceof CustomEventFiringWebDriver);
    Assert.assertNull(((CustomEventFiringWebDriver) driver).getNeoloadDriver());
    Capabilities caps = ((CustomEventFiringWebDriver) driver).getInternalCapabilities();
    Assert.assertNotNull(caps.getCapability(DriverUsage.START_TIME));
    Assert.assertNotNull(caps.getCapability(DriverUsage.STARTUP_DURATION));
}
Also used : NLWebDriver(com.neotys.selenium.proxies.NLWebDriver) WebDriver(org.openqa.selenium.WebDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) Capabilities(org.openqa.selenium.Capabilities) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 18 with CustomEventFiringWebDriver

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

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

the class HtmlElement method enterFrame.

/**
 * Method for going into the right frame before doing anything else this method
 * should be called each time we need to get an element Therefore, it's used
 * inside findElement() method
 */
private void enterFrame() {
    List<FrameElement> frameTree = new ArrayList<>();
    FrameElement frame = getFrameElement();
    while (frame != null) {
        frameTree.add(0, frame);
        frame = frame.getFrameElement();
    }
    for (FrameElement frameEl : frameTree) {
        Integer idx = frameEl.getElementIndex() == null ? 0 : frameEl.getElementIndex();
        WebElement frameWebElement;
        try {
            frameWebElement = getDriver().findElements(frameEl.getBy()).get(idx);
        } catch (IndexOutOfBoundsException e) {
            throw new NoSuchFrameException(String.format("Frame %s with index %d has not been found", frameEl, idx));
        }
        ((CustomEventFiringWebDriver) getDriver()).scrollToElement(frameWebElement, -20);
        getDriver().switchTo().frame(frameWebElement);
    }
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) ArrayList(java.util.ArrayList) NoSuchFrameException(org.openqa.selenium.NoSuchFrameException) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement)

Example 20 with CustomEventFiringWebDriver

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

the class PictureElement method isDriverCreated.

private WebUIDriver isDriverCreated() {
    WebUIDriver uiDriver = WebUIDriver.getWebUIDriver(false);
    if (uiDriver == null) {
        throw new ScenarioException("Driver has not already been created");
    }
    CustomEventFiringWebDriver driver = (CustomEventFiringWebDriver) uiDriver.getDriver();
    if (driver == null) {
        throw new ScenarioException("Driver has not already been created");
    }
    return uiDriver;
}
Also used : WebUIDriver(com.seleniumtests.driver.WebUIDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) ScenarioException(com.seleniumtests.customexception.ScenarioException)

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