Best Carina code snippet using com.qaprosoft.carina.core.foundation.utils.mobile.IMobileUtils.swipeInContainer
Source:IMobileUtils.java
...333 oppositeDirection = Direction.UP;334 bothDirections = true;335 break;336 default:337 throw new RuntimeException("Unsupported direction for swipeInContainerTillElement: " + direction);338 }339 int currentCount = count;340 while (!isVisible && currentCount-- > 0) {341 UTILS_LOGGER.debug("Element not present! Swipe " + direction + " will be executed to element: " + element.getNameWithLocator().toString());342 swipeInContainer(container, direction, duration);343 UTILS_LOGGER.info("Swipe was executed. Attempts remain: " + currentCount);344 isVisible = element.isVisible(1);345 }346 currentCount = count;347 while (bothDirections && !isVisible && currentCount-- > 0) {348 UTILS_LOGGER.debug(349 "Element not present! Swipe " + oppositeDirection + " will be executed to element: " + element.getNameWithLocator().toString());350 swipeInContainer(container, oppositeDirection, duration);351 UTILS_LOGGER.info("Swipe was executed. Attempts remain: " + currentCount);352 isVisible = element.isVisible(1);353 }354 UTILS_LOGGER.info("Result: " + isVisible);355 return isVisible;356 }357 /**358 * Swipe by coordinates using TouchAction (platform independent)359 *360 * @param startx int361 * @param starty int362 * @param endx int363 * @param endy int364 * @param duration int Millis365 */366 @SuppressWarnings("rawtypes")367 default public void swipe(int startx, int starty, int endx, int endy, int duration) {368 UTILS_LOGGER.debug("Starting swipe...");369 WebDriver drv = castDriver();370 UTILS_LOGGER.debug("Getting driver dimension size...");371 Dimension scrSize = drv.manage().window().getSize();372 UTILS_LOGGER.debug("Finished driver dimension size...");373 // explicitly limit range of coordinates374 if (endx >= scrSize.width) {375 UTILS_LOGGER.warn("endx coordinate is bigger then device width! It will be limited!");376 endx = scrSize.width - 1;377 } else {378 endx = Math.max(1, endx);379 }380 if (endy >= scrSize.height) {381 UTILS_LOGGER.warn("endy coordinate is bigger then device height! It will be limited!");382 endy = scrSize.height - 1;383 } else {384 endy = Math.max(1, endy);385 }386 UTILS_LOGGER.debug("startx: " + startx + "; starty: " + starty + "; endx: " + endx + "; endy: " + endy387 + "; duration: " + duration);388 PointOption<?> startPoint = PointOption.point(startx, starty);389 PointOption<?> endPoint = PointOption.point(endx, endy);390 WaitOptions waitOptions = WaitOptions.waitOptions(Duration.ofMillis(duration));391 new TouchAction((MobileDriver<?>) drv).press(startPoint).waitAction(waitOptions).moveTo(endPoint).release()392 .perform();393 UTILS_LOGGER.debug("Finished swipe...");394 }395 /**396 * swipeInContainer397 *398 * @param container ExtendedWebElement399 * @param direction Direction400 * @param duration int401 * @return boolean402 */403 default public boolean swipeInContainer(ExtendedWebElement container, Direction direction, int duration) {404 return swipeInContainer(container, direction, DEFAULT_MIN_SWIPE_COUNT, duration);405 }406 /**407 * swipeInContainer408 *409 * @param container ExtendedWebElement410 * @param direction Direction411 * @param count int412 * @param duration int413 * @return boolean414 */415 default public boolean swipeInContainer(ExtendedWebElement container, Direction direction, int count, int duration) {416 int startx = 0;417 int starty = 0;418 int endx = 0;419 int endy = 0;420 Point elementLocation = null;421 Dimension elementDimensions = null;422 if (container == null) {423 // whole screen/driver is a container!424 WebDriver driver = castDriver();425 elementLocation = new Point(0, 0); // initial left corner for that case426 elementDimensions = driver.manage().window().getSize();427 } else {428 if (container.isElementNotPresent(5)) {429 Assert.fail("Cannot swipe! Impossible to find element " + container.getName());430 }431 elementLocation = container.getLocation();432 elementDimensions = container.getSize();433 }434 double minCoefficient = 0.3;435 double maxCoefficient = 0.6;436 // calculate default coefficient based on OS type437 String os = IDriverPool.getDefaultDevice().getOs();438 if (os.equalsIgnoreCase(SpecialKeywords.ANDROID)) {439 minCoefficient = 0.25;440 maxCoefficient = 0.5;441 } else if (os.equalsIgnoreCase(SpecialKeywords.IOS) || os.equalsIgnoreCase(SpecialKeywords.MAC) || os.equalsIgnoreCase(SpecialKeywords.TVOS)) {442 minCoefficient = 0.25;443 maxCoefficient = 0.8;444 }445 switch (direction) {446 case LEFT:447 starty = endy = elementLocation.getY() + Math.round(elementDimensions.getHeight() / 2f);448 startx = (int) (elementLocation.getX() + Math.round(maxCoefficient * elementDimensions.getWidth()));449 endx = (int) (elementLocation.getX() + Math.round(minCoefficient * elementDimensions.getWidth()));450 break;451 case RIGHT:452 starty = endy = elementLocation.getY() + Math.round(elementDimensions.getHeight() / 2f);453 startx = (int) (elementLocation.getX() + Math.round(minCoefficient * elementDimensions.getWidth()));454 endx = (int) (elementLocation.getX() + Math.round(maxCoefficient * elementDimensions.getWidth()));455 break;456 case UP:457 startx = endx = elementLocation.getX() + Math.round(elementDimensions.getWidth() / 2f);458 starty = (int) (elementLocation.getY() + Math.round(maxCoefficient * elementDimensions.getHeight()));459 endy = (int) (elementLocation.getY() + Math.round(minCoefficient * elementDimensions.getHeight()));460 break;461 case DOWN:462 startx = endx = elementLocation.getX() + Math.round(elementDimensions.getWidth() / 2f);463 starty = (int) (elementLocation.getY() + Math.round(minCoefficient * elementDimensions.getHeight()));464 endy = (int) (elementLocation.getY() + Math.round(maxCoefficient * elementDimensions.getHeight()));465 break;466 default:467 throw new RuntimeException("Unsupported direction: " + direction);468 }469 UTILS_LOGGER.debug(String.format("Swipe from (X = %d; Y = %d) to (X = %d; Y = %d)", startx, starty, endx, endy));470 try {471 for (int i = 0; i < count; ++i) {472 swipe(startx, starty, endx, endy, duration);473 }474 return true;475 } catch (Exception e) {476 UTILS_LOGGER.error(String.format("Error during Swipe from (X = %d; Y = %d) to (X = %d; Y = %d): %s", startx, starty, endx, endy, e));477 }478 return false;479 }480 /**481 * Swipe up several times482 *483 * @param times int484 * @param duration int485 */486 default public void swipeUp(final int times, final int duration) {487 for (int i = 0; i < times; i++) {488 swipeUp(duration);489 }490 }491 /**492 * Swipe up493 *494 * @param duration int495 */496 default public void swipeUp(final int duration) {497 UTILS_LOGGER.info("Swipe up will be executed.");498 swipeInContainer(null, Direction.UP, duration);499 }500 /**501 * Swipe down several times502 *503 * @param times int504 * @param duration int505 */506 default public void swipeDown(final int times, final int duration) {507 for (int i = 0; i < times; i++) {508 swipeDown(duration);509 }510 }511 /**512 * Swipe down513 *514 * @param duration int515 */516 default public void swipeDown(final int duration) {517 UTILS_LOGGER.info("Swipe down will be executed.");518 swipeInContainer(null, Direction.DOWN, duration);519 }520 /**521 * Swipe left several times522 *523 * @param times int524 * @param duration int525 */526 default public void swipeLeft(final int times, final int duration) {527 for (int i = 0; i < times; i++) {528 swipeLeft(duration);529 }530 }531 /**532 * Swipe left533 *534 * @param duration int535 */536 default public void swipeLeft(final int duration) {537 UTILS_LOGGER.info("Swipe left will be executed.");538 swipeLeft(null, duration);539 }540 /**541 * Swipe left in container542 *543 * @param container544 * ExtendedWebElement545 * @param duration546 * int547 */548 default public void swipeLeft(ExtendedWebElement container, final int duration) {549 UTILS_LOGGER.info("Swipe left will be executed.");550 swipeInContainer(container, Direction.LEFT, duration);551 }552 /**553 * Swipe right several times554 *555 * @param times int556 * @param duration int557 */558 default public void swipeRight(final int times, final int duration) {559 for (int i = 0; i < times; i++) {560 swipeRight(duration);561 }562 }563 /**564 * Swipe right565 *566 * @param duration int567 */568 default public void swipeRight(final int duration) {569 UTILS_LOGGER.info("Swipe right will be executed.");570 swipeRight(null, duration);571 }572 /**573 * Swipe right in container574 *575 * @param container576 * ExtendedWebElement577 * @param duration578 * int579 */580 default public void swipeRight(ExtendedWebElement container, final int duration) {581 UTILS_LOGGER.info("Swipe right will be executed.");582 swipeInContainer(container, Direction.RIGHT, duration);583 }584 /**585 * Set Android Device Default TimeZone And Language based on config or to GMT and En586 * Without restoring actual focused apk.587 */588 default public void setDeviceDefaultTimeZoneAndLanguage() {589 setDeviceDefaultTimeZoneAndLanguage(false);590 }591 /**592 * set Android Device Default TimeZone And Language based on config or to GMT and En593 *594 * @param returnAppFocus - if true store actual Focused apk and activity, than restore after setting Timezone and Language.595 */596 default public void setDeviceDefaultTimeZoneAndLanguage(boolean returnAppFocus) {...
swipeInContainer
Using AI Code Generation
1import com.qaprosoft.carina.core.foundation.utils.mobile.IMobileUtils;2import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement;3import io.appium.java_client.TouchAction;4import org.openqa.selenium.Dimension;5import org.openqa.selenium.Point;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8public class SwipeInContainerTest extends AbstractTest {9 public void testSwipeInContainerTest() {10 WebDriver driver = getDriver();
swipeInContainer
Using AI Code Generation
1import com.qaprosoft.carina.core.foundation.utils.mobile.IMobileUtils;2public class SwipeInContainerTest extends AbstractTest {3 public void testSwipeInContainer() {4 IMobileUtils.swipeInContainer(0.5, 0.8, 0.5, 0.2);5 }6}7import com.qaprosoft.carina.core.foundation.utils.mobile.IMobileUtils;8public class SwipeInContainerTest extends AbstractTest {9 public void testSwipeInContainer() {10 IMobileUtils.swipeInContainer(0.5, 0.8, 0.5, 0.2);11 }12}13import com.qaprosoft.carina.core.foundation.utils.mobile.IMobileUtils;14public class SwipeInContainerTest extends AbstractTest {15 public void testSwipeInContainer() {16 IMobileUtils.swipeInContainer(0.5, 0.8, 0.5, 0.2);17 }18}19import com.qaprosoft.carina.core.foundation.utils.mobile.IMobileUtils;20public class SwipeInContainerTest extends AbstractTest {21 public void testSwipeInContainer() {22 IMobileUtils.swipeInContainer(0.5, 0.8, 0.5, 0.2);23 }24}25import com.qaprosoft.carina.core.foundation.utils.mobile.IMobileUtils;26public class SwipeInContainerTest extends AbstractTest {27 public void testSwipeInContainer() {28 IMobileUtils.swipeInContainer(0.5, 0.8, 0.5, 0.2);29 }30}31import com.qaprosoft.carina.core.foundation.utils.mobile.IMobileUtils;32public class SwipeInContainerTest extends AbstractTest {33 public void testSwipeInContainer() {34 IMobileUtils.swipeInContainer(0.5, 0.8, 0.5, 0.2);35 }36}37import com.qaprosoft.carina.core.foundation.utils.mobile.IMobileUtils;38public class SwipeInContainerTest extends AbstractTest {39 public void testSwipeInContainer() {40 IMobileUtils.swipeInContainer(0.5, 0.8, 0.5
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!!