Best Carina code snippet using com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils.checkTimeout
Source:IAndroidUtils.java
...341 UTILS_LOGGER.error(String.format("%s %s:%s", SpecialKeywords.NO_SUCH_ELEMENT_ERROR, eleSelectorType, scrollToEle),342 noSuchElement);343 }344 for (int j = 0; j < i; j++) {345 checkTimeout(startTime);346 MobileBy.AndroidUIAutomator(347 "new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType)348 + ".instance(" + containerInstance + ")).scrollForward()");349 UTILS_LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");350 }351 }352 return extendedWebElement;353 }354 /**355 * Scrolls into view in specified container356 * 357 * @param scrollToEle358 * - has to be id, text, contentDesc or className359 * @param scrollableContainer360 * - ExtendedWebElement type361 * @param containerSelectorType362 * - has to be id, text, textContains, textStartsWith, Description,363 * DescriptionContains or className364 * @param containerInstance365 * - has to an instance number of desired container366 * @param eleSelectorType367 * - has to be id, text, textContains, textStartsWith, Description,368 * DescriptionContains or className369 * @param eleSelectorInstance370 * - has to an instance number of desired container371 * @return ExtendedWebElement372 * <p>373 * example of usage: ExtendedWebElement res =374 * AndroidUtils.scroll("News", newsListContainer,375 * AndroidUtils.SelectorType.CLASS_NAME, 1,376 * AndroidUtils.SelectorType.TEXT, 2);377 **/378 default public ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer,379 SelectorType containerSelectorType, int containerInstance, SelectorType eleSelectorType,380 int eleSelectorInstance) {381 ExtendedWebElement extendedWebElement = null;382 long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());383 // TODO: support multi threaded WebDriver's removing DriverPool usage384 WebDriver drv = castDriver();385 // workaorund for appium issue: https://github.com/appium/appium/issues/10159386 if (scrollToEle.contains(",")) {387 scrollToEle = StringUtils.join(StringUtils.split(scrollToEle, ","), ",", 0, 2);388 if (eleSelectorType.equals(SelectorType.TEXT)) {389 eleSelectorType = SelectorType.TEXT_CONTAINS;390 }391 }392 for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {393 try {394 By scrollBy = MobileBy.AndroidUIAutomator("new UiScrollable("395 + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ".instance("396 + containerInstance + "))" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")"397 + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ".instance("398 + eleSelectorInstance + "))");399 WebElement ele = drv.findElement(scrollBy);400 if (ele.isDisplayed()) {401 UTILS_LOGGER.info("Element found!!!");402 // initializing with driver context because scrollBy consists from container and element selectors403 extendedWebElement = new ExtendedWebElement(scrollBy, scrollToEle, drv, drv);404 break;405 }406 } catch (NoSuchElementException noSuchElement) {407 UTILS_LOGGER.error(String.format("%s%s:%s", SpecialKeywords.NO_SUCH_ELEMENT_ERROR, eleSelectorType, scrollToEle),408 noSuchElement);409 }410 for (int j = 0; j < i; j++) {411 checkTimeout(startTime);412 MobileBy.AndroidUIAutomator(413 "new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType)414 + ".instance(" + containerInstance + ")).scrollForward()");415 UTILS_LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");416 }417 }418 return extendedWebElement;419 }420 /**421 * Scrolls into view in specified container422 * 423 * @param scrollToEle424 * - has to be id, text, contentDesc or className425 * @param scrollableContainer426 * - ExtendedWebElement type427 * @param containerSelectorType428 * - container Selector type: has to be id, text, textContains,429 * textStartsWith, Description, DescriptionContains or className430 * @param eleSelectorType431 * - scrollToEle Selector type: has to be id, text, textContains,432 * textStartsWith, Description, DescriptionContains or className433 * @return ExtendedWebElement434 * <p>435 * example of usage: ExtendedWebElement res =436 * AndroidUtils.scroll("News", newsListContainer,437 * AndroidUtils.SelectorType.CLASS_NAME,438 * AndroidUtils.SelectorType.TEXT);439 **/440 default public ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer,441 SelectorType containerSelectorType, SelectorType eleSelectorType) {442 ExtendedWebElement extendedWebElement = null;443 long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());444 // TODO: support multi threaded WebDriver's removing DriverPool usage445 WebDriver drv = castDriver();446 // workaorund for appium issue: https://github.com/appium/appium/issues/10159447 if (scrollToEle.contains(",")) {448 scrollToEle = StringUtils.join(StringUtils.split(scrollToEle, ","), ",", 0, 2);449 if (eleSelectorType.equals(SelectorType.TEXT)) {450 eleSelectorType = SelectorType.TEXT_CONTAINS;451 }452 }453 for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {454 try {455 By scrollBy = MobileBy.AndroidUIAutomator(456 "new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType)457 + ")" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView("458 + getScrollToElementSelector(scrollToEle, eleSelectorType) + ")");459 WebElement ele = drv.findElement(scrollBy);460 if (ele.isDisplayed()) {461 UTILS_LOGGER.info("Element found!!!");462 // initializing with driver context because scrollBy consists from container and element selectors463 extendedWebElement = new ExtendedWebElement(scrollBy, scrollToEle, drv, drv);464 break;465 }466 } catch (NoSuchElementException noSuchElement) {467 UTILS_LOGGER.error(String.format("%s%s:%s", SpecialKeywords.NO_SUCH_ELEMENT_ERROR, eleSelectorType, scrollToEle),468 noSuchElement);469 }470 for (int j = 0; j < i; j++) {471 checkTimeout(startTime);472 MobileBy.AndroidUIAutomator("new UiScrollable("473 + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ").scrollForward()");474 UTILS_LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");475 }476 }477 return extendedWebElement;478 }479 /**480 * Scrolls into view in specified container481 * 482 * @param scrollableContainer483 * - ExtendedWebElement type484 * @param containerSelectorType485 * - Selector type: has to be id, text, contentDesc or className486 * @return scrollViewContainerFinder String487 *488 **/489 default String getScrollContainerSelector(ExtendedWebElement scrollableContainer,490 SelectorType containerSelectorType) {491 UTILS_LOGGER.debug(scrollableContainer.getBy().toString());492 String scrollableContainerBy;493 String scrollViewContainerFinder = "";494 switch (containerSelectorType) {495 case TEXT:496 scrollableContainerBy = scrollableContainer.getBy().toString().replace("By.text:", "").trim();497 scrollViewContainerFinder = "new UiSelector().text(\"" + scrollableContainerBy + "\")";498 break;499 case TEXT_CONTAINS:500 scrollableContainerBy = scrollableContainer.getBy().toString().replace("By.textContains:", "").trim();501 scrollViewContainerFinder = "new UiSelector().textContains(\"" + scrollableContainerBy + "\")";502 break;503 case TEXT_STARTS_WITH:504 scrollableContainerBy = scrollableContainer.getBy().toString().replace("By.textStartsWith:", "").trim();505 scrollViewContainerFinder = "new UiSelector().textStartsWith(\"" + scrollableContainerBy + "\")";506 break;507 case ID:508 scrollableContainerBy = scrollableContainer.getBy().toString().replace("By.id:", "").trim();509 scrollViewContainerFinder = "new UiSelector().resourceId(\"" + scrollableContainerBy + "\")";510 break;511 case DESCRIPTION:512 scrollableContainerBy = scrollableContainer.getBy().toString().replace("By.description:", "").trim();513 scrollViewContainerFinder = "new UiSelector().description(\"" + scrollableContainerBy + "\")";514 break;515 case DESCRIPTION_CONTAINS:516 scrollableContainerBy = scrollableContainer.getBy().toString().replace("By.descriptionContains:", "")517 .trim();518 scrollViewContainerFinder = "new UiSelector().descriptionContains(\"" + scrollableContainerBy + "\")";519 break;520 case CLASS_NAME:521 scrollableContainerBy = scrollableContainer.getBy().toString().replace("By.className:", "").trim();522 scrollViewContainerFinder = "new UiSelector().className(\"" + scrollableContainerBy + "\")";523 break;524 default:525 UTILS_LOGGER.info("Please provide valid selectorType for element to be found...");526 break;527 }528 return scrollViewContainerFinder;529 }530 /**531 * Scrolls into view in specified container532 * 533 * @param scrollToEle534 * - String type535 * @param eleSelectorType536 * - Selector type: has to be id, text, contentDesc or className537 * @return String538 **/539 default String getScrollToElementSelector(String scrollToEle, SelectorType eleSelectorType) {540 String neededElementFinder = "";541 String scrollToEleTrimmed;542 switch (eleSelectorType) {543 case TEXT:544 neededElementFinder = "new UiSelector().text(\"" + scrollToEle + "\")";545 break;546 case TEXT_CONTAINS:547 neededElementFinder = "new UiSelector().textContains(\"" + scrollToEle + "\")";548 break;549 case TEXT_STARTS_WITH:550 neededElementFinder = "new UiSelector().textStartsWith(\"" + scrollToEle + "\")";551 break;552 case ID:553 scrollToEleTrimmed = scrollToEle.replace("By.id:", "").trim();554 neededElementFinder = "new UiSelector().resourceId(\"" + scrollToEleTrimmed + "\")";555 break;556 case DESCRIPTION:557 neededElementFinder = "new UiSelector().description(\"" + scrollToEle + "\")";558 break;559 case DESCRIPTION_CONTAINS:560 neededElementFinder = "new UiSelector().descriptionContains(\"" + scrollToEle + "\")";561 break;562 case CLASS_NAME:563 scrollToEleTrimmed = scrollToEle.replace("By.className:", "").trim();564 neededElementFinder = "new UiSelector().className(\"" + scrollToEleTrimmed + "\")";565 break;566 default:567 UTILS_LOGGER.info("Please provide valid selectorType for element to be found...");568 break;569 }570 return neededElementFinder;571 }572 /**573 * Scroll Timeout check574 * 575 * @param startTime576 * - Long initial time for timeout count down577 **/578 default public void checkTimeout(long startTime) {579 long elapsed = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) - startTime;580 if (elapsed > SCROLL_TIMEOUT) {581 throw new NoSuchElementException("Scroll timeout has been reached..");582 }583 }584 /**585 * getCurrentDeviceFocus - get actual device apk in focus.586 *587 * @return String588 */589 default public String getCurrentDeviceFocus() {590 String result = executeAdbCommand("shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'");591 return result;592 }...
checkTimeout
Using AI Code Generation
1public void checkTimeout ( long timeout , TimeUnit unit ) { 2 long timeoutInMs = unit . toMillis ( timeout ); 3 long timeoutInSec = unit . toSeconds ( timeout ); 4 if ( timeoutInMs <= 0 ) { 5 throw new IllegalArgumentException ( "Timeout value should be greater than 0!" ); 6 } 7 if ( timeoutInSec > 60 ) { 8 LOGGER . warn ( "Timeout value is greater than 60 sec! Please consider using other timeout value." ); 9 } 10 }11public void checkTimeout ( long timeout , TimeUnit unit ) { 12 long timeoutInMs = unit . toMillis ( timeout ); 13 long timeoutInSec = unit . toSeconds ( timeout ); 14 if ( timeoutInMs <= 0 ) { 15 throw new IllegalArgumentException ( "Timeout value should be greater than 0!" ); 16 } 17 if ( timeoutInSec > 60 ) { 18 LOGGER . warn ( "Timeout value is greater than 60 sec! Please consider using other timeout value." ); 19 } 20 }21public void checkTimeout ( long timeout , TimeUnit unit ) { 22 long timeoutInMs = unit . toMillis ( timeout ); 23 long timeoutInSec = unit . toSeconds ( timeout ); 24 if ( timeoutInMs <= 0 ) { 25 throw new IllegalArgumentException ( "Timeout value should be greater than 0!" ); 26 } 27 if ( timeoutInSec > 60 ) { 28 LOGGER . warn ( "Timeout value is greater than 60 sec! Please consider using other timeout value." ); 29 } 30 }31public void checkTimeout ( long timeout , TimeUnit unit ) { 32 long timeoutInMs = unit . toMillis ( timeout ); 33 long timeoutInSec = unit . toSeconds ( timeout ); 34 if ( timeoutInMs <= 0 ) { 35 throw new IllegalArgumentException ( "Timeout value should be greater than 0!" ); 36 } 37 if ( timeoutInSec > 60 ) { 38 LOGGER . warn ( "Timeout value is greater than 60 sec! Please consider using other timeout value." ); 39 } 40 }
checkTimeout
Using AI Code Generation
1public class IAndroidUtils_checkTimeout_Method extends BaseTest {2 public void testIAndroidUtils_checkTimeout_Method() {3 IAndroidUtils androidUtils = new AndroidUtils();4 androidUtils.checkTimeout("timeout");5 }6}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!