How to use SupportsSpecialEmulatorCommands class of io.appium.java_client.android package

Best io.appium code snippet using io.appium.java_client.android.SupportsSpecialEmulatorCommands

pureDrivers.java

Source:pureDrivers.java Github

copy

Full Screen

...1859 // ********************************************************************************************************************************************************1860 // AndroidDriver [153] = public default <T> java.lang.String io.appium.java_client.screenrecording.CanRecordScreen.stopRecordingScreen(T)1861 1862 // ********************************************************************************************************************************************************1863 // AndroidDriver [154] = public default void io.appium.java_client.android.SupportsSpecialEmulatorCommands.sendSMS(java.lang.String,java.lang.String)1864 1865 // ********************************************************************************************************************************************************1866 // AndroidDriver [155] = public default void io.appium.java_client.android.SupportsSpecialEmulatorCommands.makeGsmCall(java.lang.String,io.appium.java_client.android.GsmCallActions)1867 1868 // ********************************************************************************************************************************************************1869 // AndroidDriver [156] = public default void io.appium.java_client.android.SupportsSpecialEmulatorCommands.setGsmVoice(io.appium.java_client.android.GsmVoiceState)1870 1871 // ********************************************************************************************************************************************************1872 // AndroidDriver [157] = public default void io.appium.java_client.android.SupportsSpecialEmulatorCommands.setNetworkSpeed(io.appium.java_client.android.NetworkSpeed)1873 1874 // ********************************************************************************************************************************************************1875 // AndroidDriver [158] = public default void io.appium.java_client.android.SupportsSpecialEmulatorCommands.setPowerCapacity(int)1876 1877 // ********************************************************************************************************************************************************1878 // AndroidDriver [159] = public default void io.appium.java_client.android.SupportsSpecialEmulatorCommands.setPowerAC(io.appium.java_client.android.PowerACState)1879 1880 // ********************************************************************************************************************************************************1881 // AndroidDriver [160] = public default void io.appium.java_client.android.SupportsSpecialEmulatorCommands.setGsmSignalStrength(io.appium.java_client.android.GsmSignalStrength)1882 1883 // ********************************************************************************************************************************************************1884 // AndroidDriver [161] = public default void io.appium.java_client.android.SupportsNetworkStateManagement.toggleWifi()1885 public void toggleWifi() {1886 pureDriverDetails currentDriver = getCurrentDriverDetails();1887 pureCore.callMethod( currentDriver.mainDriver, currentDriver.mainDriver.getClass(), "toggleWifi", (Class<?>)null,1888 currentDriver.mainDriver.getClass().toString(), (Object)null );1889 }1890 1891 // ********************************************************************************************************************************************************1892 // AndroidDriver [162] = public default void io.appium.java_client.android.SupportsNetworkStateManagement.toggleData()1893 public void toggleData() {1894 pureDriverDetails currentDriver = getCurrentDriverDetails();1895 pureCore.callMethod( currentDriver.mainDriver, currentDriver.mainDriver.getClass(), "toggleData", (Class<?>)null,...

Full Screen

Full Screen

SeleniumFunctionsAndroidEnv.java

Source:SeleniumFunctionsAndroidEnv.java Github

copy

Full Screen

