use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class AndroidUtils method scroll.
/**
* Scrolls into view in a container specified by it's instance (index)
* @param scrollToEle - has to be id, text, contentDesc or className
* @param scrollableContainer - ExtendedWebElement type
* @param containerSelectorType - has to be id, text, textContains, textStartsWith, Description, DescriptionContains
* or className
* @param containerInstance - has to an instance number of desired container
* @param eleSelectorType - has to be id, text, textContains, textStartsWith, Description, DescriptionContains
* or className
* @return ExtendedWebElement
* <p>
* example of usage:
* ExtendedWebElement res = AndroidUtils.scroll("News", newsListContainer, AndroidUtils.SelectorType.CLASS_NAME, 1,
* AndroidUtils.SelectorType.TEXT);
*/
public static ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer, SelectorType containerSelectorType, int containerInstance, SelectorType eleSelectorType) {
ExtendedWebElement el = null;
long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {
try {
WebElement ele = DriverPool.getDriver().findElement(MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ".instance(" + containerInstance + "))" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ")"));
if (ele.isDisplayed()) {
LOGGER.info("Element found!!!");
el = new ExtendedWebElement(ele, scrollToEle, DriverPool.getDriver());
break;
}
} catch (NoSuchElementException noSuchElement) {
LOGGER.error(String.format("Element %s:%s was NOT found.", eleSelectorType, scrollToEle), noSuchElement);
}
for (int j = 0; j < i; j++) {
checkTimeout(startTime);
MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ".instance(" + containerInstance + ")).scrollForward()");
LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");
}
}
return el;
}
use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class AndroidUtils method scroll.
/**
* Scrolls into view in specified container
* @param scrollToEle - has to be id, text, contentDesc or className
* @param scrollableContainer - ExtendedWebElement type
* @param containerSelectorType - container Selector type: has to be id, text, textContains, textStartsWith, Description, DescriptionContains
* or className
* @param eleSelectorType - scrollToEle Selector type: has to be id, text, textContains, textStartsWith, Description, DescriptionContains
* or className
* @return ExtendedWebElement
* <p>
* example of usage:
* ExtendedWebElement res = AndroidUtils.scroll("News", newsListContainer, AndroidUtils.SelectorType.CLASS_NAME,
* AndroidUtils.SelectorType.TEXT);
*/
public static ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer, SelectorType containerSelectorType, SelectorType eleSelectorType) {
ExtendedWebElement el = null;
long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {
try {
WebElement ele = DriverPool.getDriver().findElement(MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ")" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ")"));
if (ele.isDisplayed()) {
LOGGER.info("Element found!!!");
el = new ExtendedWebElement(ele, scrollToEle, DriverPool.getDriver());
break;
}
} catch (NoSuchElementException noSuchElement) {
LOGGER.error(String.format("Element %s:%s was NOT found.", eleSelectorType, scrollToEle), noSuchElement);
}
for (int j = 0; j < i; j++) {
checkTimeout(startTime);
MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ").scrollForward()");
LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");
}
}
return el;
}
use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class DriverHelper method findExtendedWebElement.
/**
* Find Extended Web Element on page using By.
*
* @param by
* Selenium By locator
* @param name
* Element name
* @param timeout
* Timeout to find
* @return ExtendedWebElement if exists otherwise null.
*/
public ExtendedWebElement findExtendedWebElement(final By by, String name, long timeout) {
ExtendedWebElement element;
final WebDriver drv = getDriver();
wait = new WebDriverWait(drv, timeout, RETRY_TIME);
try {
setImplicitTimeout(0);
wait.until((Function<WebDriver, Object>) dr -> !drv.findElements(by).isEmpty());
element = new ExtendedWebElement(driver.findElement(by), name, by, driver);
Messager.ELEMENT_FOUND.info(name);
} catch (Exception e) {
element = null;
Messager.ELEMENT_NOT_FOUND.error(name);
throw new RuntimeException(e);
} finally {
setImplicitTimeout(IMPLICIT_TIMEOUT);
}
return element;
}
use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class LocatingElementListHandler method invoke.
public Object invoke(Object object, Method method, Object[] objects) throws Throwable {
List<WebElement> elements = locator.findElements();
List<ExtendedWebElement> extendedWebElements = null;
if (elements != null) {
extendedWebElements = new ArrayList<ExtendedWebElement>();
for (WebElement element : elements) {
extendedWebElements.add(new ExtendedWebElement(element, name, by, webDriver));
}
}
try {
return method.invoke(extendedWebElements, objects);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class IAndroidUtils method scroll.
/**
* Scrolls into view in specified container
*
* @param scrollToEle
* - has to be id, text, contentDesc or className
* @param scrollableContainer
* - ExtendedWebElement type
* @param containerSelectorType
* - has to be id, text, textContains, textStartsWith, Description,
* DescriptionContains or className
* @param containerInstance
* - has to an instance number of desired container
* @param eleSelectorType
* - has to be id, text, textContains, textStartsWith, Description,
* DescriptionContains or className
* @param eleSelectorInstance
* - has to an instance number of desired container
* @return ExtendedWebElement
* <p>
* example of usage: ExtendedWebElement res =
* AndroidUtils.scroll("News", newsListContainer,
* AndroidUtils.SelectorType.CLASS_NAME, 1,
* AndroidUtils.SelectorType.TEXT, 2);
*/
public default ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer, SelectorType containerSelectorType, int containerInstance, SelectorType eleSelectorType, int eleSelectorInstance) {
ExtendedWebElement extendedWebElement = null;
long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
// TODO: support multi threaded WebDriver's removing DriverPool usage
WebDriver drv = castDriver();
// workaorund for appium issue: https://github.com/appium/appium/issues/10159
if (scrollToEle.contains(",")) {
scrollToEle = StringUtils.join(StringUtils.split(scrollToEle, ","), ",", 0, 2);
if (eleSelectorType.equals(SelectorType.TEXT)) {
eleSelectorType = SelectorType.TEXT_CONTAINS;
}
}
for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {
try {
By scrollBy = MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ".instance(" + containerInstance + "))" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ".instance(" + eleSelectorInstance + "))");
WebElement ele = drv.findElement(scrollBy);
if (ele.isDisplayed()) {
UTILS_LOGGER.info("Element found!!!");
extendedWebElement = new ExtendedWebElement(scrollBy, scrollToEle, drv);
break;
}
} catch (NoSuchElementException noSuchElement) {
UTILS_LOGGER.error(String.format("Element %s:%s was NOT found.", eleSelectorType, scrollToEle), noSuchElement);
}
for (int j = 0; j < i; j++) {
checkTimeout(startTime);
MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ".instance(" + containerInstance + ")).scrollForward()");
UTILS_LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");
}
}
return extendedWebElement;
}
Aggregations