Search in sources :

Example 6 with FrameElement

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

the class TestFrameElement method testImageElementInsideFrame.

@Test(groups = { "ut" })
public void testImageElementInsideFrame() throws Exception {
    FrameElement frame = new FrameElement("", By.id("frameId"));
    ImageElement el = new ImageElement("", By.id("el"), frame);
    el.getWidth();
    verify(locator).frame(any(WebElement.class));
    verify(locator).defaultContent();
}
Also used : ImageElement(com.seleniumtests.uipage.htmlelements.ImageElement) FrameElement(com.seleniumtests.uipage.htmlelements.FrameElement) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 7 with FrameElement

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

the class TestFrameElement method testUseElementInside2Frames.

@Test(groups = { "ut" })
public void testUseElementInside2Frames() throws Exception {
    FrameElement frame = new FrameElement("", By.id("frameId"));
    FrameElement frame2 = new FrameElement("", By.id("frameId2"), frame);
    HtmlElement el = new HtmlElement("", By.id("el"), frame2);
    el.click();
    // switch to each frame
    verify(locator, times(2)).frame(any(WebElement.class));
    verify(locator).defaultContent();
}
Also used : HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) FrameElement(com.seleniumtests.uipage.htmlelements.FrameElement) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 8 with FrameElement

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

the class SeleniumNativeActions method getFrameElement.

/**
 * Returns a FrameElement based on the object passed in argument
 * @param frameArg
 * @return
 * @throws SecurityException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 */
private FrameElement getFrameElement(Object frameArg) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    FrameElement frameEl = null;
    if (frameArg instanceof HtmlElement) {
        frameEl = new FrameElement("", ((HtmlElement) frameArg).getBy());
    } else if (frameArg instanceof WebElement && frameArg.getClass().getName().contains("Proxy")) {
        LocatingElementHandler locatingEh = (LocatingElementHandler) Proxy.getInvocationHandler(frameArg);
        Field locatorField = LocatingElementHandler.class.getDeclaredField("locator");
        locatorField.setAccessible(true);
        DefaultElementLocator locator = ((DefaultElementLocator) locatorField.get(locatingEh));
        Field byField = DefaultElementLocator.class.getDeclaredField("by");
        byField.setAccessible(true);
        frameEl = new FrameElement("", (By) byField.get(locator));
    } else if (frameArg instanceof By) {
        frameEl = new FrameElement("", (By) frameArg);
    } else if (frameArg instanceof Integer) {
        frameEl = new FrameElement("", By.tagName("iframe"), (Integer) frameArg);
    } else if (frameArg instanceof String) {
        String name = ((String) frameArg).replaceAll("(['\"\\\\#.:;,!?+<>=~*^$|%&@`{}\\-/\\[\\]\\(\\)])", "\\\\$1");
        frameEl = new FrameElement("", By.cssSelector("frame[name='" + name + "'],iframe[name='" + name + "'],frame#" + name + ",iframe#" + name));
    }
    return frameEl;
}
Also used : Field(java.lang.reflect.Field) DefaultElementLocator(org.openqa.selenium.support.pagefactory.DefaultElementLocator) LocatingElementHandler(org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler) HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) By(org.openqa.selenium.By) FrameElement(com.seleniumtests.uipage.htmlelements.FrameElement) WebElement(org.openqa.selenium.WebElement)

Example 9 with FrameElement

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

the class SeleniumNativeActions method recordSwitchToFramCalls.

/**
 * Method interceptFindHtmlElement creates an HtmlElement from findElement, but does not handle frames.
 * Here, we record all switchTo().frame(WebElement) call to create a FrameElement chain
 * @param joinPoint
 * @return
 * @throws Throwable
 */
@Around(// caller is a PageObject
"this(com.seleniumtests.uipage.PageObject) && " + "(call(public * org.openqa.selenium.WebDriver.TargetLocator+.frame (..))" + ")")
public Object recordSwitchToFramCalls(ProceedingJoinPoint joinPoint) throws Throwable {
    if (Boolean.TRUE.equals(doOverride())) {
        Object frameArg = joinPoint.getArgs()[0];
        FrameElement frameEl = getFrameElement(frameArg);
        if (frameEl == null) {
            return joinPoint.proceed(joinPoint.getArgs());
        }
        if (getCurrentFrame() == null) {
            setCurrentFrame(frameEl);
        } else {
            frameEl.setFrameElement(getCurrentFrame());
            setCurrentFrame(frameEl);
        }
        return null;
    } else {
        return joinPoint.proceed(joinPoint.getArgs());
    }
}
Also used : FrameElement(com.seleniumtests.uipage.htmlelements.FrameElement) Around(org.aspectj.lang.annotation.Around)

Example 10 with FrameElement

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

the class TestFrameElement method testTableInsideFrame.

@Test(groups = { "ut" })
public void testTableInsideFrame() throws Exception {
    FrameElement frame = new FrameElement("", By.id("frameId"));
    Table el = new Table("", By.id("el"), frame);
    el.getColumns();
    // issue #320: as we return HtmlElement instead of WebElement, we need to search for root element (the table) each time we search for columns and cells
    verify(locator, times(3)).frame(any(WebElement.class));
    verify(locator, times(3)).defaultContent();
}
Also used : Table(com.seleniumtests.uipage.htmlelements.Table) FrameElement(com.seleniumtests.uipage.htmlelements.FrameElement) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

FrameElement (com.seleniumtests.uipage.htmlelements.FrameElement)19 MockitoTest (com.seleniumtests.MockitoTest)16 WebElement (org.openqa.selenium.WebElement)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 Test (org.testng.annotations.Test)16 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)15 HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)8 LinkElement (com.seleniumtests.uipage.htmlelements.LinkElement)2 RadioButtonElement (com.seleniumtests.uipage.htmlelements.RadioButtonElement)2 Around (org.aspectj.lang.annotation.Around)2 By (org.openqa.selenium.By)2 WebDriverException (org.openqa.selenium.WebDriverException)2 SeleniumTestsContextManager (com.seleniumtests.core.SeleniumTestsContextManager)1 TestStepManager (com.seleniumtests.core.TestStepManager)1 ScenarioException (com.seleniumtests.customexception.ScenarioException)1 BrowserType (com.seleniumtests.driver.BrowserType)1 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)1 DriverConfig (com.seleniumtests.driver.DriverConfig)1 DriverExceptionListener (com.seleniumtests.driver.DriverExceptionListener)1 TestType (com.seleniumtests.driver.TestType)1