How to use MobileBy.ByAndroidUIAutomator class of io.appium.java_client package

Best io.appium code snippet using io.appium.java_client.MobileBy.ByAndroidUIAutomator

NativeDialerApplicationAutomation.java

Source:NativeDialerApplicationAutomation.java Github

copy

Full Screen

1package com.example.dialpadautomation;2import io.appium.java_client.AppiumDriver;3import io.appium.java_client.MobileBy;4import io.appium.java_client.MobileElement;5import io.appium.java_client.TouchAction;6import io.appium.java_client.remote.MobileCapabilityType;7import io.appium.java_client.touch.LongPressOptions;8import io.appium.java_client.touch.offset.ElementOption;9import org.openqa.selenium.By;10import org.openqa.selenium.interactions.touch.TouchActions;11import org.openqa.selenium.remote.CapabilityType;12import org.openqa.selenium.remote.DesiredCapabilities;13import org.testng.Assert;14import org.testng.annotations.AfterTest;15import org.testng.annotations.BeforeTest;16import org.testng.annotations.Test;17import java.net.MalformedURLException;18import java.net.URL;19import java.util.concurrent.TimeUnit;20public class NativeDialerApplicationAutomation {21 // This will show you Focused App in Your Emulator :22 // adb shell "dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'"23 AppiumDriver<MobileElement> appium_Driver;24 @BeforeTest25 public void settingEnvironment() throws MalformedURLException {26 // Created object of DesiredCapabilities class.27 DesiredCapabilities capabilities = new DesiredCapabilities();28 // Set android deviceName desired capability. Set your device name.29 capabilities.setCapability("deviceName", "emulator-5554");30 // Set BROWSER_NAME desired capability. It's Android in our case here.31 //capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");32 // Set android VERSION desired capability. Set your mobile device's OS version.33 capabilities.setCapability(CapabilityType.VERSION, "7.1.1");34 // Set android platformName desired capability. It's Android in our case here.35 capabilities.setCapability("platformName", "Android");36 // Set android appPackage desired capability. It is37 // com.android.calculator2 for calculator application.38 // Set your application's appPackage if you are using any other app.39 capabilities.setCapability("appPackage", "com.android.dialer");40 // Set android appActivity desired capability. It is41 // com.android.calculator2.Calculator for calculator application.42 // Set your application's appPackage if you are using any other app.43 capabilities.setCapability("appActivity", "com.android.dialer.DialtactsActivity");44 //capabilities.setCapability(MobileCapabilityType.FULL_RESET, true);45 // Created object of RemoteWebDriver will all set capabilities.46 // Set appium server address and port number in URL string.47 // It will launch calculator app in android device.48 appium_Driver = new AppiumDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);49 appium_Driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);50 }51 @Test52 public void CommencingTest(){53// try{54//55// //appium_Driver.back();56// appium_Driver.navigate().back();57//58// } catch (Exception ex){59// System.out.println(ex.getCause());60// }61 appium_Driver.findElement(By.id("com.android.dialer:id/floating_action_button")).click();62// appium_Driver.findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.FrameLayout" +63// "/android.widget.FrameLayout/android.widget.LinearLayout/android.support.v4.view.ViewPager/android.widget.FrameLayout")).click();64 //appium_Driver.findElement(By.name("+")).click();65 //appium_Driver.findElementByAccessibilityId("+").click();66 //appium_Driver.findElementsById("com.android.dialer:id/dialpad_key_letters").get(8).click();67 //appium_Driver.findElement(By.id("com.android.dialer:id/digits")).sendKeys("+");68 //appium_Driver.findElementsById("com.android.dialer:id/dialpad_key_number").get(10).click();69// 11170 //appium_Driver.findElement(MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"+\")"));71 //appium_Driver.findElement(MobileBy.ByAndroidUIAutomator("new UiSelector().className("android.widget.TextView").text(+)")).click();72 //appium_Driver.findElement(MobileBy.ByAndroidUIAutomator("new UiSelector().text(( "+" ))")).click();73 //appium_Driver.findElement(ByElementText("text value"))74 //appium_Driver.findElement(By.tagName("+")).click();75// String selector = "new UiSelector().text(“+”))";76// appium_Driver.findElement(MobileBy.AndroidUIAutomator(selector)).click();77 //TouchActions longClick = new TouchActions(appium_Driver);78 TouchAction longClick = new TouchAction(appium_Driver);79 //longClick.longPress(appium_Driver.findElementById("com.android.dialer:id/zero")).perform();80 //MobileElement mobileElement = appium_Driver.findElement(MobileBy.id("com.android.dialer:id/zero"));81 MobileElement mobileElement = appium_Driver.findElementById("com.android.dialer:id/zero");82 //longClick.longPress(mobileElement).release().perform();83 longClick.longPress(LongPressOptions.longPressOptions().84 withElement(ElementOption.element(mobileElement))).release().perform(); // Using longPress85 //appium_Driver.findElement(By.xpath("//android.widget.TextView[@text='+']")).click(); // Using sendKeys86 appium_Driver.findElement(By.id("com.android.dialer:id/eight")).click();87 appium_Driver.findElement(By.id("com.android.dialer:id/eight")).click();88 appium_Driver.findElement(By.id("com.android.dialer:id/zero")).click();89 appium_Driver.findElement(By.id("com.android.dialer:id/one")).click();90 appium_Driver.findElement(By.id("com.android.dialer:id/nine")).click();91 appium_Driver.findElement(By.id("com.android.dialer:id/one")).click();92 appium_Driver.findElement(By.id("com.android.dialer:id/five")).click();93 appium_Driver.findElement(By.id("com.android.dialer:id/six")).click();94 appium_Driver.findElement(By.id("com.android.dialer:id/four")).click();95 appium_Driver.findElement(By.id("com.android.dialer:id/five")).click();96 appium_Driver.findElement(By.id("com.android.dialer:id/zero")).click();97 appium_Driver.findElement(By.id("com.android.dialer:id/nine")).click();98 appium_Driver.findElement(By.id("com.android.dialer:id/three")).click();99 //appium_Driver.findElement(By.id("com.android.dialer:id/dialpad_key_number")).click();100 //appium_Driver.findElement(By.id("com.android.dialer:id/dialpad")).click();101 appium_Driver.findElement(By.id("com.android.dialer:id/dialpad_floating_action_button")).click();102 appium_Driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);103 appium_Driver.findElementById("android:id/button1").click();104// try{105//106//107// //appium_Driver.findElementById("android:id/button1").click();108// appium_Driver.findElement(By.id("com.android.dialer:id/dialpad_floating_action_button")).click();109// //appium_Driver.findElement(By.id("com.android.dialer:id/endButton")).click();110//111// } catch (Exception ex){112//113// System.out.println(ex.getCause());114// }115// appium_Driver.closeApp();116// System.out.println("App Closed");117 }118 @AfterTest119 public void tearDown(){120 appium_Driver.quit();121 System.out.print("Test Completed");122 }123}...

Full Screen

Full Screen

Elements.java

Source:Elements.java Github

copy

Full Screen

1package utils;2/**3 * Created by dinkark on 30-Sep-20164 */5import java.util.ArrayList;6import java.util.HashMap;7import java.util.List;8import org.junit.Assert;9import org.openqa.selenium.By;10import io.appium.java_client.AppiumDriver;11import io.appium.java_client.MobileBy.ByAndroidUIAutomator;12import io.appium.java_client.MobileBy.ByIosUIAutomation;13import io.appium.java_client.MobileElement;14public class Elements {15 public static MobileElement find(HashMap<String, String> params, AppiumDriver<MobileElement> Driver) {16 Assert.assertNotNull("Error Emulator is not opened. Use Launch Emulator action.", Driver);17 MobileElement foundElement = null;18 if (params.get(Constants.APP_TYPE).equals(Constants.ANDROID)) {19 switch (params.get(Constants.ID_TYPE)) {20 case Constants.CLASS_NAME:21 foundElement = Driver.findElement(ByAndroidUIAutomator.className(params.get(Constants.ID)));22 break;23 case Constants.ID:24 foundElement = Driver.findElement(ByAndroidUIAutomator.id(params.get(Constants.ID)));25 break;26 case Constants.XPATH:27 foundElement = Driver.findElement(ByAndroidUIAutomator.xpath(params.get(Constants.ID)));28 break;29 case Constants.ANDROID_UI_AUTOMATOR:30 foundElement = Driver.findElement(ByAndroidUIAutomator.AndroidUIAutomator(params.get(Constants.ID)));31 break;32 case Constants.NAME:33 String xpath = ".//*[contains(@text,'" + params.get(Constants.ID) + "')]";34 foundElement = Driver.findElement(ByAndroidUIAutomator.xpath(xpath));35 break;36 default:37 foundElement = Driver.findElement(ByAndroidUIAutomator.id(params.get(Constants.ID)));38 }39 return foundElement;40 } else if (params.get(Constants.APP_TYPE).equals(Constants.IOS)) {41 switch (params.get(Constants.ID_TYPE)) {42 case Constants.CLASS_NAME:43 foundElement = Driver.findElement(ByIosUIAutomation.className(params.get(Constants.ID)));44 break;45 case Constants.ID:46 foundElement = Driver.findElement(ByIosUIAutomation.id(params.get(Constants.ID)));47 break;48 case Constants.XPATH:49 foundElement = Driver.findElement(ByIosUIAutomation.xpath(params.get(Constants.ID)));50 break;51 case Constants.IOS_UI_AUTOMATOR:52 foundElement = Driver.findElement(ByIosUIAutomation.IosUIAutomation(params.get(Constants.ID)));53 break;54 default:55 foundElement = Driver.findElement(ByIosUIAutomation.id(params.get(Constants.ID)));56 }57 return foundElement;58 } else {59 switch (params.get(Constants.ID_TYPE)) {60 case Constants.CLASS_NAME:61 foundElement = Driver.findElement(By.className(params.get(Constants.ID)));62 break;63 case Constants.CSS_SELECTOR:64 foundElement = Driver.findElement(By.cssSelector(params.get(Constants.ID)));65 break;66 case Constants.ID:67 foundElement = Driver.findElement(By.id(params.get(Constants.ID)));68 break;69 case Constants.LINK_TEXT:70 foundElement = Driver.findElement(By.linkText(params.get(Constants.ID)));71 break;72 case Constants.XPATH:73 foundElement = Driver.findElement(By.xpath(params.get(Constants.ID)));74 break;75 case Constants.NAME:76 foundElement = Driver.findElement(By.name(params.get(Constants.ID)));77 break;78 case Constants.PARTIAL_LINK_TEXT:79 foundElement = Driver.findElement(By.partialLinkText(params.get(Constants.ID)));80 break;81 case Constants.TAG_NAME:82 foundElement = Driver.findElement(By.tagName(params.get(Constants.ID)));83 break;84 default:85 foundElement = Driver.findElement(By.id(params.get(Constants.ID)));86 }87 return foundElement;88 }89 }90 public static List<MobileElement> findAll(HashMap<String, String> params, AppiumDriver<MobileElement> Driver) {91 Assert.assertNotNull("Error Emulator is not opened. Use Launch Emulator action.", Driver);92 List<MobileElement> foundElements = new ArrayList<>();93 if (params.get(Constants.APP_TYPE).equals(Constants.ANDROID)) {94 switch (params.get(Constants.ID_TYPE)) {95 case Constants.CLASS_NAME:96 foundElements = Driver.findElements(ByAndroidUIAutomator.className(params.get(Constants.ID)));97 break;98 case Constants.ID:99 foundElements = Driver.findElements(ByAndroidUIAutomator.id(params.get(Constants.ID)));100 break;101 case Constants.XPATH:102 foundElements = Driver.findElements(ByAndroidUIAutomator.xpath(params.get(Constants.ID)));103 break;104 case Constants.ANDROID_UI_AUTOMATOR:105 foundElements = Driver.findElements(ByAndroidUIAutomator.AndroidUIAutomator(params.get(Constants.ID)));106 break;107 case Constants.NAME:108 String xpath = ".//*[contains(@text,'" + params.get(Constants.ID) + "')]";109 foundElements = Driver.findElements(ByAndroidUIAutomator.xpath(xpath));110 break;111 default:112 foundElements = Driver.findElements(ByAndroidUIAutomator.id(params.get(Constants.ID)));113 }114 return foundElements;115 } else if (params.get(Constants.APP_TYPE).equals(Constants.IOS)) {116 switch (params.get(Constants.ID_TYPE)) {117 case Constants.CLASS_NAME:118 foundElements = Driver.findElements(ByIosUIAutomation.className(params.get(Constants.ID)));119 break;120 case Constants.ID:121 foundElements = Driver.findElements(ByIosUIAutomation.id(params.get(Constants.ID)));122 break;123 case Constants.XPATH:124 foundElements = Driver.findElements(ByIosUIAutomation.xpath(params.get(Constants.ID)));125 break;126 case Constants.IOS_UI_AUTOMATOR:127 foundElements = Driver.findElements(ByIosUIAutomation.IosUIAutomation(params.get(Constants.ID)));128 break;129 default:130 foundElements = Driver.findElements(ByIosUIAutomation.id(params.get(Constants.ID)));131 }132 return foundElements;133 } else {134 switch (params.get(Constants.ID_TYPE)) {135 case Constants.CLASS_NAME:136 foundElements = Driver.findElements(By.className(params.get(Constants.ID)));137 break;138 case Constants.CSS_SELECTOR:139 foundElements = Driver.findElements(By.cssSelector(params.get(Constants.ID)));140 break;141 case Constants.ID:142 foundElements = Driver.findElements(By.id(params.get(Constants.ID)));143 break;144 case Constants.LINK_TEXT:145 foundElements = Driver.findElements(By.linkText(params.get(Constants.ID)));146 break;147 case Constants.XPATH:148 foundElements = Driver.findElements(By.xpath(params.get(Constants.ID)));149 break;150 case Constants.NAME:151 foundElements = Driver.findElements(By.name(params.get(Constants.ID)));152 break;153 case Constants.PARTIAL_LINK_TEXT:154 foundElements = Driver.findElements(By.partialLinkText(params.get(Constants.ID)));155 break;156 case Constants.TAG_NAME:157 foundElements = Driver.findElements(By.tagName(params.get(Constants.ID)));158 break;159 default:160 foundElements = Driver.findElements(By.id(params.get(Constants.ID)));161 }162 return foundElements;163 }164 }165}...

Full Screen

Full Screen

AndroidLocator.java

Source:AndroidLocator.java Github

copy

Full Screen

1package config.locators;2import config.DriverCreator;3import cucumber.api.Scenario;4import io.appium.java_client.MobileBy;5import io.appium.java_client.MobileElement;6import io.appium.java_client.android.AndroidDriver;7import io.appium.java_client.android.AndroidElement;8import io.appium.java_client.android.AndroidKeyCode;9import org.apache.commons.io.FileUtils;10import org.openqa.selenium.*;11import org.openqa.selenium.support.ui.ExpectedConditions;12import org.openqa.selenium.support.ui.FluentWait;13import org.openqa.selenium.support.ui.Wait;14/*import io.appium.java_client.android.nativekey.AndroidKey;15import io.appium.java_client.android.nativekey.KeyEvent;*/16import java.io.File;17import java.io.IOException;18import java.sql.Driver;19import java.text.DateFormat;20import java.text.SimpleDateFormat;21import java.util.Date;22import java.util.List;23import java.util.concurrent.TimeUnit;24import java.util.function.Function;25public class AndroidLocator implements LocatorInterface{26 public static AndroidDriver<AndroidElement> driver = null;27 public AndroidLocator(){28 driver=DriverCreator.androidDriver;29 }30 @Override31 public MobileElement getLocator(final String strategy, final String element){32 AndroidElement e=null;33 MobileBy mobileBy=null;34 Wait wait = new FluentWait(driver)35 .withTimeout(30, TimeUnit.SECONDS)36 .pollingEvery(2, TimeUnit.SECONDS)37 .ignoring(NoSuchElementException.class);38 switch (strategy) {39 case "id":40 e = (AndroidElement) wait.until(new Function<AndroidDriver, AndroidElement>() {41 public AndroidElement apply(AndroidDriver driver) {42 driver = DriverCreator.androidDriver;43 return (AndroidElement) driver.findElement(new MobileBy.ByAndroidUIAutomator("new UiSelector().resourceId(\""+element+"\")"));44 }45 });46 wait.until(ExpectedConditions.elementToBeClickable(new MobileBy.ByAndroidUIAutomator("new UiSelector().resourceId(\""+element+"\")")));47 break;48 case "accessibility":49 e = (AndroidElement) wait.until(new Function<AndroidDriver, AndroidElement>() {50 public AndroidElement apply(AndroidDriver driver) {51 driver = DriverCreator.androidDriver;52 return (AndroidElement) driver.findElement(new MobileBy.ByAccessibilityId(element));53 }54 });55 wait.until(ExpectedConditions.elementToBeClickable(new MobileBy.ByAccessibilityId(element)));56 break;57 case ("descriptionStartsWith"):58 e= initDriver(this.driver, new MobileBy.ByAndroidUIAutomator59 ("descriptionStartsWith(\""+element+"\")"));60 break;61 case ("textStartsWith"):62 e= initDriver(this.driver, new MobileBy.ByAndroidUIAutomator63 ("descriptionStartsWith(\""+element+"\")"));64 break;65 default:66 //we will pass the element name as a filename for sreenshot67 //TODO: set the scenario name and element name as the SS name68 takeScreenshot(element.split("/")[1]);69 throw new IllegalArgumentException("check type of the identifier");70 }71 return e;72 }73 @Override74 public List getLocators(final String strategy, final String element){75 List<AndroidElement> e=null;76 switch (strategy) {77 case "id":78 //e= (List<AndroidElement>) driver.findElements(MobileBy.AndroidUIAutomator(element));79 e= (List<AndroidElement>) driver.findElements(new MobileBy.ByAndroidUIAutomator("new UiSelector().resourceId(\""+element+"\")"));80 break;81 default:82 throw new IllegalArgumentException("check type of the identifier");83 }84 return e;85 }86 public void sendKeysToKeyBoard(int keyCode) {87 driver.pressKeyCode(keyCode);88 //driver.pressKey(new KeyEvent(keyCode));89 }90 public AndroidElement initDriver(AndroidDriver driver, final MobileBy byType){91 Wait wait = new FluentWait(driver)92 .withTimeout(30, TimeUnit.SECONDS)93 .pollingEvery(2, TimeUnit.SECONDS)94 .ignoring(NoSuchElementException.class);95 AndroidElement element = (AndroidElement) wait.until(new Function<AndroidDriver, AndroidElement>() {96 public AndroidElement apply(AndroidDriver driver) {97 driver = DriverCreator.androidDriver;98 return (AndroidElement) driver.findElement(byType);99 }100 });101 wait.until(ExpectedConditions.elementToBeClickable(byType));102 return element;103 }104 public AndroidElement initDriverBy(AndroidDriver driver, By byType){105 Wait wait = new FluentWait(driver)106 .withTimeout(10, TimeUnit.SECONDS)107 .pollingEvery(1, TimeUnit.SECONDS)108 .ignoring(NoSuchElementException.class);109 AndroidElement element = (AndroidElement) wait.until(new Function<AndroidDriver, AndroidElement>() {110 public AndroidElement apply(AndroidDriver driver) {111 driver = DriverCreator.androidDriver;112 return (AndroidElement) driver.findElement(byType);113 }114 });115 wait.until(ExpectedConditions.elementToBeClickable(byType));116 return element;117 }118 public void takeScreenshot(String tcName){119 //Create Folder for SS120 new File("TestArtifacts").mkdir();121 //Output type122 File f=((TakesScreenshot)this.driver).getScreenshotAs(OutputType.FILE);123 //Set filename124 String filename=tcName+".png";125 try {126 FileUtils.copyFile(f, new File("TestArtifacts" + "/" + filename));127 } catch (IOException e) {128 e.printStackTrace();129 }130 }131 //this is primarly implement for IOS and not for Android.132 public void switchToStub(){}133}...

Full Screen

Full Screen

PartsPage.java

Source:PartsPage.java Github

copy

Full Screen

1package Pages;2import io.appium.java_client.MobileBy;3import io.appium.java_client.MobileDriver;4import io.appium.java_client.android.AndroidDriver;5import io.appium.java_client.android.AndroidElement;6import org.openqa.selenium.By;7import org.openqa.selenium.NoSuchElementException;8import org.openqa.selenium.StaleElementReferenceException;9import org.openqa.selenium.support.ui.ExpectedConditions;10import org.openqa.selenium.support.ui.FluentWait;11import java.time.Duration;12public class PartsPage {13 private AndroidDriver<AndroidElement> driver;14 private FluentWait<MobileDriver> wait;15 public PartsPage(AndroidDriver driver) {16 this.driver = driver;17 this.wait = new FluentWait<>((MobileDriver) driver)18 .pollingEvery(Duration.ofMillis(50))19 .withTimeout(Duration.ofSeconds(10))20 .ignoring(NoSuchElementException.class)21 .ignoring(StaleElementReferenceException.class)22 .ignoring(NullPointerException.class)23 .ignoring(ClassCastException.class)24 ;25 }26 private static final By moreFiltersSelector = new MobileBy.ByAndroidUIAutomator("new UiSelector().resourceId(\"pl.otomoto:id/show_more_filters\")");27 private static final By subcategoryChooser = new MobileBy.ByAndroidUIAutomator("new UiSelector().resourceId(\"pl.otomoto:id/subcategoryChooser\")");28 private static final By deliveryVehiclePartsSubCategory = new MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"Części do pojazdów dostawczych\")");29 private static final By carMake = new MobileBy.ByAndroidUIAutomator("new UiSelector().resourceId(\"pl.otomoto:id/chooserBtn\")");30 private static final By carMakeSearch = new MobileBy.ByAndroidUIAutomator("new UiSelector().resourceId(\"pl.otomoto:id/filter\")");31 private static final By getCarMakeSearchResult = new MobileBy.ByAndroidUIAutomator("new UiSelector().resourceId(\"android:id/text1\").index(0)");32 private static final By partCategory = new MobileBy.ByAndroidUIAutomator("new UiScrollable(new UiSelector()"33 + ".resourceId(\"pl.otomoto:id/search_scroll_view\")).scrollIntoView("34 + "new UiSelector().text(\"Rodzaj części\"));");35 private static final By selectRims = new MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"Felgi\")");36 private static final By searchResults = new MobileBy.ByAndroidUIAutomator("new UiSelector().resourceId(\"pl.otomoto:id/mag_icon\")");37 public ResultsPage searchResults() {38 clickElement(searchResults);39 return new ResultsPage(driver);40 }41 public boolean checkIfElementExists(By selector) {42 try{43 wait.until(ExpectedConditions.presenceOfElementLocated(selector));44 return true;45 } catch (Exception e) {46 return false;47 }48 }49 public AndroidElement getElementIfExists(By selector) {50 if(!checkIfElementExists(selector)) {51 //should be added to report52 System.out.println("Element " + selector + "cannot be clicked");53 return null;54 }55 else {56 return driver.findElement(selector);57 }58 }59 public void clickElement(By selector) {60 getElementIfExists(selector).click();61 }62 public void selectMoreFilters() {63 clickElement(moreFiltersSelector);64 }65 public void chooseSubcategory(String subcategoryName) {66 clickElement(subcategoryChooser);67 switch(subcategoryName) {68 case "deliveryVehicleParts":69 clickElement(deliveryVehiclePartsSubCategory);70 default:71 throw new IllegalArgumentException("Unsupported subcategory");72 }73 }74 public void chooseCarMake(String make) {75 clickElement(carMake);76 getElementIfExists(carMakeSearch).sendKeys(make);77 clickElement(getCarMakeSearchResult);78 }79 public void choosePartCategory(String category) {80 driver.findElement(partCategory).click();81 switch(category){82 case "rims":83 clickElement(selectRims);84 default:85 throw new IllegalArgumentException("Unsupported part category");86 }87 }88}...

Full Screen

Full Screen

AddNVRDevicePage.java

Source:AddNVRDevicePage.java Github

copy

Full Screen

1package com.seetong.page.device;2import com.seetong.page.main.BasePage;3import io.appium.java_client.MobileBy;4import io.appium.java_client.android.AndroidDriver;5import org.openqa.selenium.By;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import java.util.List;9public class AddNVRDevicePage extends BasePage {10 public AddNVRDevicePage(WebDriver driver) {11 super(driver);12 }13 private By addDeviceBtn = By.id("device_add");14 private MobileBy NVR = new MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"网络硬盘录像机\")");15 private By deviceIdInput = By.id("device_add_id");16 private By devicePasswordInput = By.id("device_add_password");17 private By confirmBtn = new MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"确定添加\")");18 private By toastTips = By.xpath("//*[contains(@text,'不合法')]");19 private By goBackBtn = By.id("add_device_back_rl");20 // 添加失败错误提示框信息21 private By message = By.xpath("//android.widget.TextView");22 private By closeBtn = By.xpath("//*[@text='关闭']");23 //通过局域网添加设备24 private By addDeviceLanBtn = By.id("device_add_add_lan");25 private By addDeviceLanCommitBtn = By.id("lan_device_add");26 private By passwordInput = new MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"输入密码\")");27 private By addDeviceLanConfirmBtn = new MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"确认\")");28 /**29 * 添加设备30 *31 * @param deviceId 设备ID32 * @param devicePassword 设备密码33 * @return34 */35 public AddNVRDevicePage addDevice(String deviceId, String devicePassword) {36 clickElement(addDeviceBtn);37 clickElement(NVR);38 sendKey(deviceIdInput, deviceId);39 sendKey(devicePasswordInput, devicePassword);40 clickElement(confirmBtn);41 return this;42 }43 public AddNVRDevicePage addDeviceThroughLan(String deviceId, String devicePassword) throws Exception {44 clickElement(addDeviceBtn);45 clickElement(NVR);46 clickElement(addDeviceLanBtn);47 Thread.sleep(10000);48 clickElement(By.xpath(49 "//*[@text='" + deviceId + "']" +50 "/following-sibling::" +51 "*[@resource-id='com.seetong.app.seetong:id/dev_check']"));52 clickElement(addDeviceLanCommitBtn);53 sendKey(passwordInput, devicePassword);54 clickElement(addDeviceLanConfirmBtn);55 return this;56 }57 /**58 * 获取toast中的错误信息59 *60 * @return toastTipsContent61 */62 public String getAddDeviceToastTips() {63 String toastTipsContent = driver.findElement(toastTips).getText();64 clickElement(goBackBtn);65 return toastTipsContent;66 }67 /**68 * 获取toast中的错误弹框信息69 *70 * @return toastTipsContent71 */72 public String getAddDeviceMessage() {73 try {74 Thread.sleep(5000);75 } catch (InterruptedException e) {76 e.printStackTrace();77 }78 String messageContent = "";79 List<WebElement> elements = driver.findElements(message);80 for (WebElement element : elements81 ) {82 messageContent += element.getText();83 }84 clickElement(closeBtn);85 clickElement(goBackBtn);86 return messageContent;87 }88}...

Full Screen

Full Screen

AddAndEditMemberPage.java

Source:AddAndEditMemberPage.java Github

copy

Full Screen

1package com.appium.page;2import io.appium.java_client.MobileBy;3import io.appium.java_client.TouchAction;4import io.appium.java_client.android.AndroidDriver;5import io.appium.java_client.touch.WaitOptions;6import io.appium.java_client.touch.offset.PointOption;7import org.openqa.selenium.By;8import java.time.Duration;9public class AddAndEditMemberPage extends BasePage {10 public AddAndEditMemberPage(AndroidDriver driver) {11 super(driver);12 }13 // 输入姓名14 private By username = MobileBy.id("b4t");15 // 输入手机16 private By phone = MobileBy.id("fow");17 // 保存18 private MobileBy save = new MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"保存\")");19 private MobileBy departmentSetting = new MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"设置部门\")");20 // 设置部门内的确定按钮21 private MobileBy setDepartmentConfirmBtn = new MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"确定(1)\")");22 private By telephone = new By.ByXPath("//*[@text='座机 ']/following-sibling::android.widget.EditText");23 // 删除成员24 private MobileBy deleteMember = new MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"删除成员\")");25 private MobileBy deleteMemberConfirmBtn = new MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"确定\")");26 /**27 * 输入名字28 * @param name29 */30 public void sendUsername(String name){31 sendKey(username,name);32 }33 public void sendPhone(String phoneNum){34 sendKey(phone,phoneNum);35 }36 /**37 * 输入座机38 * @param telephoneNum 座机号码39 */40 public void sendTelephone(String telephoneNum){41 sendKey(telephone,telephoneNum);42 }43 /**44 * 设置部门 暂时没有新部门 直接点确定45 */46 public void setDepartment(){47 clickElement(departmentSetting);48 clickElement(setDepartmentConfirmBtn);49 }50 /**51 * 点击保存52 */53 public void save(){54 clickElement(save);55 }56 /**57 * 在编辑也点击删除成员并点击确定58 */59 public void deleteMember(){60 clickElement(deleteMember);61 clickElement(deleteMemberConfirmBtn);62 }63}...

Full Screen

Full Screen

SearchPage.java

Source:SearchPage.java Github

copy

Full Screen

1package pages;2import io.appium.java_client.AppiumDriver;3import io.appium.java_client.MobileBy;4import io.appium.java_client.MobileElement;5import io.appium.java_client.pagefactory.AndroidFindBy;6import io.appium.java_client.pagefactory.AppiumFieldDecorator;7import manager.AppiumDriverManager;8import org.openqa.selenium.support.PageFactory;9import org.openqa.selenium.support.ui.WebDriverWait;10public class SearchPage {11 private AppiumDriver<MobileElement> driver;12 private WebDriverWait wait;13 public SearchPage(AppiumDriver<MobileElement> appiumDriver) {14 PageFactory.initElements(new AppiumFieldDecorator(appiumDriver), this);15 this.driver = appiumDriver;16 wait = AppiumDriverManager.getWait();17 }18 private final String turno1Str = "15/11/2020";19 private final String turno2Str = "29/11/2020";20 @AndroidFindBy(uiAutomator = "new UiSelector().className(\"android.view.View\").textContains(\"Todas\")")21 public MobileElement ufList;22 @AndroidFindBy(uiAutomator = "new UiSelector().className(\"android.widget.RadioButton\").textContains(\"AL\")")23 public MobileElement state;24 @AndroidFindBy(uiAutomator = "new UiSelector().className(\"android.widget.Button\").textContains(\"OK\")")25 public MobileElement okBtn;26 private String turnoSelectorRegex = "new UiSelector().className(\"android.widget.Button\").textContains(\"%s\")";27 private String stateSelectorRegex = "new UiSelector().className(\"android.widget.RadioButton\").textContains(\"%s\")";28 public void selectState(String option){29 String stateSelector = String.format(stateSelectorRegex, option);30 ufList.click();31 driver.findElement(new MobileBy.ByAndroidUIAutomator(stateSelector)).click();32 okBtn.click();33 }34 public void selectTurno(String option){35 String turnoSelector = "";36 if(option.equals("1")){37 turnoSelector = String.format(turnoSelectorRegex, turno1Str);38 }else if(option.equals("2")){39 turnoSelector = String.format(turnoSelectorRegex, turno2Str);40 }41 driver.findElement(new MobileBy.ByAndroidUIAutomator(turnoSelector)).click();42 }43}...

Full Screen

Full Screen

WelcomeSteps.java

Source:WelcomeSteps.java Github

copy

Full Screen

1package steps;2import cucumber.api.java.en.And;3import cucumber.api.java.en.Then;4import cucumber.api.java.en.When;5import helper.AppiumHelper;6import io.appium.java_client.AppiumDriver;7import io.appium.java_client.MobileBy;8import org.openqa.selenium.By;9public class WelcomeSteps {10 private AppiumHelper appiumHelper;11 private AppiumDriver appiumDriver;12 @When("^I launch demo app$")13 public void iLaunchDemoApp() throws Throwable {14 appiumHelper = new AppiumHelper();15 appiumHelper.Connect();16 appiumDriver = appiumHelper.getDriver();17 }18 @And("^The App opened$")19 public void theAppOpened() {20 appiumDriver.findElement(By.id("th.in.howtoautomate.helloworld:id/fab")).isEnabled();21 }22 @Then("^I see a welcome message \"([^\"]*)\"$")23 public void iSeeAWelcomeMessage(String message) {24 By byAndroidUIAutomator = new MobileBy.ByAndroidUIAutomator("new UiSelector().textContains(\""+message+"\")");25 appiumDriver.findElement(byAndroidUIAutomator);26 }27}...

Full Screen

Full Screen

MobileBy.ByAndroidUIAutomator

Using AI Code Generation

copy

Full Screen

1package appium;2import org.openqa.selenium.By;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.remote.DesiredCapabilities;5import org.testng.annotations.AfterTest;6import org.testng.annotations.BeforeTest;7import org.testng.annotations.Test;8import io.appium.java_client.android.AndroidDriver;9import io.appium.java_client.android.AndroidElement;10import io.appium.java_client.remote.MobileCapabilityType;11public class appium {12 AndroidDriver<AndroidElement> driver;13 public void setup() throws Exception14 {15 DesiredCapabilities cap = new DesiredCapabilities();16 cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");17 cap.setCapability("appPackage", "com.androidsample.generalstore");18 cap.setCapability("appActivity", ".SplashActivity");

Full Screen

Full Screen

MobileBy.ByAndroidUIAutomator

Using AI Code Generation

copy

Full Screen

1MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"Views\")").click();2MobileBy.ByIosUIAutomation(".elements()[0].cells()[1]").click();3self.driver.find_element_by_android_uiautomator('new UiSelector().text(\"Views\")').click()4self.driver.find_element_by_ios_uiautomation('.elements()[0].cells()[1]').click()5element = find_element :android_uiautomator, 'new UiSelector().text(\"Views\")'6element = find_element :ios_uiautomation, '.elements()[0].cells()[1]'7driver.findElement(MobileBy.ByAndroidUIAutomator('new UiSelector().text(\"Views\")')).click();8driver.findElement(MobileBy.ByIosUIAutomation('.elements()[0].cells()[1]')).click();9AndroidDriver.FindElement(MobileBy.AndroidUIAutomator("new UiSelector().text(\"Views\")")).Click();10IosDriver.FindElement(MobileBy.IosUIAutomation(".elements()[0].cells()[1]")).Click();11$driver->findElement(Facebook\WebDriver\WebDriverBy::androidUIAutomator('new UiSelector().text(\"Views\")'))->click();12$driver->findElement(Facebook\WebDriver\WebDriverBy

Full Screen

Full Screen

MobileBy.ByAndroidUIAutomator

Using AI Code Generation

copy

Full Screen

1MobileElement element = (MobileElement) driver.findElement(MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"Views\")"));2element.click();3MobileElement element = (MobileElement) driver.findElement(MobileBy.ByIosUIAutomation(".elements()[0]"));4element.click();5element = driver.find_element(MobileBy.ByAndroidUIAutomator, 'new UiSelector().text("Views")')6element.click()7element = driver.find_element(MobileBy.ByIosUIAutomation, '.elements()[0]')8element.click()

Full Screen

Full Screen

MobileBy.ByAndroidUIAutomator

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.MobileBy;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.android.AndroidElement;4import org.openqa.selenium.remote.DesiredCapabilities;5import java.net.MalformedURLException;6import java.net.URL;7public class UiAutomator {8 public static void main(String[] args) throws MalformedURLException, InterruptedException {9 DesiredCapabilities caps = new DesiredCapabilities();10 caps.setCapability("deviceName", "Pixel_3a_API_30_x86");11 caps.setCapability("platformName", "Android");12 caps.setCapability("automationName", "UiAutomator2");13 caps.setCapability("appPackage", "com.androidsample.generalstore");14 caps.setCapability("appActivity", ".SplashActivity");15 caps.setCapability("noReset", "true");

Full Screen

Full Screen

MobileBy.ByAndroidUIAutomator

Using AI Code Generation

copy

Full Screen

1package appium.java;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.concurrent.TimeUnit;5import org.openqa.selenium.By;6import org.openqa.selenium.remote.DesiredCapabilities;7import io.appium.java_client.MobileBy;8import io.appium.java_client.android.AndroidDriver;9public class appium.java {10public static void main(String[] args) throws MalformedURLException {11 DesiredCapabilities caps = new DesiredCapabilities();12 caps.setCapability("deviceName", "My Phone");13 caps.setCapability("platformName", "Android");14 caps.setCapability("platformVersion", "9");15 caps.setCapability("skipUnlock", "true");16 caps.setCapability("appPackage", "com.android.calculator2");17 caps.setCapability("appActivity","com.android.calculator2.Calculator");18 caps.setCapability("noReset", "false");

Full Screen

Full Screen

MobileBy.ByAndroidUIAutomator

Using AI Code Generation

copy

Full Screen

1MobileElement element = (MobileElement) driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Views\")");2element.click();3MobileElement element = (MobileElement) driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Views\")");4element.click();5MobileElement element = (MobileElement) driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Views\")");6element.click();7MobileElement element = (MobileElement) driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Views\")");8element.click();9MobileElement element = (MobileElement) driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Views\")");10element.click();11MobileElement element = (MobileElement) driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Views\")");12element.click();

Full Screen

Full Screen

MobileBy.ByAndroidUIAutomator

Using AI Code Generation

copy

Full Screen

1package appium;2import java.net.URL;3import java.util.concurrent.TimeUnit;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.remote.DesiredCapabilities;7import io.appium.java_client.MobileBy;8import io.appium.java_client.android.AndroidDriver;9import io.appium.java_client.android.AndroidElement;10import io.appium.java_client.remote.MobileCapabilityType;11public class AndroidUIAutomator {12public static void main(String[] args) throws Exception {13DesiredCapabilities cap = new DesiredCapabilities();14cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");15cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");16cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1.1");17cap.setCapability("appPackage", "com.android.calculator2");18cap.setCapability("appActivity", "com.android.calculator2.Calculator");

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.

Most used methods in MobileBy.ByAndroidUIAutomator

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful