How to use toString method of io.appium.java_client.AppiumBy class

Best io.appium code snippet using io.appium.java_client.AppiumBy.toString

TouchActions.java

Source:TouchActions.java Github

copy

Full Screen

...154 } catch (Exception e) {155 WebDriverElementActions.failAction(driver, internalElementLocator, e);156 }157 if (elementText == null || elementText.equals("")){158 elementText = internalElementLocator.toString();159 }160 WebDriverElementActions.passAction(driver, internalElementLocator, elementText.replaceAll("\n", " "), screenshot);161 } else {162 WebDriverElementActions.failAction(driver, internalElementLocator);163 }164 return this;165 }166 /**167 * Double-Taps an element on a touch-enabled screen168 *169 * @param elementLocator the locator of the webElement under test (By xpath, id,170 * selector, name ...etc)171 * @return a self-reference to be used to chain actions172 */173 public TouchActions doubleTap(By elementLocator) {174 By internalElementLocator = elementLocator;175 if (WebDriverElementActions.identifyUniqueElement(driver, internalElementLocator)) {176 // Override current locator with the aiGeneratedElementLocator177 internalElementLocator = WebDriverElementActions.updateLocatorWithAIGeneratedOne(internalElementLocator);178 String elementText = "";179 try {180 elementText = driver.findElement(internalElementLocator).getText();181 } catch (Exception e) {182 // do nothing183 }184 // takes screenshot before clicking the element out of view185 var screenshot = WebDriverElementActions.takeScreenshot(driver, internalElementLocator, "doubleTap", null, true);186 List<List<Object>> attachments = new LinkedList<>();187 attachments.add(screenshot);188 try {189 if (driver instanceof AppiumDriver appiumDriver) {190 // appium native device191 (new Actions(driver)).doubleClick(driver.findElement(internalElementLocator)).perform();192// (new TouchAction<>((appiumDriver))193// .tap(ElementOption.element(driver.findElement(internalElementLocator)))194// .tap(ElementOption.element(driver.findElement(internalElementLocator))).perform();195 } else {196 // regular touch screen device197 (new org.openqa.selenium.interactions.touch.TouchActions(driver)).doubleTap(driver.findElement(internalElementLocator)).perform();198 }199 } catch (Exception e) {200 WebDriverElementActions.failAction(driver, internalElementLocator, e);201 }202 if (elementText != null && !elementText.equals("")) {203 WebDriverElementActions.passAction(driver, internalElementLocator, elementText.replaceAll("\n", " "), screenshot);204 } else {205 WebDriverElementActions.passAction(driver, internalElementLocator, attachments);206 }207 } else {208 WebDriverElementActions.failAction(driver, internalElementLocator);209 }210 return this;211 }212 /**213 * Performs a long-tap on an element to trigger the context menu on a214 * touch-enabled screen215 *216 * @param elementLocator the locator of the webElement under test (By xpath, id,217 * selector, name ...etc)218 * @return a self-reference to be used to chain actions219 */220 public TouchActions longTap(By elementLocator) {221 By internalElementLocator = elementLocator;222 if (WebDriverElementActions.identifyUniqueElement(driver, internalElementLocator)) {223 // Override current locator with the aiGeneratedElementLocator224 internalElementLocator = WebDriverElementActions.updateLocatorWithAIGeneratedOne(internalElementLocator);225 String elementText = "";226 try {227 elementText = driver.findElement(internalElementLocator).getText();228 } catch (Exception e) {229 // do nothing230 }231 // takes screenshot before clicking the element out of view232 List<Object> screenshot = WebDriverElementActions.takeScreenshot(driver, internalElementLocator, "longPress", null, true);233 List<List<Object>> attachments = new LinkedList<>();234 attachments.add(screenshot);235 try {236 if (driver instanceof AppiumDriver appiumDriver) {237 // appium native device238 new Actions(appiumDriver).clickAndHold(driver.findElement(internalElementLocator)).perform();239 } else {240 // regular touch screen device241 (new org.openqa.selenium.interactions.touch.TouchActions(driver)).longPress(driver.findElement(internalElementLocator)).perform();242 }243 } catch (Exception e) {244 WebDriverElementActions.failAction(driver, internalElementLocator, e);245 }246 if (elementText != null && !elementText.equals("")) {247 WebDriverElementActions.passAction(driver, internalElementLocator, elementText.replaceAll("\n", " "), screenshot);248 } else {249 WebDriverElementActions.passAction(driver, internalElementLocator, attachments);250 }251 } else {252 WebDriverElementActions.failAction(driver, internalElementLocator);253 }254 return this;255 }256 257 /**258 * Send the currently active app to the background, and return after a certain number of seconds.259 * 260 * @param secondsToSpendInTheBackground number of seconds before returning back to the app261 * @return a self-reference to be used to chain actions262 */263 public TouchActions sendAppToBackground(int secondsToSpendInTheBackground) {264 if (DriverFactoryHelper.isMobileNativeExecution()) {265 if (driver instanceof AndroidDriver androidDriver){266 androidDriver.runAppInBackground(Duration.ofSeconds(secondsToSpendInTheBackground));267 }else if (driver instanceof IOSDriver iosDriver){268 iosDriver.runAppInBackground(Duration.ofSeconds(secondsToSpendInTheBackground));269 }else{270 WebDriverElementActions.failAction(driver, null);271 }272 WebDriverElementActions.passAction(driver, null);273 }else {274 WebDriverElementActions.failAction(driver, null);275 }276 return this;277 }278 279 /**280 * Send the currently active app to the background and leave the app deactivated.281 * 282 * @return a self-reference to be used to chain actions283 */284 public TouchActions sendAppToBackground() {285 return sendAppToBackground(-1);286 }287 288 /**289 * Activates an app that has been previously deactivated or sent to the background.290 * 291 * @param appPackageName the full name for the app package that you want to activate. for example [com.apple.Preferences] or [io.appium.android.apis]292 * @return a self-reference to be used to chain actions293 */294 public TouchActions activateAppFromBackground(String appPackageName) {295 if (DriverFactoryHelper.isMobileNativeExecution()) {296 if (driver instanceof AndroidDriver androidDriver){297 androidDriver.activateApp(appPackageName);298 }else if (driver instanceof IOSDriver iosDriver){299 iosDriver.activateApp(appPackageName);300 }else{301 WebDriverElementActions.failAction(driver, null);302 }303 WebDriverElementActions.passAction(driver, null);304 }else {305 WebDriverElementActions.failAction(driver, null);306 }307 return this;308 }309 310 /**311 * Close the app which was provided in the capabilities at session creation and quits the session. Then re-Launches the app and restarts the session.312 * 313 * @return a self-reference to be used to chain actions314 */315 @Deprecated(forRemoval = true)316 public TouchActions restartApp() {317 if (DriverFactoryHelper.isMobileNativeExecution()) {318 if (driver instanceof AndroidDriver androidDriver){319 androidDriver.closeApp();320 androidDriver.launchApp();321 }else if (driver instanceof IOSDriver iosDriver){322 iosDriver.closeApp();323 iosDriver.launchApp();324 }else {325 WebDriverElementActions.failAction(driver, null);326 }327 WebDriverElementActions.passAction(driver, null);328 }else {329 WebDriverElementActions.failAction(driver, null);330 }331 return this;332 }333 334 /**335 * Resets the currently running app together with the session.336 * 337 * @return a self-reference to be used to chain actions338 */339 @Deprecated(forRemoval = true)340 public TouchActions resetApp() {341 if (DriverFactoryHelper.isMobileNativeExecution()) {342 if (driver instanceof AndroidDriver androidDriver){343 androidDriver.resetApp();344 }else if (driver instanceof IOSDriver iosDriver){345 iosDriver.resetApp();346 }else {347 WebDriverElementActions.failAction(driver, null);348 }349 WebDriverElementActions.passAction(driver, null);350 }else {351 WebDriverElementActions.failAction(driver, null);352 }353 return this;354 }355 /**356 * Swipes the sourceElement onto the destinationElement on a touch-enabled357 * screen358 *359 * @param sourceElementLocator the locator of the webElement that needs to360 * be swiped (By xpath, id, selector, name361 * ...etc)362 * @param destinationElementLocator the locator of the webElement that you'll363 * drop the sourceElement on (By xpath, id,364 * selector, name ...etc)365 * @return a self-reference to be used to chain actions366 */367 public TouchActions swipeToElement(By sourceElementLocator, By destinationElementLocator) {368 By internalSourceElementLocator = sourceElementLocator;369 By internalDestinationElementLocator = destinationElementLocator;370 if (WebDriverElementActions.identifyUniqueElement(driver, internalSourceElementLocator)371 && WebDriverElementActions.identifyUniqueElement(driver, internalDestinationElementLocator)) {372 // Override current locator with the aiGeneratedElementLocator373 internalSourceElementLocator = WebDriverElementActions.updateLocatorWithAIGeneratedOne(internalSourceElementLocator);374 internalDestinationElementLocator = WebDriverElementActions.updateLocatorWithAIGeneratedOne(internalDestinationElementLocator);375 WebElement sourceElement = driver.findElement(internalSourceElementLocator);376 WebElement destinationElement = driver.findElement(internalDestinationElementLocator);377 String startLocation = sourceElement.getLocation().toString();378 try {379 if (driver instanceof AppiumDriver appiumDriver) {380 // appium native device381 new Actions(appiumDriver).dragAndDrop(sourceElement, destinationElement).perform();382 } else {383 // regular touch screen device384 (new org.openqa.selenium.interactions.touch.TouchActions(driver)).clickAndHold(sourceElement).release(destinationElement).perform();385 }386 } catch (Exception e) {387 WebDriverElementActions.failAction(driver, internalSourceElementLocator, e);388 }389 String endLocation = driver.findElement(internalSourceElementLocator).getLocation().toString();390 String reportMessage = "Start point: " + startLocation + ", End point: " + endLocation;391 if (!endLocation.equals(startLocation)) {392 WebDriverElementActions.passAction(driver, internalSourceElementLocator, reportMessage);393 } else {394 WebDriverElementActions.failAction(driver, reportMessage, internalSourceElementLocator);395 }396 } else {397 WebDriverElementActions.failAction(driver, internalSourceElementLocator);398 }399 return this;400 }401 /**402 * Swipes an element with the desired x and y offset. Swiping direction is403 * determined by the positive/negative nature of the offset. Swiping destination404 * is determined by the value of the offset.405 *406 * @param elementLocator the locator of the webElement under test (By xpath, id,407 * selector, name ...etc)408 * @param xOffset the horizontal offset by which the element should be409 * swiped. positive value is "right" and negative value is410 * "left"411 * @param yOffset the vertical offset by which the element should be412 * swiped. positive value is "down" and negative value is413 * "up"414 * @return a self-reference to be used to chain actions415 */416 public TouchActions swipeByOffset(By elementLocator, int xOffset, int yOffset) {417 By internalElementLocator = elementLocator;418 if (WebDriverElementActions.identifyUniqueElement(driver, internalElementLocator)) {419 // Override current locator with the aiGeneratedElementLocator420 internalElementLocator = WebDriverElementActions.updateLocatorWithAIGeneratedOne(internalElementLocator);421 WebElement sourceElement = driver.findElement(internalElementLocator);422 Point elementLocation = sourceElement.getLocation();423 String startLocation = elementLocation.toString();424 try {425 if (driver instanceof AppiumDriver appiumDriver) {426 // appium native device427 new Actions(appiumDriver).dragAndDropBy(sourceElement, xOffset, yOffset).perform();428 } else {429 // regular touch screen device430 (new org.openqa.selenium.interactions.touch.TouchActions(driver)).clickAndHold(sourceElement).moveByOffset(xOffset, yOffset).release()431 .perform();432 }433 } catch (Exception e) {434 WebDriverElementActions.failAction(driver, internalElementLocator, e);435 }436 String endLocation = driver.findElement(internalElementLocator).getLocation().toString();437 String reportMessage = "Start point: " + startLocation + ", End point: " + endLocation;438 if (!endLocation.equals(startLocation)) {439 WebDriverElementActions.passAction(driver, internalElementLocator, reportMessage);440 } else {441 WebDriverElementActions.failAction(driver, reportMessage, internalElementLocator);442 }443 } else {444 WebDriverElementActions.failAction(driver, internalElementLocator);445 }446 return this;447 }448 449 /**450 * Attempts to scroll the element into view in case of native mobile elements.451 *452 * @param targetElementLocator the locator of the webElement under test (By xpath, id,453 * selector, name ...etc)454 * @param swipeDirection SwipeDirection.DOWN, UP, RIGHT, or LEFT455 * @return a self-reference to be used to chain actions456 */457 public TouchActions swipeElementIntoView(By targetElementLocator, SwipeDirection swipeDirection) {458 return swipeElementIntoView(null, targetElementLocator, swipeDirection);459 }460 /**461 * Attempts to scroll the element into view in case of native mobile elements.462 *463 * @param targetElementLocator the locator of the webElement under test (By xpath, id,464 * selector, name ...etc)465 * @param swipeDirection SwipeDirection.DOWN, UP, RIGHT, or LEFT466 * @param swipeTechnique SwipeTechnique.TOUCH_ACTIONS, or UI_SELECTOR467 * @return a self-reference to be used to chain actions468 */469 @Deprecated(forRemoval = true)470 public TouchActions swipeElementIntoView(By targetElementLocator, SwipeDirection swipeDirection, SwipeTechnique swipeTechnique) {471 return swipeElementIntoView(targetElementLocator, swipeDirection, swipeTechnique, 0);472 }473 /**474 * Attempts to scroll the element into view in case of native mobile elements.475 *476 * @param targetElementLocator the locator of the webElement under test (By xpath, id,477 * selector, name ...etc)478 * @param swipeDirection SwipeDirection.DOWN, UP, RIGHT, or LEFT479 * @param swipeTechnique SwipeTechnique.TOUCH_ACTIONS, or UI_SELECTOR480 * @param scrollableElementInstanceNumber in case of multiple scrollable views, insert the instance number here (starts with 0)481 * @return a self-reference to be used to chain actions482 */483 @Deprecated(forRemoval = true)484 public TouchActions swipeElementIntoView(By targetElementLocator, SwipeDirection swipeDirection, SwipeTechnique swipeTechnique, int scrollableElementInstanceNumber) {485 By internalElementLocator = targetElementLocator;486 internalElementLocator = WebDriverElementActions.updateLocatorWithAIGeneratedOne(internalElementLocator);487 try {488 if (driver instanceof AppiumDriver appiumDriver) {489 // appium native application490 boolean isElementFound = attemptToSwipeElementIntoViewInNativeApp(internalElementLocator, swipeDirection, swipeTechnique, scrollableElementInstanceNumber);491 if (Boolean.FALSE.equals(isElementFound)) {492 WebDriverElementActions.failAction(appiumDriver, internalElementLocator);493 }494 } else {495 // regular touch screen device496 if (WebDriverElementActions.identifyUniqueElement(driver, internalElementLocator)) {497 Point elementLocation = driver.findElement(internalElementLocator).getLocation();498 (new org.openqa.selenium.interactions.touch.TouchActions(driver)).scroll(elementLocation.getX(), elementLocation.getY()).perform();499 } else {500 WebDriverElementActions.failAction(driver, internalElementLocator);501 }502 }503 WebDriverElementActions.passAction(driver, internalElementLocator);504 } catch (Exception e) {505 WebDriverElementActions.failAction(driver, internalElementLocator, e);506 }507 return this;508 }509 //TODO: swipeToEndOfView(SwipeDirection swipeDirection)510 //TODO: waitUntilElementIsNotVisible(String elementReferenceScreenshot)511 /**512 * Waits until a specific element is now visible on the current screen513 * @param elementReferenceScreenshot relative path to the reference image from the local object repository514 * @return a self-reference to be used to chain actions515 */516 public TouchActions waitUntilElementIsVisible(String elementReferenceScreenshot){517 var visualIdentificationObjects = ElementActionsHelper.waitForElementPresence(driver, elementReferenceScreenshot);518 byte[] currentScreenImage = (byte[]) visualIdentificationObjects.get(0);519 byte[] referenceImage = (byte[]) visualIdentificationObjects.get(1);520 List<Integer> coordinates = (List<Integer>) visualIdentificationObjects.get(2);521 // prepare attachments522 var screenshot = ScreenshotManager.prepareImageforReport(currentScreenImage, "waitUntilElementIsVisible - Current Screen Image");523 var referenceScreenshot = ScreenshotManager.prepareImageforReport(referenceImage, "waitUntilElementIsVisible - Reference Screenshot");524 List<List<Object>> attachments = new LinkedList<>();525 attachments.add(referenceScreenshot);526 attachments.add(screenshot);527 if (!Collections.emptyList().equals(coordinates)) {528 WebDriverElementActions.passAction(driver, null, attachments);529 }else{530 WebDriverElementActions.failAction(driver, "Couldn't find reference element on the current screen. If you can see it in the attached image then kindly consider cropping it and updating your reference image.", null, attachments);531 }532 return this;533 }534 /**535 * Attempts to scroll element into view using the new W3C compliant actions for android and ios and AI for image identification536 * @param elementReferenceScreenshot relative path to the reference image from the local object repository537 * @param swipeDirection SwipeDirection.DOWN, UP, RIGHT, or LEFT538 * @return a self-reference to be used to chain actions539 */540 public TouchActions swipeElementIntoView(String elementReferenceScreenshot, SwipeDirection swipeDirection) {541 return swipeElementIntoView(null, elementReferenceScreenshot, swipeDirection);542 }543 /**544 * Attempts to scroll element into view using the new W3C compliant actions for android and ios and AI for image identification545 * @param scrollableElementLocator the locator of the container/view/scrollable webElement that the scroll action will be performed inside546 * @param elementReferenceScreenshot relative path to the reference image from the local object repository547 * @param swipeDirection SwipeDirection.DOWN, UP, RIGHT, or LEFT548 * @return a self-reference to be used to chain actions549 */550 public TouchActions swipeElementIntoView(By scrollableElementLocator, String elementReferenceScreenshot, SwipeDirection swipeDirection) {551 By internalScrollableElementLocator = WebDriverElementActions.updateLocatorWithAIGeneratedOne(scrollableElementLocator);552 // Prepare attachments for reporting553 List<List<Object>> attachments = new LinkedList<>();554 if (WebDriverElementActions.identifyUniqueElement(driver, internalScrollableElementLocator)) {555 try {556 if (driver instanceof AppiumDriver appiumDriver) {557 // appium native application558 var visualIdentificationObjects = attemptToSwipeElementIntoViewInNativeApp(scrollableElementLocator, elementReferenceScreenshot, swipeDirection);559 byte[] currentScreenImage = (byte[]) visualIdentificationObjects.get(0);560 byte[] referenceImage = (byte[]) visualIdentificationObjects.get(1);561 List<Integer> coordinates = (List<Integer>) visualIdentificationObjects.get(2);562 // prepare attachments563 var screenshot = ScreenshotManager.prepareImageforReport(currentScreenImage, "swipeElementIntoView - Current Screen Image");564 var referenceScreenshot = ScreenshotManager.prepareImageforReport(referenceImage, "swipeElementIntoView - Reference Screenshot");565 attachments = new LinkedList<>();566 attachments.add(referenceScreenshot);567 attachments.add(screenshot);568 // If coordinates are empty then OpenCV couldn't find the element on screen569 if (Collections.emptyList().equals(coordinates)) {570 WebDriverElementActions.failAction(driver, "Couldn't find reference element on the current screen. If you can see it in the attached image then kindly consider cropping it and updating your reference image.", null, attachments);571 }572 } else {573 // Wait for element presence and get the needed data574 var objects = ElementActionsHelper.waitForElementPresence(driver, elementReferenceScreenshot);575 byte[] currentScreenImage = (byte[]) objects.get(0);576 byte[] referenceImage = (byte[]) objects.get(1);577 List<Integer> coordinates = (List<Integer>) objects.get(2);578 // prepare attachments579 var screenshot = ScreenshotManager.prepareImageforReport(currentScreenImage, "swipeElementIntoView - Current Screen Image");580 var referenceScreenshot = ScreenshotManager.prepareImageforReport(referenceImage, "swipeElementIntoView - Reference Screenshot");581 attachments = new LinkedList<>();582 attachments.add(referenceScreenshot);583 attachments.add(screenshot);584 // If coordinates are empty then OpenCV couldn't find the element on screen585 if (Collections.emptyList().equals(coordinates)) {586 WebDriverElementActions.failAction(driver, "Couldn't find reference element on the current screen. If you can see it in the attached image then kindly consider cropping it and updating your reference image.", null, attachments);587 } else {588 (new org.openqa.selenium.interactions.touch.TouchActions(driver)).scroll(coordinates.get(0), coordinates.get(1)).perform();589 }590 }591 WebDriverElementActions.passAction(driver, null, attachments);592 } catch (Exception e) {593 WebDriverElementActions.failAction(driver, "Couldn't find reference element on the current screen. If you can see it in the attached image then kindly consider cropping it and updating your reference image.", null, attachments);594 }595 }else {596 WebDriverElementActions.failAction(driver, internalScrollableElementLocator);597 }598 return this;599 }600 /**601 * Attempts to scroll element into view using the new W3C compliant actions for android and ios602 * @param scrollableElementLocator the locator of the container/view/scrollable webElement that the scroll action will be performed inside603 * @param targetElementLocator the locator of the webElement that you want to scroll to under test (By xpath, id,604 * selector, name ...etc)605 * @param swipeDirection SwipeDirection.DOWN, UP, RIGHT, or LEFT606 * @return a self-reference to be used to chain actions607 */608 public TouchActions swipeElementIntoView(By scrollableElementLocator, By targetElementLocator, SwipeDirection swipeDirection) {609 By internalScrollableElementLocator = WebDriverElementActions.updateLocatorWithAIGeneratedOne(scrollableElementLocator);610 By internalTargetElementLocator = WebDriverElementActions.updateLocatorWithAIGeneratedOne(targetElementLocator);611 if (WebDriverElementActions.identifyUniqueElement(driver, internalScrollableElementLocator)) {612 try {613 if (driver instanceof AppiumDriver appiumDriver) {614 // appium native application615 boolean isElementFound = attemptToSwipeElementIntoViewInNativeApp(scrollableElementLocator, targetElementLocator, swipeDirection);616 if (Boolean.FALSE.equals(isElementFound)) {617 WebDriverElementActions.failAction(appiumDriver, internalTargetElementLocator);618 }619 } else {620 // regular touch screen device621 if (WebDriverElementActions.identifyUniqueElement(driver, internalTargetElementLocator)) {622 Point elementLocation = driver.findElement(internalTargetElementLocator).getLocation();623 (new org.openqa.selenium.interactions.touch.TouchActions(driver)).scroll(elementLocation.getX(), elementLocation.getY()).perform();624 } else {625 WebDriverElementActions.failAction(driver, internalTargetElementLocator);626 }627 }628 WebDriverElementActions.passAction(driver, internalTargetElementLocator);629 } catch (Exception e) {630 WebDriverElementActions.failAction(driver, internalTargetElementLocator, e);631 }632 }else {633 WebDriverElementActions.failAction(driver, internalScrollableElementLocator);634 }635 return this;636 }637 private boolean attemptToSwipeElementIntoViewInNativeApp(By elementLocator, SwipeDirection swipeDirection, SwipeTechnique swipeTechnique, int scrollableElementInstanceNumber) {638 boolean isElementFound = false;639 int attemptsToFindElement = 0;640 String lastPageSourceBeforeSwiping = "";641 do {642 // appium native device643 if (!driver.findElements(elementLocator).isEmpty()644 && WebDriverElementActions.isElementDisplayed(driver, elementLocator)) {645 // element is already on screen646 isElementFound = true;647 ReportManager.logDiscrete("Element found on screen.");648 } else {649 // for the animated GIF:650 WebDriverElementActions.takeScreenshot(driver, elementLocator, "swipeElementIntoView", null, true);651 lastPageSourceBeforeSwiping = driver.getPageSource();652 switch (swipeTechnique) {653 case W3C_ACTIONS -> attemptW3cCompliantActionsScroll(swipeDirection, null, elementLocator);654 case UI_SELECTOR -> attemptUISelectorScroll(swipeDirection, scrollableElementInstanceNumber);655 }656 attemptsToFindElement++;657 }658 //attempting to change scrolling method if page source was not changed659 if (lastPageSourceBeforeSwiping.equals(driver.getPageSource())){660 if (swipeTechnique.equals(SwipeTechnique.W3C_ACTIONS)){661 swipeTechnique = SwipeTechnique.UI_SELECTOR;662 }else{663 swipeTechnique = SwipeTechnique.W3C_ACTIONS;664 }665 }666 } while (Boolean.FALSE.equals(isElementFound) && attemptsToFindElement < DEFAULT_NUMBER_OF_ATTEMPTS_TO_SCROLL_TO_ELEMENT);667 return isElementFound;668 }669 private List<Object> attemptToSwipeElementIntoViewInNativeApp(By scrollableElementLocator, String targetElementImage, SwipeDirection swipeDirection) {670 boolean isElementFound = false;671 boolean canStillScroll = true;672 var isDiscrete = ReportManagerHelper.getDiscreteLogging();673 ReportManagerHelper.setDiscreteLogging(true);674 List<Object> visualIdentificationObjects;675 // force SHAFT back into the loop even if canStillScroll is false, or ignore it completely for the first 5 scroll attempts676 int blindScrollingAttempts = 0;677 do {678 // appium native device679 // Wait for element presence and get the needed data680 visualIdentificationObjects = ElementActionsHelper.waitForElementPresence(driver, targetElementImage);681 List<Integer> coordinates = (List<Integer>) visualIdentificationObjects.get(2);682 if (!Collections.emptyList().equals(coordinates)) {683 // element is already on screen684 isElementFound = true;685 ReportManager.logDiscrete("Element found on screen.");686 } else {687 // for the animated GIF:688 WebDriverElementActions.takeScreenshot(driver, null, "swipeElementIntoView", null, true);689 canStillScroll = attemptW3cCompliantActionsScroll(swipeDirection, scrollableElementLocator, null);690 blindScrollingAttempts++;691 }692 } while (Boolean.FALSE.equals(isElementFound) && blindScrollingAttempts<DEFAULT_NUMBER_OF_ATTEMPTS_TO_SCROLL_TO_ELEMENT && Boolean.TRUE.equals(canStillScroll));693 ReportManagerHelper.setDiscreteLogging(isDiscrete);694 return visualIdentificationObjects;695 }696 private boolean attemptToSwipeElementIntoViewInNativeApp(By scrollableElementLocator, By targetElementLocator, SwipeDirection swipeDirection) {697 boolean isElementFound = false;698 boolean canStillScroll = true;699 var isDiscrete = ReportManagerHelper.getDiscreteLogging();700 ReportManagerHelper.setDiscreteLogging(true);701 // force SHAFT back into the loop even if canStillScroll is false, or ignore it completely for the first 5 scroll attempts702 int blindScrollingAttempts = 0;703 do {704 // appium native device705 if (!driver.findElements(targetElementLocator).isEmpty()706 && WebDriverElementActions.isElementDisplayed(driver, targetElementLocator)) {707 // element is already on screen708 isElementFound = true;709 ReportManager.logDiscrete("Element found on screen.");710 } else {711 // for the animated GIF:712 WebDriverElementActions.takeScreenshot(driver, null, "swipeElementIntoView", null, true);713 canStillScroll = attemptW3cCompliantActionsScroll(swipeDirection, scrollableElementLocator, targetElementLocator);714 }715 blindScrollingAttempts++;716 } while (Boolean.FALSE.equals(isElementFound) && blindScrollingAttempts<DEFAULT_NUMBER_OF_ATTEMPTS_TO_SCROLL_TO_ELEMENT && Boolean.TRUE.equals(canStillScroll));717 ReportManagerHelper.setDiscreteLogging(isDiscrete);718 return isElementFound;719 }720 721 private void attemptUISelectorScroll(SwipeDirection swipeDirection, int scrollableElementInstanceNumber) {722 ReportManager.logDiscrete("Swiping to find Element using UiSelector.");723 int scrollingSpeed = 100;724 String scrollDirection = "Forward";725 ReportManager.logDiscrete("Swiping to find Element using UiSelector.");726 By androidUIAutomator = AppiumBy727 .androidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance("728 + scrollableElementInstanceNumber + ")).scroll" + scrollDirection + "(" + scrollingSpeed + ")");729 WebDriverElementActions.getElementsCount(driver, androidUIAutomator);730 }731 private boolean attemptW3cCompliantActionsScroll(SwipeDirection swipeDirection, By scrollableElementLocator, By targetElementLocator) {732 var logMessage = "Swiping to find Element using W3C Compliant Actions. SwipeDirection ["+swipeDirection+"]";733 if (targetElementLocator !=null){734 logMessage+= ", TargetElementLocator ["+targetElementLocator+"]";735 }736 if (scrollableElementLocator != null){737 logMessage += ", inside ScrollableElement ["+scrollableElementLocator+"]";738 }739 logMessage += ".";740 ReportManager.logDiscrete(logMessage);741 Dimension screenSize = driver.manage().window().getSize();742 boolean canScrollMore = true;743 var scrollParameters = new HashMap<>();744 if (scrollableElementLocator!=null) {745 //scrolling inside an element746 Rectangle elementRectangle = driver.findElement(scrollableElementLocator).getRect();747 scrollParameters.putAll(ImmutableMap.of(748 "height", elementRectangle.getHeight() *90/100749 ));750 //percent 0.5 works for UP/DOWN, optimized to 0.8 to scroll faster and introduced delay 1000ms after every scroll action to increase stability751 switch (swipeDirection){752 case UP -> scrollParameters.putAll(ImmutableMap.of("percent", 0.8, "height", elementRectangle.getHeight() *90/100, "width", elementRectangle.getWidth(), "left", elementRectangle.getX(), "top", elementRectangle.getHeight() - 100));753 case DOWN -> scrollParameters.putAll(ImmutableMap.of("percent", 0.8, "height", elementRectangle.getHeight() *90/100, "width", elementRectangle.getWidth(), "left", elementRectangle.getX(), "top", 100));754 case RIGHT -> scrollParameters.putAll(ImmutableMap.of("percent", 1, "height", elementRectangle.getHeight(), "width", elementRectangle.getWidth()*70/100, "left", 100, "top", elementRectangle.getY()));755 case LEFT -> scrollParameters.putAll(ImmutableMap.of("percent", 1, "height", elementRectangle.getHeight(), "width", elementRectangle.getWidth(), "left", elementRectangle.getX()+(elementRectangle.getWidth() *50/100), "top", elementRectangle.getY()));756 }757 }else{758 //scrolling inside the screen759 scrollParameters.putAll(ImmutableMap.of(760 "width", screenSize.getWidth(), "height", screenSize.getHeight() *90/100,761 "percent", 0.8762 ));763 switch (swipeDirection){764 case UP -> scrollParameters.putAll(ImmutableMap.of("left", 0, "top", screenSize.getHeight() - 100));765 case DOWN -> scrollParameters.putAll(ImmutableMap.of("left", 0, "top", 100));766// case RIGHT -> scrollParameters.putAll(ImmutableMap.of("left", 100, "top", 0));767// case LEFT -> scrollParameters.putAll(ImmutableMap.of("left", screenSize.getWidth() - 100, "top", 0));768 }769 }770 if (driver instanceof AndroidDriver androidDriver){771 scrollParameters.putAll(ImmutableMap.of(772 "direction", swipeDirection.toString()773 ));774 canScrollMore = (Boolean) ((JavascriptExecutor) androidDriver).executeScript("mobile: scrollGesture", scrollParameters);775 } else if (driver instanceof IOSDriver iosDriver) {776 scrollParameters.putAll(ImmutableMap.of(777 "direction", swipeDirection.toString()778 ));779 canScrollMore = (Boolean) ((JavascriptExecutor) iosDriver).executeScript("mobile: scroll", scrollParameters);780 }781 var logMessageAfter = "Attempted to scroll using these parameters: ["+scrollParameters+"]";782 if (canScrollMore){783 logMessageAfter += ", there is still more room to keep scrolling.";784 }else{785 logMessageAfter += ", there is no more room to keep scrolling.";786 }787 try {788 //insert delay for scrolling to finish789 Thread.sleep(1000);790 } catch (InterruptedException e) {791 e.printStackTrace();...

Full Screen

Full Screen

PrivateTests.java

Source:PrivateTests.java Github

copy

Full Screen

...179 bookshelfAllPage().clickOfflineTab();180 assertBookshelfOfflinePageSelected();181 bookshelfOfflinePage().assertBookDownloadedTitle(bookTitle).equals(getDriver().findElement(AppiumBy.androidUIAutomator("new UiSelector().resourceId(\"com.bokus.play:id/itemView\").index(1).childSelector(new UiSelector().resourceId(\"com.bokus.play:id/textBookTitle\"))")).getText());182 bookshelfOfflinePage().assertDownloaded();183 String sessionID = getDriver().getSessionId().toString();184 //USE JAVA HTTP CLIENT INSTEAD!!! - curl cheat sheet: https://curl.github.io/curl-cheat-sheet/http-sheet.html - https://everything.curl.dev/http/cheatsheet185 //String command = "curl -u \"kevinzhang_vxoIiW:ndt4o19pDheTksDbu2z3\" -H \"Content-Type: application/json\" -d '{\"networkProfile\":\"airplane-mode\"}' -X PUT \"https://api-cloud.browserstack.com/app-automate/sessions/" + sessionID + "/update_network.json\"";186 String[] command = { "curl\s", "-u\s", username + ":" + accessKey, "\s-H\s", "Content-Type: application/json\s", "-d\s", "'{\"networkProfile\":\"airplane-mode\"}'\s", "-X\s", "PUT\s", "https://api-cloud.browserstack.com/app-automate/sessions/", sessionID + "/update_network.json" };187 //String[] command = { "curl ", "-u ", username + ":" + accessKey, " -H " , "Content-Type: application/json ", "-d ", "'{\"networkProfile\":\"airplane-mode\"}' ", "-X ", "PUT ", "https://api-cloud.browserstack.com/app-automate/sessions/", sessionID + "/update_network.json" };188 ProcessBuilder process = new ProcessBuilder(command);189 Process p;190 p = process.start();191 BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));192 StringBuilder builder = new StringBuilder();193 String line;194 while ((line = reader.readLine()) != null) {195 builder.append(line);196 builder.append(System.getProperty("line.separator"));197 }198 String result = builder.toString();199 System.out.print(result);200 bookshelfOfflinePage().clickBookTitle("Musikmysteriet");201 assertAudiobookPlayerBookCoverDisplayed();202 audiobookPlayerPage().assertAudioBookPlayed();203 }*/204 @Test205 public void testDownloadWait() {206 loginPremiumAccount();207 assertExplorePageDisplayed();208 explorePage().clickBook();209 assertBookDetailViewDisplayed();210 String bookTitle = bookDetailViewPage().getBookTitle();211 bookDetailViewPage().clickDownloadIndicator();212 bookDetailViewPage().clickBookshelfTab();...

Full Screen

Full Screen

MobileBy.java

Source:MobileBy.java Github

copy

Full Screen

...158 public static class ByAndroidUIAutomator extends AppiumBy.ByAndroidUIAutomator {159 public ByAndroidUIAutomator(String uiautomatorText) {160 super(uiautomatorText);161 }162 @Override public String toString() {163 return "By.AndroidUIAutomator: " + getRemoteParameters().value();164 }165 }166 /**167 * About Android accessibility168 * https://developer.android.com/intl/ru/training/accessibility/accessible-app.html169 * About iOS accessibility170 * https://developer.apple.com/library/ios/documentation/UIKit/Reference/171 * UIAccessibilityIdentification_Protocol/index.html172 * @deprecated Use {@link AppiumBy.ByAccessibilityId} instead.173 */174 @Deprecated175 public static class ByAccessibilityId extends AppiumBy.ByAccessibilityId {176 public ByAccessibilityId(String accessibilityId) {177 super(accessibilityId);178 }179 @Override public String toString() {180 return "By.AccessibilityId: " + getRemoteParameters().value();181 }182 }183 /**184 * This locator strategy is available in XCUITest Driver mode.185 * See <a href="https://github.com/facebookarchive/WebDriverAgent/wiki/Class-Chain-Queries-Construction-Rules">186 * the documentation</a> for more details187 * @deprecated Use {@link AppiumBy.ByIosClassChain} instead.188 */189 @Deprecated190 public static class ByIosClassChain extends AppiumBy.ByIosClassChain {191 protected ByIosClassChain(String locatorString) {192 super(locatorString);193 }194 @Override public String toString() {195 return "By.IosClassChain: " + getRemoteParameters().value();196 }197 }198 /**199 * This locator strategy is only available in Espresso Driver mode.200 * See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">201 * the documentation</a> for more details202 * @deprecated Use {@link AppiumBy.ByAndroidDataMatcher} instead.203 */204 @Deprecated205 public static class ByAndroidDataMatcher extends AppiumBy.ByAndroidDataMatcher {206 protected ByAndroidDataMatcher(String locatorString) {207 super(locatorString);208 }209 @Override public String toString() {210 return "By.AndroidDataMatcher: " + getRemoteParameters().value();211 }212 }213 /**214 * This locator strategy is only available in Espresso Driver mode.215 * See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">216 * the documentation</a> for more details217 * @deprecated Use {@link AppiumBy.ByAndroidViewMatcher} instead.218 */219 @Deprecated220 public static class ByAndroidViewMatcher extends AppiumBy.ByAndroidViewMatcher {221 protected ByAndroidViewMatcher(String locatorString) {222 super(locatorString);223 }224 @Override public String toString() {225 return "By.AndroidViewMatcher: " + getRemoteParameters().value();226 }227 }228 /**229 * This locator strategy is available in XCUITest Driver mode.230 * @deprecated Use {@link AppiumBy.ByIosNsPredicate} instead.231 */232 @Deprecated233 public static class ByIosNsPredicate extends AppiumBy.ByIosNsPredicate {234 protected ByIosNsPredicate(String locatorString) {235 super(locatorString);236 }237 @Override public String toString() {238 return "By.IosNsPredicate: " + getRemoteParameters().value();239 }240 }241 /**242 * The Windows UIAutomation selector.243 * @deprecated Not supported on the server side.244 */245 @Deprecated246 public static class ByWindowsAutomation extends MobileBy implements Serializable {247 protected ByWindowsAutomation(String locatorString) {248 super("-windows uiautomation", locatorString, "windowsAutomation");249 }250 @Override public String toString() {251 return "By.windowsAutomation: " + getRemoteParameters().value();252 }253 }254 /**255 * This locator strategy is available only if OpenCV libraries and256 * NodeJS bindings are installed on the server machine.257 * @deprecated Use {@link AppiumBy.ByImage} instead.258 */259 @Deprecated260 public static class ByImage extends AppiumBy.ByImage {261 protected ByImage(String b64Template) {262 super(b64Template);263 }264 @Override public String toString() {265 return "By.Image: " + getRemoteParameters().value();266 }267 }268 /**269 * This type of locator requires the use of the 'customFindModules' capability and a270 * separately-installed element finding plugin.271 * @deprecated Use {@link AppiumBy.ByCustom} instead.272 */273 @Deprecated274 public static class ByCustom extends AppiumBy.ByCustom {275 protected ByCustom(String selector) {276 super(selector);277 }278 @Override public String toString() {279 return "By.Custom: " + getRemoteParameters().value();280 }281 }282 /**283 * This locator strategy is available in Espresso Driver mode.284 * @deprecated Use {@link AppiumBy.ByAndroidViewTag} instead.285 */286 @Deprecated287 public static class ByAndroidViewTag extends AppiumBy.ByAndroidViewTag {288 public ByAndroidViewTag(String tag) {289 super(tag);290 }291 @Override public String toString() {292 return "By.AndroidViewTag: " + getRemoteParameters().value();293 }294 }295}...

Full Screen

Full Screen

AppiumBy.java

Source:AppiumBy.java Github

copy

Full Screen

...35 }36 @Override public WebElement findElement(SearchContext context) {37 return context.findElement(this);38 }39 @Override public String toString() {40 return String.format("%s.%s: %s", AppiumBy.class.getSimpleName(), locatorName, remoteParameters.value());41 }42 /**43 * About Android accessibility44 * https://developer.android.com/intl/ru/training/accessibility/accessible-app.html45 * About iOS accessibility46 * https://developer.apple.com/library/ios/documentation/UIKit/Reference/47 * UIAccessibilityIdentification_Protocol/index.html48 * @param accessibilityId id is a convenient UI automation accessibility Id.49 * @return an instance of {@link AppiumBy.ByAndroidUIAutomator}50 */51 public static By accessibilityId(final String accessibilityId) {52 return new ByAccessibilityId(accessibilityId);53 }...