...31import io.appium.java_client.android.AndroidStartScreenRecordingOptions;32import io.appium.java_client.android.GsmCallActions;33import io.appium.java_client.android.NetworkSpeed;34import io.appium.java_client.android.SupportsNetworkStateManagement;35import io.appium.java_client.android.SupportsSpecialEmulatorCommands;36import io.appium.java_client.screenrecording.CanRecordScreen;37import static io.appium.java_client.touch.TapOptions.tapOptions;38import static io.appium.java_client.touch.LongPressOptions.longPressOptions;39import static java.time.Duration.ofSeconds;40import java.time.Duration;41import static io.appium.java_client.touch.offset.ElementOption.element;42import io.cucumber.datatable.DataTable;43public class SeleniumFunctionsAndroidEnv extends SeleniumFunctionsHelper {44 45 46 47 48 @Override49 public void waitForElementPresence(By locator) throws NotFoundException {50 Pojo.getWebDriverWait().until(ExpectedConditions.presenceOfElementLocated(locator));51 52 }53 54 55 @Override56 public void waitForPresenceOfNestedElementLocated(WebElement webElement, By sub_locator)57 throws NotFoundException {58 Pojo.getWebDriverWait().until(ExpectedConditions.presenceOfNestedElementLocatedBy(webElement, sub_locator));59 60 }61 62 @Override63 public void waitForPresenceOfNestedElementsLocated(By locator, By sub_locator)64 throws NotFoundException {65 Pojo.getWebDriverWait().until(ExpectedConditions.presenceOfNestedElementsLocatedBy(locator, sub_locator));66 67 }68 69 70 @Override71 public void waitForElementToBeClickable(By locator) throws NotFoundException {72 Pojo.getWebDriverWait().until(ExpectedConditions.elementToBeClickable(locator));73 74 }75 76 77 @Override78 public void waitForElementVisibilityLocated(By locator) throws NotFoundException {79 Pojo.getWebDriverWait().until(ExpectedConditions.visibilityOfElementLocated(locator));80 81 }82 83 84 85 @Override86 public boolean waitForElementInVisibilityLocated(By locator, int timeInMiliSeconds) throws NotFoundException {87 WebDriverWait webDriverWait = new WebDriverWait(Pojo.getAndroidDriver(), timeInMiliSeconds);88 return webDriverWait.until(ExpectedConditions.invisibilityOfElementLocated(locator));89 }90 91 92 @Override93 public boolean waitFor(int timeUnitSeconds) {94 try {95 Thread.sleep(TimeUnit.MILLISECONDS.convert(timeUnitSeconds, TimeUnit.SECONDS));96 return true;97 } catch (Exception exception) {98 exception.printStackTrace();99 return false;100 }101 }102 @Override103 public boolean waitFor(String timeUnitSeconds) {104 try {105 Thread.sleep(TimeUnit.MILLISECONDS.convert(Integer.parseInt(timeUnitSeconds), TimeUnit.SECONDS));106 return true;107 } catch (Exception exception) {108 exception.printStackTrace();109 return false;110 }111 }112 113 114 @Override115 public boolean checkElementDisplayed(By locator) {116 try {117 this.waitForElementVisibilityLocated(locator);118 //this.setHighlight(Pojo.getDriver().findElement(locator));119 return Pojo.getAndroidDriver().findElement(locator).isDisplayed();120 }121 122 catch (NoSuchElementException e) { 123 return false; 124 }125 catch (NotFoundException exception) {126 System.out.println("I got timeout " + exception.getMessage());127 exception.printStackTrace();128 return false;129 } 130 catch (Exception exception) {131 return false;132 }133 }134 135 @Override136 public boolean checkElementDisplayed(WebElement webElement) {137 try {138 this.waitForElementVisibility(webElement);139 return webElement.isDisplayed();140 } catch (NotFoundException exception) {141 System.out.println("I got timeout " + exception.getMessage());142 exception.printStackTrace();143 return false;144 } catch (Exception exception) {145 return false;146 }147 }148 149 150 @Override151 public boolean checkElementPresence(By locator) {152 try {153 this.waitForElementPresence(locator);154 return true;155 } catch (Exception exception) {156 return false;157 }158 }159 160 161 162 @Override163 public boolean isElementDisplayed(By locator) {164 try {165 Pojo.getWebDriverWait().until(ExpectedConditions.visibilityOfElementLocated(locator));166 return true;167 } catch (Exception exception) {168 return false;169 }170 }171 172 173 @Override174 public boolean checkElementVisibile(By locator) {175 try {176 this.waitForElementVisibilityLocated(locator);177 return Pojo.getAndroidDriver().findElement(locator).isDisplayed();178 } catch (Exception exception) {179 return false;180 }181 }182 183 184 185 @Override186 public boolean checkElementInVisibile(By locator) {187 try {188 boolean blnFlag=this.waitForElementInVisibilityLocated(locator,10);189 Pojo.getObjUtilitiesFunctions().consoleLogPrinter("Verify Locator InVisibility Status -----> " +blnFlag);190 return !this.checkElementDisplayed(locator);191 } catch (Exception exception) {192 Pojo.getObjUtilitiesFunctions().consoleLogPrinter("Error Message -------> "+exception.getMessage());193 exception.printStackTrace();194 return false;195 }196 }197 198 199 @Override200 public boolean waitForElementDisplayed(By locator, int timeInMiliSeconds) {201 try {202 WebDriverWait webDriverWait = new WebDriverWait(Pojo.getAndroidDriver(), timeInMiliSeconds);203 webDriverWait.until(ExpectedConditions.visibilityOfElementLocated(locator));204 205 return Pojo.getDriver().findElement(locator).isDisplayed();206 } catch (Exception exception) {207 return false;208 }209 }210 211 @Override212 public boolean waitForElementIfVisible(By locator, int timeInMiliSeconds) {213 try {214 215 WebDriverWait webDriverWait = new WebDriverWait(Pojo.getAndroidDriver(), timeInMiliSeconds);216 217 webDriverWait.until(ExpectedConditions.presenceOfElementLocated(locator));218 219 return Pojo.getAndroidDriver().findElement(locator).isDisplayed();220 } catch (Exception exception) {221 return false;222 }223 }224 225 226 @Override227 public boolean checkElementEnabled(By locator) {228 try {229 this.waitForElementVisibilityLocated(locator);230 // this.setHighlight(Pojo.getDriver().findElement(locator));231 return Pojo.getAndroidDriver().findElement(locator).isEnabled();232 } catch (Exception exception) {233 return false;234 }235 }236 237 238 @Override239 public boolean click(By locator) {240 try {241 //this.waitForElementPresence(locator);242 // this.waitForElementToBeClickable(locator);243 // this.setHighlight(Pojo.getDriver().findElement(locator));244 Pojo.getAndroidDriver().findElement(locator).click();245 return true;246 } catch (NoSuchElementException exception) {247 System.out.println("I got no such " + exception.getMessage());248 exception.printStackTrace();249 return false;250 } catch (TimeoutException exception) {251 System.out.println("I got timeout " + exception.getMessage());252 exception.printStackTrace();253 return false;254 } catch (NotFoundException exception) {255 System.out.println("I got timeout " + exception.getMessage());256 exception.printStackTrace();257 return false;258 } catch (ElementNotVisibleException exception) {259 System.out.println("I got timeout " + exception.getMessage());260 exception.printStackTrace();261 return false;262 } catch (ElementNotInteractableException exception) {263 System.out.println("I got timeout " + exception.getMessage());264 exception.printStackTrace();265 return false;266 } catch (Exception exception) {267 try {268 waitForElementPresence(locator);269 waitForElementToBeClickable(locator);270 Pojo.getAndroidDriver().findElement(locator).click(); 271 return true;272 } catch (Exception exceptionJavascript) {273 System.out.println("NoSuchElement Exception");274 return false;275 }276 }277 }278 279 @Override280 public boolean setText(By locator, String fieldValue) {281try {282 //this.setHighlight(Pojo.getDriver().findElement(locator));283 clearText(locator);284 // webElement.clear();285 Pojo.getAndroidDriver().findElement(locator).sendKeys(fieldValue);286 return true;287 } catch (NoSuchElementException exception) {288 System.out.println("I got no such " + exception.getMessage());289 exception.printStackTrace();290 return false;291 } catch (TimeoutException exception) {292 System.out.println("I got timeout " + exception.getMessage());293 exception.printStackTrace();294 return false;295 } catch (Exception exception) {296 System.out.println("NoSuchElement Exception");297 exception.printStackTrace();298 return false;299 }300 }301 302 303 @Override304 public void clearText(By locator) {305 Pojo.getAndroidDriver().findElement(locator).clear();306 307 }308 @Override309 public boolean mouseHover(By locator) {310 // TODO Auto-generated method stub311 return false;312 }313 314 315 @Override316 public boolean selectRadioButton(By locator, boolean status) {317 try {318 waitForElementPresence(locator);319 // this.setHighlight(Pojo.getDriver().findElement(locator));320 WebElement webElement = Pojo.getAndroidDriver().findElement(locator);321 if (webElement.getAttribute("class").contains("radio")) {322 if ((webElement.isSelected() && !status) || (!webElement.isSelected() && status))323 webElement.click();324 return true;325 } else326 return false;327 } catch (NoSuchElementException exception) {328 System.out.println("I got no such " + exception.getMessage());329 exception.printStackTrace();330 return false;331 } catch (TimeoutException exception) {332 System.out.println("I got timeout " + exception.getMessage());333 exception.printStackTrace();334 return false;335 } catch (NotFoundException exception) {336 System.out.println("I got timeout " + exception.getMessage());337 exception.printStackTrace();338 return false;339 } catch (ElementNotVisibleException exception) {340 System.out.println("I got timeout " + exception.getMessage());341 exception.printStackTrace();342 return false;343 } catch (ElementNotInteractableException exception) {344 System.out.println("I got timeout " + exception.getMessage());345 exception.printStackTrace();346 return false;347 } catch (ElementNotSelectableException exception) {348 System.out.println("I got timeout " + exception.getMessage());349 exception.printStackTrace();350 return false;351 } catch (Exception exception) {352 System.out.println("NoSuchElement Exception");353 exception.printStackTrace();354 return false;355 }356 }357 358 359 @Override360 public boolean isRadioButtonSelected(By locator) {361 boolean state = false;362 try {363 waitForElementPresence(locator);364 // this.setHighlight(Pojo.getDriver().findElement(locator));365 WebElement webElement = Pojo.getAndroidDriver().findElement(locator);366 if (webElement.getAttribute("class").contains("radio"))367 state = webElement.isSelected();368 return state;369 } catch (NoSuchElementException exception) {370 System.out.println("I got no such " + exception.getMessage());371 exception.printStackTrace();372 return false;373 } catch (TimeoutException exception) {374 System.out.println("I got timeout " + exception.getMessage());375 exception.printStackTrace();376 return false;377 } catch (NotFoundException exception) {378 System.out.println("I got timeout " + exception.getMessage());379 exception.printStackTrace();380 return false;381 } catch (ElementNotVisibleException exception) {382 System.out.println("I got timeout " + exception.getMessage());383 exception.printStackTrace();384 return false;385 } catch (ElementNotInteractableException exception) {386 System.out.println("I got timeout " + exception.getMessage());387 exception.printStackTrace();388 return false;389 } catch (ElementNotSelectableException exception) {390 System.out.println("I got timeout " + exception.getMessage());391 exception.printStackTrace();392 return false;393 } catch (Exception exception) {394 System.out.println("NoSuchElement Exception");395 exception.printStackTrace();396 return false;397 }398 }399 400 401 @Override402 public boolean checkElementNOTDisplayed(By locator) {403 try {404 this.waitForElementPresence(locator);405 return !(Pojo.getAndroidDriver().findElement(locator).isDisplayed());406 } catch (Exception e) {407 // e.printStackTrace();408 return true;409 }410 }411 412 413 @Override414 public String getText(By locator, String textBy) {415 String strText = "";416 try {417 //waitForElementPresence(locator);418 //this.setHighlight(Pojo.getDriver().findElement(locator));419 WebElement webElement = Pojo.getAndroidDriver().findElement(locator);420 switch (textBy.toLowerCase()) {421 case "value":422 strText = webElement.getAttribute("value");423 break;424 case "text":425 strText = webElement.getText();426 break;427 default:428 strText = webElement.getText();429 break;430 }431 } catch (NoSuchElementException exception) {432 System.out.println("I got no such " + exception.getMessage());433 exception.printStackTrace();434 } catch (TimeoutException exception) {435 System.out.println("I got timeout " + exception.getMessage());436 exception.printStackTrace();437 } catch (NotFoundException exception) {438 System.out.println("I got timeout " + exception.getMessage());439 exception.printStackTrace();440 } catch (ElementNotVisibleException exception) {441 System.out.println("I got timeout " + exception.getMessage());442 exception.printStackTrace();443 } catch (ElementNotInteractableException exception) {444 System.out.println("I got timeout " + exception.getMessage());445 exception.printStackTrace();446 } catch (Exception exception) {447 System.out.println("NoSuchElement Exception");448 exception.printStackTrace();449 }450 return strText;451 }452 453 @Override454 public String getText(By locator) {455 this.setHighlight(Pojo.getAndroidDriver().findElement(locator));456 String strText = "";457 strText=Pojo.getAndroidDriver().findElement(locator).getText();458 return strText;459 }460 461 462 @Override463 public boolean selectCheckBox(By locator, boolean status) {464 try {465 WebElement webElement=Pojo.getAndroidDriver().findElement(locator);466 waitForElementPresence(locator);467 // this.setHighlight(Pojo.getDriver().findElement(locator));468 if (webElement.getAttribute("type").equals("checkbox")) {469 if ((webElement.isSelected() && !status) || (!webElement.isSelected() && status))470 webElement.click();471 return true;472 } else473 return false;474 } catch (NoSuchElementException exception) {475 System.out.println("I got no such " + exception.getMessage());476 exception.printStackTrace();477 return false;478 } catch (TimeoutException exception) {479 System.out.println("I got timeout " + exception.getMessage());480 exception.printStackTrace();481 return false;482 } catch (NotFoundException exception) {483 System.out.println("I got timeout " + exception.getMessage());484 exception.printStackTrace();485 return false;486 } catch (ElementNotVisibleException exception) {487 System.out.println("I got timeout " + exception.getMessage());488 exception.printStackTrace();489 return false;490 } catch (ElementNotInteractableException exception) {491 System.out.println("I got timeout " + exception.getMessage());492 exception.printStackTrace();493 return false;494 } catch (ElementNotSelectableException exception) {495 System.out.println("I got timeout " + exception.getMessage());496 exception.printStackTrace();497 return false;498 } catch (Exception exception) {499 exception.printStackTrace();500 return false;501 }502 }503 @Override504 public boolean isCheckBoxSelected(By locator) {505 boolean state = false;506 try {507 waitForElementPresence(locator);508 // this.setHighlight(Pojo.getDriver().findElement(locator));509 WebElement webElement = Pojo.getAndroidDriver().findElement(locator);510 if (webElement.getAttribute("type").equals("checkbox"))511 state = webElement.isSelected();512 return state;513 } catch (NoSuchElementException exception) {514 System.out.println("I got no such " + exception.getMessage());515 exception.printStackTrace();516 return false;517 } catch (TimeoutException exception) {518 System.out.println("I got timeout " + exception.getMessage());519 exception.printStackTrace();520 return false;521 } catch (NotFoundException exception) {522 System.out.println("I got timeout " + exception.getMessage());523 exception.printStackTrace();524 return false;525 } catch (ElementNotVisibleException exception) {526 System.out.println("I got timeout " + exception.getMessage());527 exception.printStackTrace();528 return false;529 } catch (ElementNotInteractableException exception) {530 System.out.println("I got timeout " + exception.getMessage());531 exception.printStackTrace();532 return false;533 } catch (ElementNotSelectableException exception) {534 System.out.println("I got timeout " + exception.getMessage());535 exception.printStackTrace();536 return false;537 } catch (Exception exception) {538 System.out.println("NoSuchElement Exception");539 return false;540 }541 }542 543 @Override544 public void setHighlight(WebElement element) {545 546 }547 @Override548 public boolean pageRefresh() { //Only for web view. Not for native app549try {550 551 Pojo.getAndroidDriver().navigate().refresh();552 return true;553 } catch (Exception exception) {554 555 exception.getMessage();556 return false;557 }558 559 }560 @Override561 public void deleteAllBrowserCookies() {562 // TODO Auto-generated method stub563 564 }565 566 567 @Override568 public boolean scrollToView(By locator) {569 // TODO Auto-generated method stub570 return false;571 }572 @Override573 public String getTextByUsingJavaScripts(By locator) {574 // TODO Auto-generated method stub575 return null;576 }577 @Override578 public boolean scrollToView(WebElement webElement) {579 // TODO Auto-generated method stub580 return false;581 }582 583 @Override584 public String getText(WebElement webElement) {585 // TODO Auto-generated method stub586 return null;587 }588 589 590 @Override591 public String getAttribute(By locator, String sElementAttribute) {592 try {593 waitForElementPresence(locator);594 WebElement webElement = Pojo.getAndroidDriver().findElement(locator);595 return webElement.getAttribute(sElementAttribute);596 } catch (Exception exception) {597 exception.printStackTrace();598 return null;599 }600 }601 602 @Override603 public boolean clickUsingActionClass(By locator) {604 // TODO Auto-generated method stub605 return false;606 }607 @Override608 public String getCSSValue(By locator, String attributeName) {609 // TODO Auto-generated method stub610 return null;611 }612 @Override613 public List<WebElement> getWebElementList(By locator) {614 return null;615 // TODO Auto-generated method stub616 617 }618 619 620 @Override621 public boolean closeBrowserEnvironment() {622 // TODO Auto-generated method stub623 return false;624 }625 @SuppressWarnings("deprecation")626 @Override627 public boolean navigateToBack() {628 try629 {630 Pojo.getAndroidDriver().pressKeyCode(AndroidKeyCode.BACK);631 return true;632 }633 catch(Exception exception)634 {635 return false;636 }637 }638 @Override639 public boolean mouseHover(WebElement webElement) {640 // TODO Auto-generated method stub641 return false;642 }643 @Override644 public boolean openNewTabInSameBrowser(String pageUrl) {645 // TODO Auto-generated method stub646 return false;647 }648 @Override649 public boolean switchToWindowUsingTitle(String windowTitle) {650 // TODO Auto-generated method stub651 return false;652 }653 @Override654 public boolean switchToWindowContainsURL(String windowURL) {655 // TODO Auto-generated method stub656 return false;657 }658 @Override659 public String getCurrentURL() {660 // TODO Auto-generated method stub661 return null;662 }663 @Override664 public String getLatestDownloadedFileName() {665 // TODO Auto-generated method stub666 return null;667 }668 669 @Override670 public boolean scrollToDown(By locator) {671 // TODO Auto-generated method stub672 return false;673 }674 @Override675 public boolean closeBrowserAndAppEnv() {676 // TODO Auto-generated method stub677 return false;678 }679 @Override680 public boolean launchMobileApplication() {681 // TODO Auto-generated method stub682 return false;683 }684 @Override685 public boolean switchContextToHybridApp() {686 try {687 Set<String> contextNames = Pojo.getAndroidDriver().getContextHandles();688 for (String contextName : contextNames) {689 System.out.println(contextName);// prints out something like NATIVE_APP \n WEBVIEW_1690 }691 Pojo.getAndroidDriver().context((String) contextNames.toArray()[1]);692 System.out.println("Hybrid");693 return true;694 }695 catch(Exception e)696 {697 return false;698 }699 }700 @Override701 public boolean switchWindowByUsingWindowHandles() {702 // TODO Auto-generated method stub703 return false;704 }705 @Override706 public boolean switchToDefaultContent() {707 // TODO Auto-generated method stub708 return false;709 }710 @Override711 public boolean tap(By locator) {712 try713 {714 WebElement e=Pojo.getAndroidDriver().findElement(locator);715 TouchAction t=new TouchAction(Pojo.getAndroidDriver());716 t.tap(tapOptions().withElement(element(e))).perform();717 return true;718 }719 catch (Exception e)720 {721 return false;722 }723 }724 @Override725 public boolean longPress(By locator) {726 try727 {728 WebElement e=Pojo.getAndroidDriver().findElement(locator);729 TouchAction t=new TouchAction(Pojo.getAndroidDriver());730 t.longPress(longPressOptions().withElement(element(e)).withDuration(ofSeconds(2))).release().perform();731 return true;732 }733 catch (Exception e)734 {735 return false;736 }737 }738 739 @Override740 public boolean swipe(By locator1, By locator2) {741 try {742 WebElement first=Pojo.getAndroidDriver().findElement(locator1);743 WebElement second=Pojo.getAndroidDriver().findElement(locator2);744 TouchAction t=new TouchAction(Pojo.getAndroidDriver());745 t.longPress(longPressOptions().withElement(element(first)).withDuration(ofSeconds(2))).moveTo(element(second)).release().perform();746 return true;747 }748 catch (Exception e)749 {750 return false;751 }752 }753 754 755 @Override756 public boolean selectRadioButtonByTypeIsRadio(By locator, boolean status) {757 try {758 waitForElementPresence(locator);759 WebElement webElement = Pojo.getAndroidDriver().findElement(locator);760 if (webElement.getAttribute("type").equals("radio")) {761 if ((webElement.isSelected() && !status) || (!webElement.isSelected() && status))762 this.click(locator);763 return true;764 } else765 return false;766 } catch (Exception exception) {767 exception.printStackTrace();768 return false;769 }770 }771 @Override772 public boolean mouseHoverUsingJavaScript(WebElement webElement) {773 // TODO Auto-generated method stub774 return false;775 }776 777 @Override778 public boolean selectCheckBoxByClassIsCheckBox(By locator, boolean status) {779 try {780 waitForElementPresence(locator);781 //this.setHighlight(Pojo.getDriver().findElement(locator));782 WebElement webElement = Pojo.getAndroidDriver().findElement(locator);783 if (webElement.getAttribute("class").contains("checkbox")) {784 if ((webElement.isSelected() && !status) || (!webElement.isSelected() && status))785 webElement.click();786 return true;787 } else788 return false;789 } catch (NoSuchElementException exception) {790 System.out.println("I got no such " + exception.getMessage());791 exception.printStackTrace();792 return false;793 } catch (TimeoutException exception) {794 System.out.println("I got timeout " + exception.getMessage());795 exception.printStackTrace();796 return false;797 } catch (NotFoundException exception) {798 System.out.println("I got timeout " + exception.getMessage());799 exception.printStackTrace();800 return false;801 } catch (ElementNotVisibleException exception) {802 System.out.println("I got timeout " + exception.getMessage());803 exception.printStackTrace();804 return false;805 } catch (ElementNotInteractableException exception) {806 System.out.println("I got timeout " + exception.getMessage());807 exception.printStackTrace();808 return false;809 } catch (ElementNotSelectableException exception) {810 System.out.println("I got timeout " + exception.getMessage());811 exception.printStackTrace();812 return false;813 } catch (Exception exception) {814 exception.printStackTrace();815 return false;816 }817 }818 819 @Override820 public String getTitle() {821 // TODO Auto-generated method stub822 return null;823 }824 @Override825 public String getTestData(int rowNum, int colNum, DataTable table) {826 List<List<String>> data=table.asLists();827 String userData=data.get(rowNum).get(colNum);828 829 return userData;830 }831 832 833 @Override834 public WebElement getElementFluent(By locator) throws NoSuchElementException, TimeoutException {835 System.out.println(" **************** into getElementFluent");836 Wait<AndroidDriver> wait = new FluentWait<AndroidDriver>(Pojo.getAndroidDriver())837 .withTimeout(Duration.ofSeconds(Long.parseLong(Pojo.getObjConfig().getProperty("driver.WebDriverWait"))))838 .pollingEvery(Duration.ofSeconds(Long.parseLong(Pojo.getObjConfig().getProperty("driver.FluentWaiPulling"))))839 .ignoring(NoSuchElementException.class);840 WebElement webElement = wait.until(new Function<AndroidDriver, WebElement>() {841 public WebElement apply(AndroidDriver driver) {842 return Pojo.getAndroidDriver().findElement(locator);843 }844 });845 return webElement;846 }847 848 849 850 @Override851 public WebElement getNestedElementFluent(WebElement parentWebElement, By locator)852 throws NoSuchElementException, TimeoutException {853 // System.out.println("**************** into getNestedElementFluent");854 Wait<AndroidDriver> wait = new FluentWait<AndroidDriver>(Pojo.getAndroidDriver())855 .withTimeout(Duration.ofSeconds(Long.parseLong(Pojo.getObjConfig().getProperty("driver.WebDriverWait"))))856 .pollingEvery(Duration.ofSeconds(Long.parseLong(Pojo.getObjConfig().getProperty("driver.FluentWaiPulling"))))857 .ignoring(NoSuchElementException.class);858 WebElement webElement = wait.until(new Function<AndroidDriver, WebElement>() {859 public WebElement apply(AndroidDriver driver) {860 return parentWebElement.findElement(locator);861 }862 });863 return webElement;864 }865 @Override866 public WebElement getElementFluent(WebElement webElement) throws NoSuchElementException, TimeoutException {867System.out.println(" **************** into getElementFluent");868 869 Wait<AndroidDriver> wait = new FluentWait<AndroidDriver>(Pojo.getAndroidDriver())870 .withTimeout(Duration.ofSeconds(Long.parseLong(Pojo.getObjConfig().getProperty("driver.WebDriverWait"))))871 .pollingEvery(Duration.ofSeconds(Long.parseLong(Pojo.getObjConfig().getProperty("driver.FluentWaiPulling"))))872 .ignoring(NoSuchElementException.class);873 WebElement weElement = wait.until(new Function<AndroidDriver, WebElement>() {874 public WebElement apply(AndroidDriver driver) {875 return webElement;876 }877 });878 return webElement;879 }880 881 882 @Override883 public boolean verifyElementDisplay(By locator) {884 try {885 Pojo.getAndroidDriver().manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 886 Pojo.getAndroidDriver().findElement(locator).isDisplayed();887 return true;888 }889 catch(NoSuchElementException e){890 return false;891 }892 catch(Exception e)893 {894 return false;895 }896 finally897 {898 Pojo.getAndroidDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 899 }900 }901 @Override902 public String getTextNode(By locator, int nodeIndex) {903 // TODO Auto-generated method stub904 return null;905 }906 @Override907 public boolean androidScroll(String textToView) {908 909 try910 {911 Pojo.getObjSeleniumFunctions().waitFor(2);912 String text="\""+textToView+"\""+"";913 // Pojo.getAndroidDriver().findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().textContains(\""+textToView+"\").instance(0))");914 Pojo.getAndroidDriver().findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().text(\""+textToView+"\").instance(0))");915 return true;916 }917 catch(Exception e)918 {919 return false;920 }921 }922 @Override923 public boolean switchContextToNativeApp() { 924 try{925 Set<String> contextNames = Pojo.getAndroidDriver().getContextHandles();926 for (String contextName : contextNames) {927 System.out.println(contextName);// prints out something like NATIVE_APP \n WEBVIEW_1928 }929 Pojo.getAndroidDriver().context((String) contextNames.toArray()[0]);930 System.out.println("Native");931 return true;932 }933 catch (Exception e)934 {935 return false;936 }937 }938 @Override939 public boolean hideKeyBoard() {940 try {941 Pojo.getAndroidDriver().hideKeyboard();942 return true;943 }944 catch(Exception e)945 {946 return false;947 }948 }949 @Override950 public String getToastMessage(By locator,String attributeName) { //name attribute for toast messages will have toast message content951 String toastMessage=Pojo.getAndroidDriver().findElement(locator).getAttribute(attributeName);952 return toastMessage;953 }954 @Override955 public boolean androidScrollToScrollableElement(String resourceId, String textToView) {956 try957 {958 String text="\""+textToView+"\""+"";959 String resourceIdConverted="\""+resourceId+"\""+"";960 Pojo.getAndroidDriver().findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().resourceId("+resourceIdConverted+")).scrollIntoView(new UiSelector().text("+text+").instance(0));");//remove instance if it does not work. There is no intance in appium documentation961 Pojo.getObjSeleniumFunctions().waitFor(5);962 return true;963 964 }965 catch(Exception e)966 {967 return false;968 }969 }970 @Override971 public String getTextByXpath(String text) {972 By loc_text=By.xpath("//android.widget.TextView[contains(@text, '"+text+"')]");973 String actualText=Pojo.getAndroidDriver().findElement(loc_text).getText();974 return actualText;975 }976 @Override977 public String getTextByAccessibilityIdTest(String IdText) {978 String text=Pojo.getAndroidDriver().findElement(MobileBy.AccessibilityId(IdText)).getText().trim();979 return text;980 }981 @Override982 public boolean landscapeRightRotation() {983 try {984 DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 90);985 Pojo.getAndroidDriver().rotate(landscapeRightRotation);986 return true;987 }988 catch(Exception e)989 {990 return false;991 }992 }993 @Override994 public boolean landscapeLeftRotation() {995 try996 {997 DeviceRotation landscapeLeftRotation = new DeviceRotation(0, 0, 270);998 Pojo.getAndroidDriver().rotate(landscapeLeftRotation);999 return true;1000 }1001 catch(Exception e)1002 {1003 return false;1004 }1005 }1006 @Override1007 public boolean portraitUpsideDown() {1008 try {1009 DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 180);1010 Pojo.getAndroidDriver().rotate(landscapeRightRotation); 1011 return true;1012 }1013 catch(Exception e)1014 {1015 return false;1016 }1017 }1018 @Override1019 public boolean openNotification() {1020 try1021 {1022 Pojo.getAndroidDriver().closeApp();1023 Pojo.getAndroidDriver().openNotifications();1024 return true;1025 }1026 catch(Exception e)1027 {1028 return false;1029 }1030 1031 1032 }1033 @Override1034 public boolean setClipBoardText(String text) {1035 try1036 {1037 final String textSet=text;1038 Pojo.getAndroidDriver().setClipboardText(textSet);1039 return true;1040 }1041 catch(Exception e)1042 {1043 return false;1044 }1045 }1046 @Override1047 public String getClipBoardText() {1048 String clipBoardText=Pojo.getAndroidDriver().getClipboardText();1049 return clipBoardText;1050 }1051 @Override1052 public boolean screenRecordRealDevice(int durationSec) throws InterruptedException {1053 try {1054 ((CanRecordScreen) Pojo.getDriver()).startRecordingScreen(new AndroidStartScreenRecordingOptions()1055 .withTimeLimit(Duration.ofSeconds(durationSec)));1056 Thread.sleep(5000);1057 Pojo.getAndroidDriver().stopRecordingScreen();1058 1059 return true;1060 }1061 catch(WebDriverException e)1062 {1063 return false;1064 }1065 1066 1067 }1068 @Override1069 public boolean gsmCallTest() {1070 try {1071 ((SupportsSpecialEmulatorCommands) Pojo.getDriver()).makeGsmCall("11111111", GsmCallActions.CALL);1072 ((SupportsSpecialEmulatorCommands) Pojo.getDriver()).makeGsmCall("11111111", GsmCallActions.ACCEPT);1073 return true;1074 } catch (Exception e) {1075 return false;1076 }1077 }1078 1079 @Override1080 public boolean toggleWiFi() {1081 try {1082 ((SupportsNetworkStateManagement) Pojo.getDriver()).toggleWifi();1083 return true;1084 } catch (Exception e) {1085 return false;1086 }1087 }1088 1089 1090 @Override1091 public boolean toggleAirPlane() {1092 // TODO Auto-generated method stub1093 try {1094 ((SupportsNetworkStateManagement) Pojo.getDriver()).toggleAirplaneMode();1095 return true;1096 } catch (Exception e) {1097 return false;1098 }1099 1100 }1101 @Override1102 public boolean setNetworkSpeedTest() {1103 try {1104 ((SupportsSpecialEmulatorCommands) Pojo.getDriver()).setNetworkSpeed(NetworkSpeed.EDGE);1105 return true;1106 } catch (Exception e) {1107 return false;1108 }1109 }1110 1111 @Override1112 public ScreenOrientation getOrientation() {1113 ScreenOrientation orientation=Pojo.getAndroidDriver().getOrientation();1114 return orientation;1115 }1116 @Override1117 public boolean lockDevice() {1118 try...

Full Screen

Full Screen

AndroidDriver.java

Source:AndroidDriver.java Github

copy

Full Screen

...59 implements PressesKey, HasNetworkConnection, PushesFiles, StartsActivity,60 FindsByAndroidUIAutomator<T>, FindsByAndroidViewTag<T>, FindsByAndroidDataMatcher<T>,61 FindsByAndroidViewMatcher<T>, LocksDevice, HasAndroidSettings, HasAndroidDeviceDetails,62 HasSupportedPerformanceDataType, AuthenticatesByFinger, HasOnScreenKeyboard,63 CanRecordScreen, SupportsSpecialEmulatorCommands,64 SupportsNetworkStateManagement, ListensToLogcatMessages, HasAndroidClipboard,65 HasBattery<AndroidBatteryInfo>, ExecuteCDPCommand {66 private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID;67 private StringWebSocketClient logcatClient;68 /**69 * Creates a new instance based on command {@code executor} and {@code capabilities}.70 *71 * @param executor is an instance of {@link HttpCommandExecutor}72 * or class that extends it. Default commands or another vendor-specific73 * commands may be specified there.74 * @param capabilities take a look at {@link Capabilities}75 */76 public AndroidDriver(HttpCommandExecutor executor, Capabilities capabilities) {77 super(executor, updateDefaultPlatformName(capabilities, ANDROID_PLATFORM));...

Full Screen

Full Screen

SupportsSpecialEmulatorCommands.java

Source:SupportsSpecialEmulatorCommands.java Github

copy

Full Screen

...7import static io.appium.java_client.android.AndroidMobileCommandHelper.powerCapacityCommand;8import static io.appium.java_client.android.AndroidMobileCommandHelper.sendSMSCommand;9import io.appium.java_client.CommandExecutionHelper;10import io.appium.java_client.ExecutesMethod;11public interface SupportsSpecialEmulatorCommands extends ExecutesMethod {12 /**13 * Emulate send SMS event on the connected emulator.14 *15 * @param phoneNumber The phone number of message sender.16 * @param message The message content.17 */18 default void sendSMS(String phoneNumber, String message) {19 CommandExecutionHelper.execute(this, sendSMSCommand(phoneNumber, message));20 }21 /**22 * Emulate GSM call event on the connected emulator.23 *24 * @param phoneNumber The phone number of the caller.25 * @param gsmCallActions One of available {@link GsmCallActions} values....

Full Screen

Full Screen

SendSms.java

Source:SendSms.java Github

copy

Full Screen

...13import io.appium.java_client.AppiumDriver;14import io.appium.java_client.android.AndroidDriver;15import io.appium.java_client.android.AndroidElement;16import io.appium.java_client.android.AndroidTouchAction;17import io.appium.java_client.android.SupportsSpecialEmulatorCommands;18import io.appium.java_client.remote.MobileCapabilityType;19import io.appium.java_client.touch.WaitOptions;20import io.appium.java_client.touch.offset.ElementOption;21import io.appium.java_client.touch.offset.PointOption;22public class SendSms {23 public AndroidDriver driver;24 @BeforeTest25 public void setUp() throws MalformedURLException {26 DesiredCapabilities capabilities = new DesiredCapabilities();27 capabilities.setCapability("platformName", "Android");28 capabilities.setCapability("platformVersion", "6.0");29 capabilities.setCapability("deviceName", "4TE0216714003365");30 capabilities.setCapability("appPackage", "com.android.mms");31 capabilities.setCapability("appActivity", "com.android.mms.ui.ConversationList");...

Full Screen

Full Screen

SupportsSpecialEmulatorCommands

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.android.SupportsSpecialEmulatorCommands;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.android.AndroidElement;4import java.net.URL;5import org.openqa.selenium.remote.DesiredCapabilities;6import org.testng.annotations.AfterTest;7import org.testng.annotations.BeforeTest;8import org.testng.annotations.Test;9public class AppiumTest {10 private AndroidDriver<AndroidElement> driver;11 private SupportsSpecialEmulatorCommands emulatorCommands;12 public void setUp() throws Exception {13 DesiredCapabilities capabilities = new DesiredCapabilities();14 capabilities.setCapability("deviceName", "Android Emulator");15 capabilities.setCapability("platformName", "Android");16 capabilities.setCapability("platformVersion", "7.1.1");17 capabilities.setCapability("appPackage", "com.android.calculator2");18 capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");

Full Screen

Full Screen

SupportsSpecialEmulatorCommands

Using AI Code Generation

copy

Full Screen

1driver.pressKeyCode(AndroidKeyCode.HOME);2driver.pressKeyCode(AndroidKeyCode.HOME);3driver.pressKeyCode(AndroidKeyCode.HOME);4driver.pressKeyCode(AndroidKeyCode.HOME);5driver.pressKeyCode(AndroidKeyCode.HOME);6driver.pressKeyCode(AndroidKeyCode.HOME);7driver.pressKeyCode(AndroidKeyCode.HOME);8driver.pressKeyCode(AndroidKeyCode.HOME);9driver.pressKeyCode(AndroidKeyCode.HOME);10driver.pressKeyCode(AndroidKeyCode.HOME);11driver.pressKeyCode(AndroidKeyCode.HOME);12driver.pressKeyCode(AndroidKeyCode.HOME);13driver.pressKeyCode(AndroidKeyCode.HOME);14driver.pressKeyCode(AndroidKeyCode.HOME);15driver.pressKeyCode(AndroidKeyCode.HOME);16driver.pressKeyCode(AndroidKeyCode.HOME);17driver.pressKeyCode(AndroidKeyCode.HOME);18driver.pressKeyCode(AndroidKeyCode.HOME);

Full Screen

Full Screen

SupportsSpecialEmulatorCommands

Using AI Code Generation

copy

Full Screen

1driver.installApp("path to the app");2driver.removeApp("package name of the app");3driver.install_app("path to the app")4driver.remove_app("package name of the app")5driver.install_app("path to the app")6driver.remove_app("package name of the app")7driver.installApp("path to the app");8driver.removeApp("package name of the app");9$driver->installApp("path to the app");10$driver->removeApp("package name of the app");11driver.installApp("path to the app")12driver.removeApp("package name of the app")13driver.InstallApp("path to the app");14driver.RemoveApp("package name of the app");15driver.InstallApp("path to the app")16driver.RemoveApp("package name of the app")17$driver.InstallApp("path to the app")18$driver.RemoveApp("package name of the app")19driver.installApp("path to the app")20driver.removeApp("package name of the app")21driver.install_app("path to the app")22driver.remove_app("package name of the app")23driver.installApp("path to the app");

Full Screen

Full Screen

SupportsSpecialEmulatorCommands

Using AI Code Generation

copy

Full Screen

1driver.installApp("C:\\Users\\Downloads\\app-debug.apk");2driver.removeApp("com.example.app");3driver.isAppInstalled("com.example.app");4driver.launchApp();5driver.closeApp();6driver.resetApp();7driver.terminateApp("com.example.app");8driver.startActivity("com.example.app", ".MainActivity");9driver.backgroundApp(3);10driver.runAppInBackground(3);11driver.installApp("C:\\Users\\Downloads\\app-debug.apk");12driver.removeApp("com.example.app");13driver.isAppInstalled("com.example.app");14driver.launchApp();15driver.closeApp();16driver.resetApp();17driver.terminateApp("com.example.app");18driver.startActivity("com.example.app", ".MainActivity");19driver.backgroundApp(3);20driver.runAppInBackground(3);21driver.install_app("C:\\Users\\Downloads\\app-debug.apk")22driver.remove_app("com.example.app")23driver.is_app_installed("com.example.app")24driver.launch_app()25driver.close_app()26driver.reset_app()27driver.terminate_app("com.example.app")28driver.start_activity("com.example.app", ".MainActivity")29driver.background_app(3)30driver.run_app_in_background(3)31driver.install_app("C:\\Users\\Downloads\\app-debug.apk")32driver.remove_app("com.example.app")33driver.is_app_installed("com.example.app")34driver.launch_app()35driver.close_app()36driver.reset_app()37driver.terminate_app("com.example.app")38driver.start_activity("com.example.app", ".MainActivity")39driver.background_app(3)40driver.run_app_in_background(3)41$driver->installApp("C:\\Users\\Downloads\\app-debug.apk");42$driver->removeApp("com.example.app");43$driver->isAppInstalled("com.example.app");44$driver->launchApp();45$driver->closeApp();46$driver->resetApp();47$driver->terminateApp("com.example.app");48$driver->startActivity("com.example.app", ".MainActivity");49$driver->backgroundApp(3);

Full Screen

Full Screen

SupportsSpecialEmulatorCommands

Using AI Code Generation

copy

Full Screen

1AndroidDriver driver = new AndroidDriver();2SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;3emulator.unlockDevice();4AndroidDriver driver = new AndroidDriver();5SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;6emulator.lockDevice();7AndroidDriver driver = new AndroidDriver();8SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;9emulator.toggleData();10AndroidDriver driver = new AndroidDriver();11SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;12emulator.toggleWiFi();13AndroidDriver driver = new AndroidDriver();14SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;15emulator.toggleAirplaneMode();16AndroidDriver driver = new AndroidDriver();17SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;18emulator.toggleLocationServices();19AndroidDriver driver = new AndroidDriver();20SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;21emulator.toggleNetworkSpeed();22AndroidDriver driver = new AndroidDriver();23SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;24emulator.togglePower();25AndroidDriver driver = new AndroidDriver();

Full Screen

Full Screen

SupportsSpecialEmulatorCommands

Using AI Code Generation

copy

Full Screen

1SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;2emulator.installApp("C:\\Users\\Rahul\\Downloads\\app-debug.apk");3SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;4emulator.installApp("C:\\Users\\Rahul\\Downloads\\app-debug.apk");5SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;6emulator.installApp("C:\\Users\\Rahul\\Downloads\\app-debug.apk");7SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;8emulator.installApp("C:\\Users\\Rahul\\Downloads\\app-debug.apk");9SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;10emulator.installApp("C:\\Users\\Rahul\\Downloads\\app-debug.apk");11SupportsSpecialEmulatorCommands emulator = (SupportsSpecialEmulatorCommands) driver;12emulator.installApp("C:\\Users\\Rahul\\Downloads\\app-debug.apk");

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