Search in sources :

Example 6 with HtmlElement

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

the class SeleniumNativeActions method interceptPageFactoryElementsLocation.

/**
 * Intercept "findElements" action done in LocatingElementListHandler class so that we can override returned element and replace it by HtmlElement
 * This helps handling PageObjectFactory method
 * @param joinPoint
 * @return
 * @throws Throwable
 */
@Around(" this(org.openqa.selenium.support.pagefactory.internal.LocatingElementListHandler) && call(public *  org.openqa.selenium.support.pagefactory.ElementLocator+.findElements (..))")
public Object interceptPageFactoryElementsLocation(ProceedingJoinPoint joinPoint) throws Throwable {
    if (doOverride()) {
        DefaultElementLocator locator = ((DefaultElementLocator) joinPoint.getTarget());
        Field byField = DefaultElementLocator.class.getDeclaredField("by");
        byField.setAccessible(true);
        return new HtmlElement("", (By) byField.get(locator), getCurrentFrame()).findElements();
    } else {
        return joinPoint.proceed(joinPoint.getArgs());
    }
}
Also used : Field(java.lang.reflect.Field) DefaultElementLocator(org.openqa.selenium.support.pagefactory.DefaultElementLocator) HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) By(org.openqa.selenium.By) Around(org.aspectj.lang.annotation.Around)

Example 7 with HtmlElement

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

the class AngularMaterialSelect method getOptions.

@Override
public List<WebElement> getOptions() {
    parentElement.findElement(locatorClickToOpen).click();
    if (locatorParentOfDropdown == null) {
        String classes = new HtmlElement("", new ByAll(By.className(CLASS_MAT_SELECT_PANEL), By.className(CLASS_MAT_SELECT_CONTENT)), frameElement).getAttribute("class");
        if (classes.contains(CLASS_MAT_SELECT_CONTENT)) {
            locatorParentOfDropdown = By.className(CLASS_MAT_SELECT_CONTENT);
        } else {
            locatorParentOfDropdown = By.className(CLASS_MAT_SELECT_PANEL);
        }
    }
    options = new HtmlElement("options", locatorParentOfDropdown, frameElement).findHtmlElements(locatorOption).stream().map(CachedHtmlElement::new).collect(Collectors.toList());
    return options;
}
Also used : ByAll(org.openqa.selenium.support.pagefactory.ByAll) CachedHtmlElement(com.seleniumtests.uipage.htmlelements.CachedHtmlElement) HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) CachedHtmlElement(com.seleniumtests.uipage.htmlelements.CachedHtmlElement)

Example 8 with HtmlElement

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

the class AngularSelect method finalizeAction.

/**
 * Finalize any action. As for these combobox, we must click on it to get option list, it's a way to close it
 * if 'locatorClickToclose' is not null, we click on it if 'locatorParentOfDropdown' is present
 * else, we send "ESC" on parent
 */
@Override
public void finalizeAction() {
    handleAlert();
    HtmlElement selectContent = new HtmlElement("options", locatorParentOfDropdown, frameElement);
    if (selectContent.isElementPresent(0)) {
        if (locatorClickToclose != null) {
            parentElement.findElement(locatorClickToclose).click();
        } else {
            parentElement.sendKeys(Keys.ESCAPE);
        }
    }
}
Also used : HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) CachedHtmlElement(com.seleniumtests.uipage.htmlelements.CachedHtmlElement)

Example 9 with HtmlElement

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

the class AngularSelect method getOptions.

/**
 * Method for getting list of options when this list is not available without clicking the list
 * It first click on element located by 'locatorClickToOpen' element
 * This should make the element located by 'locatorParentOfDropdown' available in DOM
 * => we look for all options located by 'locatorOption'
 * All these options are cached so that combobox can be closed. It will not be necessary to open it to know the value of an element.
 */
@Override
public List<WebElement> getOptions() {
    parentElement.findElement(locatorClickToOpen).click();
    HtmlElement dropdownElement = new HtmlElement("options", locatorParentOfDropdown, frameElement);
    if (debug) {
        logger.info("drop down HTML");
        logger.info(dropdownElement.getAttribute("outerHTML"));
    }
    options = dropdownElement.findHtmlElements(locatorOption).stream().map(CachedHtmlElement::new).collect(Collectors.toList());
    return options;
}
Also used : CachedHtmlElement(com.seleniumtests.uipage.htmlelements.CachedHtmlElement) HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) CachedHtmlElement(com.seleniumtests.uipage.htmlelements.CachedHtmlElement)

Example 10 with HtmlElement

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

the class TestDriver method testFindElements.

public void testFindElements() {
    // 2 elements to find
    Assert.assertEquals(new HtmlElement("", By.name("divFindName")).findElements().size(), 2);
    // 4 elements to find, one in a branch
    Assert.assertEquals(new HtmlElement("", By.className("myClass")).findElements().size(), 4);
}
Also used : HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement)

Aggregations

HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)50 WebElement (org.openqa.selenium.WebElement)24 Test (org.testng.annotations.Test)23 MockitoTest (com.seleniumtests.MockitoTest)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)12 ScenarioException (com.seleniumtests.customexception.ScenarioException)10 LinkElement (com.seleniumtests.uipage.htmlelements.LinkElement)10 CheckBoxElement (com.seleniumtests.uipage.htmlelements.CheckBoxElement)9 Element (com.seleniumtests.uipage.htmlelements.Element)9 GenericPictureElement (com.seleniumtests.uipage.htmlelements.GenericPictureElement)9 RadioButtonElement (com.seleniumtests.uipage.htmlelements.RadioButtonElement)9 TimeoutException (org.openqa.selenium.TimeoutException)9 FrameElement (com.seleniumtests.uipage.htmlelements.FrameElement)8 LocalDateTime (java.time.LocalDateTime)8 NoSuchElementException (org.openqa.selenium.NoSuchElementException)8 Date (java.util.Date)5 WebDriverException (org.openqa.selenium.WebDriverException)5 Field (java.lang.reflect.Field)4 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)3