Full Screen

Full Screen

LocatorMap.java

Source:LocatorMap.java Github

copy

Full Screen

...66 if (platformKey == null) {67 LOG.error("Locator with key {} is undefined for platform {}.", key, platform);68 return null;69 }70 String type = platformKey.get("type").toString();71 String rawValue = platformKey.get("value").toString();72 LOG.debug("Getting locator {} of type {}", rawValue, type);73 if (type.equalsIgnoreCase(CSS)) {74 return $(By.cssSelector(formatValue(rawValue, params)));75 } else if (type.equalsIgnoreCase(XPATH)) {76 return $(By.xpath(formatValue(rawValue, params)));77 } else if (type.equalsIgnoreCase(ID)) {78 return $(By.id(formatValue(rawValue, params)));79 } else if (type.equalsIgnoreCase(ACCESIBILITY_ID)) {80 return $(AppiumBy.accessibilityId(formatValue(rawValue, params)));81 } else if (type.equalsIgnoreCase(UIAUTOMATOR)) {82 return $(AppiumBy.androidUIAutomator(formatValue(rawValue, params)));83 } else if (type.equalsIgnoreCase(IMAGE)) {84 return $(AppiumBy.image(ImageUtils.getImageAsBase64String(rawValue)));85 } else if (type.equalsIgnoreCase(OPENCV)) {86 return $(87 ByImage.image(88 formatValue(rawValue, params), getThreshold(platformKey), templateMatcher, ocr));89 } else {90 return $(formatValue(rawValue, params));91 }92 }93 /**94 * Get a Selenide collection locator.95 *96 * @param key locator key97 * @param platform platform98 * @param params locator key parameters99 * @return {@link ElementsCollection}100 */101 public ElementsCollection getCollectionLocator(String key, Platform platform, Object... params) {102 Map<String, Object> platformKey = getRawLocator(key, platform, params);103 String type = platformKey.get("type").toString();104 String rawValue = platformKey.get("value").toString();105 if (type.equalsIgnoreCase(CSS)) {106 return $$(By.cssSelector(formatValue(rawValue, params)));107 } else if (type.equalsIgnoreCase(XPATH)) {108 return $$(By.xpath(formatValue(rawValue, params)));109 } else if (type.equalsIgnoreCase(ID)) {110 return $$(By.id(formatValue(rawValue, params)));111 } else if (type.equalsIgnoreCase(ACCESIBILITY_ID)) {112 return $$(AppiumBy.accessibilityId(formatValue(rawValue, params)));113 } else if (type.equalsIgnoreCase(UIAUTOMATOR)) {114 return $$(AppiumBy.androidUIAutomator(formatValue(rawValue, params)));115 } else if (type.equalsIgnoreCase(IMAGE)) {116 return $$(AppiumBy.image(ImageUtils.getImageAsBase64String(rawValue)));117 } else if (type.equalsIgnoreCase(OPENCV)) {118 return $$(119 ByImage.image(120 formatValue(rawValue, params), getThreshold(platformKey), templateMatcher, ocr));121 } else {122 return $$(formatValue(rawValue, params));123 }124 }125 /**126 * Get the raw locator (type and value). This is exposed for logging purposes.127 *128 * @param key locator key129 * @param platform platform130 * @param params locator key parameters131 * @return {@link Pair}132 */133 public Map<String, Object> getRawLocator(String key, Platform platform, Object... params) {134 return map.get(key).get(platform.getPlatformName());135 }136 /**137 * @param platform {@link Platform}138 * @return a map of all UI locators specified for the given platform139 */140 public Map<String, Pair<String, String>> getLocatorsForPlatform(Platform platform) {141 Map<String, Pair<String, String>> result = new HashMap<>();142 for (Map.Entry<String, Map<String, Map<String, Object>>> entry : map.entrySet()) {143 Map<String, Object> tuple = entry.getValue().get(platform.getPlatformName());144 if (tuple != null) {145 result.put(146 entry.getKey(),147 Pair.of(148 tuple.get("type").toString(), replacePlaceholders(tuple.get("value").toString())));149 }150 }151 return result;152 }153 protected String formatValue(String rawValue, Object... params) {154 if (rawValue == null) {155 return null;156 }157 return String.format(replacePlaceholders(rawValue), params);158 }159 protected String replacePlaceholders(String rawValue) {160 if (rawValue == null) {161 return null;162 }163 Matcher matcher = PLACEHOLDER_PATTERN.matcher(rawValue);164 StringBuffer strBuffer = new StringBuffer();165 while (matcher.find()) {166 matcher.appendReplacement(strBuffer, staticPlaceholders.get(matcher.group(1)).toString());167 }168 matcher.appendTail(strBuffer);169 return strBuffer.toString();170 }171 private double getThreshold(Map<String, ?> platformKey) {172 try {173 return (double) platformKey.get("threshold");174 } catch (Exception e) {175 LOG.warn(176 "Invalid or no threshold value {}. Using default: {}",177 platformKey.get("threshold"),178 ByImage.DEFAULT_THRESHOLD);179 }180 return ByImage.DEFAULT_THRESHOLD;181 }182}...

