use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class NotificationPage method clearNotifications.
/*
* public MessagesPage tapLastItemsContent(int num) {
* tapElement(lastItemsContainer.get(num));
* return new MessagesPage(driver);
* }
*
* public MessagesPage tapItemTitle(int num) {
* tapElement(lastItemsContent.get(num));
* return new MessagesPage(driver);
* }
*/
/**
* clearNotifications
*/
public void clearNotifications() {
if (!isOpened(1)) {
notificationService.expandStatusBar();
}
if (dismissBtn.isElementPresent(SHORT_TIMEOUT)) {
LOGGER.info("Dismiss all notifications btn is present.");
dismissBtn.click();
} else {
LOGGER.info("Dismiss all notifications btn isn't present. Attempt to clear all notifications manually");
LOGGER.debug("Notifications page source: ".concat(getDriver().getPageSource()));
int x1, x2, y1, y2;
Point point;
Dimension dim;
List<ExtendedWebElement> notificationList;
if (notifications.size() > 0) {
notificationList = notifications;
} else {
notificationList = notificationsOtherDevices;
}
LOGGER.info("Visible Notifications size:" + notificationList.size());
for (ExtendedWebElement notification : notificationList) {
point = notification.getElement().getLocation();
dim = notification.getElement().getSize();
x1 = point.x + dim.width / 6;
x2 = point.x + dim.width * 5 / 6;
y1 = y2 = point.y + dim.height / 2;
MobileUtils.swipe(x1, y1, x2, y2, SWIPE_DURATION);
}
}
}
use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class ScreenElementExtractor method getElementsByCoordinates.
@Override
public ExtendedWebElement getElementsByCoordinates(int x, int y) {
String elementName = String.format("Element founded by x:%d - y:%d", x, y);
WebDriver driver = getDriver();
List<WebElement> elements = getEndLevelElements(driver);
List<WebElement> result = new ArrayList<WebElement>();
Rectangle rect;
for (WebElement webElement : elements) {
try {
rect = getRect(webElement);
} catch (Exception e) {
continue;
}
if (isInside(rect, x, y)) {
result.add(webElement);
}
}
return generateExtenedElement(result, elementName);
}
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
* - 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 default ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer, SelectorType containerSelectorType, SelectorType eleSelectorType) {
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) + ")" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ")");
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) + ").scrollForward()");
UTILS_LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");
}
}
return extendedWebElement;
}
use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class IAndroidUtils method toggleAppNotificationsFromDeviceSettings.
/**
* Toggles a specified app's ability to recieve Push Notifications on the system level
*
* @param appName - The app name as it appears within device System Settings
* @param setValue - The value you wish to set the toggle to
*/
default void toggleAppNotificationsFromDeviceSettings(String appName, boolean setValue) {
openAppMenuFromDeviceSettings(appName);
WebDriver driver = getDriver();
ExtendedWebElement element = new ExtendedWebElement(By.xpath("//*[contains(@text, 'Notifications') or contains(@text, 'notifications')]"), "notifications", driver);
element.click();
element = new ExtendedWebElement(By.xpath("//*[@resource-id='com.android.settings:id/switch_text']/following-sibling::android.widget.Switch"), "toggle", driver);
if (Boolean.valueOf(element.getAttribute("checked")) != setValue) {
element.click();
}
}
use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class IAndroidUtils method openAppMenuFromDeviceSettings.
/**
* Method enters an App's menu within device System Settings
*
* @param appName - Name of the app as it appears in the device's Apps list (Language specific)
*/
default void openAppMenuFromDeviceSettings(String appName) {
AndroidService androidService = AndroidService.getInstance();
androidService.executeAdbCommand("shell am start -a android.settings.APPLICATION_SETTINGS");
ExtendedWebElement appItem = new ExtendedWebElement(By.xpath(String.format("//*[contains(@text, '%s')]", appName)), "notifications", getDriver());
swipe(appItem);
appItem.click();
}
Aggregations