Full Screen

Full Screen

Strategies.java

Source:Strategies.java Github

copy

Full Screen

...123 private static String getValue(Annotation annotation, Strategies strategy) {124 try {125 Method m = annotation.getClass()126 .getMethod(strategy.valueName, AppiumByBuilder.DEFAULT_ANNOTATION_METHOD_ARGUMENTS);127 return m.invoke(annotation).toString();128 } catch (NoSuchMethodException129 | SecurityException130 | IllegalAccessException131 | IllegalArgumentException132 | InvocationTargetException e) {133 throw new RuntimeException(e);134 }135 }136 String returnValueName() {137 return valueName;138 }139 By getBy(Annotation annotation) {140 return null;141 }...

Full Screen

Full Screen

PlaybackSpeedPage.java

Source:PlaybackSpeedPage.java Github

copy

Full Screen

...29 WebElement element = driver.findElement(AppiumBy.androidUIAutomator("new UiScrollable(" +30 "new UiSelector().scrollable(true).className(\"androidx.recyclerview.widget.RecyclerView\"))" +31 ".setAsHorizontalList().scrollIntoView(new UiSelector().className(\"android.widget.TextView\")" +32 ".text(\"" + playbackSpeed + "\"))"));33 String speedText = speed.toString().replace("x", "");34 if (!speedText.equals(playbackSpeed)) {35 element.findElement(By.xpath("//android.widget.TextView[@text='" + playbackSpeed + "']")).click();36 }37 }38}...

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1By element = AppiumBy.toString("new UiSelector().text(\"New\")");2By element = MobileBy.toString("new UiSelector().text(\"New\")");3By element = AppiumBy.findBy("new UiSelector().text(\"New\")");4By element = MobileBy.findBy("new UiSelector().text(\"New\")");5By element = AppiumBy.findBy("new UiSelector().text(\"New\")");6By element = MobileBy.findBy("new UiSelector().text(\"New\")");7By element = AppiumBy.findIosUIAutomation("new UiSelector().text(\"New\")");8By element = MobileBy.findIosUIAutomation("new UiSelector().text(\"New\")");9By element = AppiumBy.findAndroidUIAutomator("new UiSelector().text(\"New\")");10By element = MobileBy.findAndroidUIAutomator("new UiSelector().text(\"New\")");11By element = AppiumBy.findAccessibilityId("new UiSelector().text(\"New\")");12By element = MobileBy.findAccessibilityId("new UiSelector().text(\"New\")");

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.support.ui.ExpectedConditions;4import org.openqa.selenium.support.ui.WebDriverWait;5import org.testng.annotations.Test;6import io.appium.java_client.MobileElement;7import io.appium.java_client.android.AndroidDriver;8import io.appium.java_client.android.AndroidElement;9import io.appium.java_client.remote.MobileCapabilityType;10public class AppiumBy extends Base {11 public void testAppiumBy() throws Exception {12 AndroidDriver<AndroidElement> driver = capabilities();13 WebDriverWait wait = new WebDriverWait(driver, 10);14 driver.findElementByAndroidUIAutomator("text(\"Views\")").click();15 driver.findElementByAndroidUIAutomator("text(\"Expandable Lists\")").click();16 driver.findElementByAndroidUIAutomator("text(\"1. Custom Adapter\")").click();17 driver.findElementByAndroidUIAutomator("text(\"People Names\")").click();18 driver.findElementByAndroidUIAutomator("text(\"Sample menu\")").click();19 driver.findElementByAndroidUIAutomator("text(\"Sample action\")").click();20 driver.findElementByAndroidUIAutomator("text(\"OK\")").click();21 driver.findElementByAndroidUIAutomator("text(\"Sample action\")").click();22 driver.findElementByAndroidUIAutomator("text(\"OK\")").click();23 driver.findElementByAndroidUIAutomator("text(\"Sample action\")").click();24 driver.findElementByAndroidUIAutomator("text(\"OK\")").click();

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1By by = AppiumBy.toString("id=android:id/text1");2System.out.println(by.toString());3By by = AppiumBy.ByAndroidUIAutomator.toString("new UiSelector().text(\"Views\")");4System.out.println(by.toString());5By by = AppiumBy.ByIosUIAutomation.toString("UIAButton[name=\"Buttons\"]");6System.out.println(by.toString());7By by = MobileBy.toString("id=android:id/text1");8System.out.println(by.toString());9By by = MobileBy.ByAndroidUIAutomator.toString("new UiSelector().text(\"Views\")");10System.out.println(by.toString());11By by = MobileBy.ByIosUIAutomation.toString("UIAButton[name=\"Buttons\"]");12System.out.println(by.toString());13By by = MobileBy.AccessibilityId.toString("AccessibilityId");14System.out.println(by.toString());15By by = MobileBy.AndroidUIAutomator.toString("AndroidUIAutomator");16System.out.println(by.toString());17By by = MobileBy.IosUIAutomation.toString("IosUIAutomation");18System.out.println(by.toString());19By by = MobileBy.Id.toString("Id");20System.out.println(by.toString());21By by = MobileBy.Name.toString("Name");22System.out.println(by.toString());23By by = MobileBy.XPath.toString("XPath");24System.out.println(by.toString());

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1System.out.println(by.toString());2System.out.println(by.toString());3System.out.println(by.toString());4System.out.println(by.toString());5System.out.println(by.toString());6System.out.println(by.toString());7System.out.println(by.toString());8System.out.println(by.toString());9System.out.println(by.toString());10System.out.println(by.toString());

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1System.out.println(by.toString());2System.out.println(by.toString());3System.out.println(by.toString());4System.out.println(by.toString());5System.out.println(by.toString());6System.out.println(by.toString());7System.out.println(by.toString());8System.out.println(by.toString());9System.out.println(by.toString());

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1System.out.println("The value of By object is: " + by.toString());2System.out.println("The value of By object is: " + by.toString());3System.out.println("The value of By object is: " + by.toString());4System.out.println("The value of By object is: " + by.toString());5System.out.println("The value of By object is: " + by.toString());6System.out.println("The value of By object is: " + by.toString());7System.out.println("The value of By object is: " + by.toString());8System.out.println("The value of By object is: " + by.toString());9System.out.println("The value of By object is: " + by.toString());10System.out.println("The value of By object is: " + by.toString());

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful