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

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

CalculatorTests.java

Source:CalculatorTests.java Github

copy

Full Screen

1package com.cybertek.tests;2import io.appium.java_client.AppiumDriver;3import io.appium.java_client.MobileBy;4import io.appium.java_client.TouchAction;5import io.appium.java_client.android.AndroidDriver;6import io.appium.java_client.android.AndroidElement;7import io.appium.java_client.remote.AndroidMobileCapabilityType;8import io.appium.java_client.remote.MobileCapabilityType;9import io.appium.java_client.touch.TapOptions;10import io.appium.java_client.touch.offset.ElementOption;11import org.junit.After;12import org.junit.Assert;13import org.junit.Before;14import org.junit.Test;15import org.openqa.selenium.Platform;16import org.openqa.selenium.remote.DesiredCapabilities;17import org.openqa.selenium.support.ui.ExpectedConditions;18import org.openqa.selenium.support.ui.WebDriverWait;19import java.net.MalformedURLException;20import java.net.URL;21public class CalculatorTests {22 AppiumDriver<AndroidElement> driver;23 @Before24 public void setup() throws Exception {25 //desiredCapabilities.setCapability("platformName", "Android");26 //to specify test settings and required info about device and app under the test27 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();28 desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, Platform.ANDROID);29 desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.0");30 desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Pixel_2");31 desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");32 desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.android.calculator2");33 desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator");34 //for new apps - just use "app"35 //for pre-installed - "appPackage" and "appActivity"36 //address of appium server37 //localhost means that appium server is running on your computer38 //if, appium server launched on some other computer39 //specify IP/DNS address instead of localhost40 //4723 - default port number of appium server. Can be changed41 URL url = new URL("http://localhost:4723/wd/hub");42 driver = new AndroidDriver<>(url, desiredCapabilities);43 }44 @Test45 public void calculatorTest() throws Exception {46 AndroidElement btn2 = driver.findElement(MobileBy.id("com.android.calculator2:id/digit_2"));47 AndroidElement plusBtn = driver.findElement(MobileBy.AccessibilityId("plus"));48 AndroidElement equalsBtn = driver.findElement(MobileBy.AccessibilityId("equals"));49 AndroidElement resultElement = driver.findElementById("com.android.calculator2:id/result");50 //to handle synchronization issues, same as in Selenium WebDriver51 WebDriverWait wait = new WebDriverWait(driver, 20);52 wait.until(ExpectedConditions.elementToBeClickable(btn2));53 btn2.click(); // 254 plusBtn.click(); // +55 btn2.click(); // 256 equalsBtn.click(); // =57 int expected = 4;58 int actual = Integer.parseInt(resultElement.getText());59 Assert.assertEquals(expected, actual);60 }61 @Test62 public void calculatorTestWithTouchActions(){63 AndroidElement btn9 = driver.findElementById("com.android.calculator2:id/digit_9");64 AndroidElement btn0 = driver.findElementById("com.android.calculator2:id/digit_0");65 AndroidElement divide = driver.findElementByAccessibilityId("divide");66 AndroidElement btn5 = driver.findElementById("com.android.calculator2:id/digit_5");67 AndroidElement resultElement = driver.findElementById("com.android.calculator2:id/result");68 AndroidElement equalsBtn = driver.findElement(MobileBy.AccessibilityId("equals"));69 //we can click on elements, or we can use touch actions70 TouchAction touchAction = new TouchAction(driver);71 touchAction.tap(new TapOptions().withElement(new ElementOption().withElement(btn9))).perform();72 touchAction.tap(new TapOptions().withElement(new ElementOption().withElement(btn0))).perform();73 touchAction.tap(new TapOptions().withElement(new ElementOption().withElement(divide))).perform();74 touchAction.tap(new TapOptions().withElement(new ElementOption().withElement(btn5))).perform();75 touchAction.tap(new TapOptions().withElement(new ElementOption().withElement(equalsBtn))).perform();76 int expected = 18;77 int actual = Integer.parseInt(resultElement.getText());78 Assert.assertEquals(expected, actual);79 }80 @After81 public void tearDown(){82 driver.closeApp();...

Full Screen

Full Screen

correctincorrectLogin.java

Source:correctincorrectLogin.java Github

copy

Full Screen

1package projectActivities;2import org.testng.annotations.Test;3import io.appium.java_client.AppiumDriver;4import io.appium.java_client.MobileBy;5import io.appium.java_client.MobileElement;6import io.appium.java_client.android.AndroidDriver;7import org.testng.annotations.BeforeClass;8import java.net.MalformedURLException;9import java.net.URL;10import java.util.concurrent.TimeUnit;11import org.openqa.selenium.WebElement;12import org.openqa.selenium.remote.DesiredCapabilities;13import org.openqa.selenium.support.ui.WebDriverWait;14import org.testng.Assert;15import org.testng.Reporter;16import org.testng.annotations.AfterClass;17public class correctincorrectLogin {18 19 WebDriverWait wait;20 AppiumDriver<MobileElement> driver;21 22 23 @BeforeClass24 public void setup() throws MalformedURLException {25 // Set the Desired Capabilities26 DesiredCapabilities caps = new DesiredCapabilities();27 caps.setCapability("deviceName", "Xiaomi Redmi 6");28 caps.setCapability("deviceid","0e79a81b7d29");29 caps.setCapability("platformName", "Android");30 caps.setCapability("automationName", "UiAutomator2");31 caps.setCapability("appPackage", "com.android.chrome");32 caps.setCapability("appActivity", "com.google.android.apps.chrome.Main");33 caps.setCapability("noReset", true);34 // Instantiate Appium Driver35 URL appServer = new URL("http://0.0.0.0:4723/wd/hub");36 driver = new AndroidDriver<MobileElement>(appServer, caps);37 driver.get("https://www.training-support.net/selenium");38 }39 40 //Goal: Opening a page on the browser and testing a simple login page with correct and incorrect credentials41 42 @Test43 public void ValidLogin() {44 driver.findElement(MobileBy.AndroidUIAutomator("UiScrollable(UiSelector().scrollable(true).instance(0)).scrollIntoView(textStartsWith(\"Login Form\"))"));45 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);46 driver.findElement(MobileBy.xpath("//android.widget.TextView[@text='Login Form']")).click();47 48 49 //Valid Credentials50 String userName = "admin";51 String passWord = "password";52 driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"username\")")).sendKeys(userName);53 driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"password\")")).sendKeys(passWord);54 driver.findElement(MobileBy.AndroidUIAutomator("text(\"Log in\")")).click();55 String loginMessage = driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"action-confirmation\")")).getText();56 57 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);58 59 Assert.assertEquals(loginMessage, "Welcome Back, admin");60 //Invalid Credentials61 String userName1 = "admin1";62 String passWord1 = "password1";63 WebElement user1 = driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"username\")"));64 WebElement pass1 = driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"password\")"));65 user1.clear();66 pass1.clear();67 user1.sendKeys(userName1);68 pass1.sendKeys(passWord1);69 70 driver.findElement(MobileBy.AndroidUIAutomator("UiScrollable(UiSelector().scrollable(true)).scrollIntoView(textStartsWith(\"Log in\"))"));71 driver.findElement(MobileBy.AndroidUIAutomator("text(\"Log in\")")).click();72 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);73 74 String inloginMessage = driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"action-confirmation\")")).getText();75 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);76 Assert.assertEquals(inloginMessage, "Invalid Credentials");77 }78 @AfterClass79 public void afterClass() {80 driver.quit();81 }82}...

Full Screen

Full Screen

FirstAndroidTest.java

Source:FirstAndroidTest.java Github

copy

Full Screen

1import io.appium.java_client.AppiumDriver;2import io.appium.java_client.MobileBy;3import io.appium.java_client.MobileElement;4import io.appium.java_client.TouchAction;5import io.appium.java_client.android.AndroidDriver;6import io.appium.java_client.android.AndroidElement;7import io.appium.java_client.android.AndroidTouchAction;8import io.appium.java_client.android.nativekey.AndroidKey;9import io.appium.java_client.android.nativekey.KeyEvent;10import io.appium.java_client.pagefactory.AndroidFindBy;11import io.appium.java_client.touch.WaitOptions;12import io.appium.java_client.touch.offset.ElementOption;13import io.appium.java_client.touch.offset.PointOption;14import org.openqa.selenium.By;15import org.openqa.selenium.Dimension;16import org.openqa.selenium.Keys;17import org.openqa.selenium.remote.DesiredCapabilities;18import org.testng.Assert;19import org.testng.annotations.AfterTest;20import org.testng.annotations.BeforeTest;21import org.testng.annotations.Test;22import java.net.MalformedURLException;23import java.net.URL;24import java.time.Duration;25import java.util.concurrent.TimeUnit;26public class FirstAndroidTest {27 public AppiumDriver driver;28 public AndroidTouchAction touchAction;29 private TouchAction action;30 private By editText = MobileBy.id("edit");31 private By views = MobileBy.AccessibilityId("Views");32 private By grid = MobileBy.AccessibilityId("Grid");33 private By animation = MobileBy.AccessibilityId("Animation");34 private By textField = MobileBy.AccessibilityId("TextFields");35 // private By webView2 = MobileBy.AccessibilityId("WebView2");36 private By title = MobileBy.xpath("//android.webkit.WebView/android.view.View[1]");37 @BeforeTest38 public void setUp() throws MalformedURLException {39 DesiredCapabilities caps = new DesiredCapabilities();40 caps.setCapability("platformName", "Android");41 caps.setCapability("automationName", "UiAutomator1");42 caps.setCapability("platformVersion", "7.1.1");43 caps.setCapability("deviceName", "Android Emulator");44 caps.setCapability("appPackage", "com.swaglabsmobileapp");45 caps.setCapability("appActivity", "com.swaglabsmobileapp.SplashActivity");46 caps.setCapability("udid", "emulator-5554");47// caps.setCapability("app", System.getProperty("user.dir") + "/apps/ApiDemos-debug.apk");48 driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), caps);49 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);50 }51 @Test52 public void clickButtonTest() {53 MobileElement editTextName = (MobileElement) driver.findElementByAccessibilityId("test-Username");54 MobileElement editTextPaswd = (MobileElement) driver.findElementByAccessibilityId("test-Password");55 MobileElement btnLogin = (MobileElement) driver.findElementByAccessibilityId("test-LOGIN");56 editTextName.sendKeys("shimma");57 editTextPaswd.sendKeys("dhjssa");58 btnLogin.click();59 MobileElement errMsg = (MobileElement) driver.findElementByXPath("//android.view.ViewGroup[@content-desc=\"test-Error message\"]/android.widget.TextView");60 Assert.assertEquals(errMsg.getAttribute("text"), "Username and password do not match any user in this service.");61 }62 @Test63 public void clickViewsTest() throws InterruptedException {64 action = new TouchAction(driver);65 action.tap(ElementOption.element(driver.findElement(views))).perform();66 MobileElement webVi = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator(67 "new UiScrollable(new UiSelector().scrollable(true))" +68 ".scrollIntoView(new UiSelector().text(\"WebView2\"))"));69 webVi.click();70 }71// @AfterTest72// public void tearDown() {73// if (driver != null) {74// driver.quit();75// }76// }77}...

Full Screen

Full Screen

correctIncorrectLogin_PopUps.java

Source:correctIncorrectLogin_PopUps.java Github

copy

Full Screen

1package projectActivities;2import org.testng.annotations.Test;3import io.appium.java_client.AppiumDriver;4import io.appium.java_client.MobileBy;5import io.appium.java_client.MobileElement;6import io.appium.java_client.android.AndroidDriver;7import org.testng.annotations.BeforeClass;8import java.net.MalformedURLException;9import java.net.URL;10import java.util.concurrent.TimeUnit;11import org.openqa.selenium.WebElement;12import org.openqa.selenium.remote.DesiredCapabilities;13import org.openqa.selenium.support.ui.WebDriverWait;14import org.testng.Assert;15import org.testng.Reporter;16import org.testng.annotations.AfterClass;17public class correctIncorrectLogin_PopUps {18 19 WebDriverWait wait;20 AppiumDriver<MobileElement> driver;21 22 23 @BeforeClass24 public void setup() throws MalformedURLException {25 // Set the Desired Capabilities26 DesiredCapabilities caps = new DesiredCapabilities();27 caps.setCapability("deviceName", "Xiaomi Redmi 6");28 caps.setCapability("deviceid","0e79a81b7d29");29 caps.setCapability("platformName", "Android");30 caps.setCapability("automationName", "UiAutomator2");31 caps.setCapability("appPackage", "com.android.chrome");32 caps.setCapability("appActivity", "com.google.android.apps.chrome.Main");33 caps.setCapability("noReset", true);34 // Instantiate Appium Driver35 URL appServer = new URL("http://0.0.0.0:4723/wd/hub");36 driver = new AndroidDriver<MobileElement>(appServer, caps);37 driver.get("https://www.training-support.net/selenium");38 }39 //Goal: Opening a page on the browser and testing a simple login page with correct and incorrect credentials40 41 @Test42 public void PopUpsLogin() {43 driver.findElement(MobileBy.AndroidUIAutomator("UiScrollable(UiSelector().scrollable(true).instance(0)).scrollIntoView(textStartsWith(\"Popups\"))"));44 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);45 driver.findElement(MobileBy.xpath("//android.widget.TextView[@text='Popups']")).click();46 //Enter credentials 47 //Valid Credentials48 String userName = "admin";49 String passWord = "password";50 driver.findElement(MobileBy.AndroidUIAutomator("text(\"Sign In\")")).click();51 WebElement user = driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"username\")"));52 WebElement pass = driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"password\")"));53 user.sendKeys(userName);54 pass.sendKeys(passWord);55 driver.findElement(MobileBy.AndroidUIAutomator("text(\"Log in\")")).click();56 String loginMessage = driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"action-confirmation\")")).getText();57 Assert.assertEquals(loginMessage, "Welcome Back, admin");58 //Invalid Credentials59 String userName1 = "admin1";60 String passWord1 = "password1";61 driver.findElement(MobileBy.AndroidUIAutomator("text(\"Sign In\")")).click();62 user.clear();63 pass.clear();64 user.sendKeys(userName1);65 pass.sendKeys(passWord1);66 driver.findElement(MobileBy.AndroidUIAutomator("text(\"Log in\")")).click();67 String inloginMessage = driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"action-confirmation\")")).getText();68 Assert.assertEquals(inloginMessage, "Invalid Credentials");69 Assert.assertEquals(inloginMessage, "Invalid Credentials");70 }71 @AfterClass72 public void afterClass() {73 driver.quit();74 }75}...

Full Screen

Full Screen

googleKeep.java

Source:googleKeep.java Github

copy

Full Screen

1package projectActivities;2import org.testng.annotations.Test;3import io.appium.java_client.AppiumDriver;4import io.appium.java_client.MobileBy;5import io.appium.java_client.MobileElement;6import io.appium.java_client.android.AndroidDriver;7import org.testng.annotations.BeforeMethod;8import java.net.MalformedURLException;9import java.net.URL;10import java.util.List;11import java.util.concurrent.TimeUnit;12import org.openqa.selenium.remote.DesiredCapabilities;13import org.openqa.selenium.support.ui.WebDriverWait;14import org.testng.Assert;15import org.testng.annotations.AfterMethod;16public class googleKeep {17 WebDriverWait wait;18 AppiumDriver<MobileElement> driver;19 20 21 @BeforeMethod22 public void setup() throws MalformedURLException {23 // Set the Desired Capabilities24 DesiredCapabilities caps = new DesiredCapabilities();25 caps.setCapability("deviceName", "Xiaomi Redmi 6");26 caps.setCapability("deviceid","0e79a81b7d29");27 caps.setCapability("platformName", "Android");28 caps.setCapability("automationName", "UiAutomator2");29 caps.setCapability("appPackage", "com.google.android.keep");30 caps.setCapability("appActivity", "com.google.android.apps.keep.ui.activities.BrowseActivity");31 caps.setCapability("noReset", true);32 // Instantiate Appium Driver33 URL appServer = new URL("http://0.0.0.0:4723/wd/hub");34 driver = new AndroidDriver<MobileElement>(appServer, caps);35 }36@Test37public void addReminder() {38 driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);39 driver.findElementByAccessibilityId("Open navigation drawer").click();40 driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"com.google.android.keep:id/drawer_navigation_reminders\")")).click(); 41 42 List<MobileElement> created_Tasks = driver.findElements(MobileBy.AndroidUIAutomator("resourceId(\"com.google.android.keep:id/browse_text_note\")"));43 int init_count = (created_Tasks.size());44 45 driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"com.google.android.keep:id/new_note_button\")")).click();46 driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"com.google.android.keep:id/editable_title\")")).sendKeys("TitleNotes");47 driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"com.google.android.keep:id/edit_note_text\")")).sendKeys("Notes Text");48 49 driver.findElementByAccessibilityId("Reminder").click();50 51 driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"com.google.android.keep:id/time_spinner\")")).click();52 driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"com.google.android.keep:id/reminder_time_afternoon\")")).click();53 driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"com.google.android.keep:id/save\")")).click();54 55 driver.findElementByAccessibilityId("Open navigation drawer").click();56 driver.findElementByAccessibilityId("Open navigation drawer").click();57 driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"com.google.android.keep:id/drawer_navigation_reminders\")")).click(); 58 59 created_Tasks = driver.findElements(MobileBy.AndroidUIAutomator("resourceId(\"com.google.android.keep:id/browse_text_note\")"));60 int new_count = (created_Tasks.size());61 62 Assert.assertEquals((new_count - init_count), 1);63 64}65@AfterMethod66public void afterMethod() {67 driver.quit();68}69}...

Full Screen

Full Screen

SwipeDemo.java

Source:SwipeDemo.java Github

copy

Full Screen

...3import java.time.Duration;4import java.util.ArrayList;5import java.util.List;6import java.util.concurrent.TimeUnit;7import io.appium.java_client.MobileBy;8import io.appium.java_client.touch.WaitOptions;9import io.appium.java_client.touch.offset.PointOption;10import org.openqa.selenium.By;11import org.openqa.selenium.Dimension;12import org.openqa.selenium.WebElement;13import static io.appium.java_client.touch.LongPressOptions.longPressOptions;14import io.appium.java_client.TouchAction;15import io.appium.java_client.android.AndroidDriver;16import io.appium.java_client.android.AndroidElement;17import static java.time.Duration.ofSeconds;18import static io.appium.java_client.touch.offset.ElementOption.element;19public class SwipeDemo extends Base {20 public static void main(String[] args) throws MalformedURLException, InterruptedException {21 // TODO Auto-generated method stub22 AndroidDriver<AndroidElement> driver = Capabilities();23 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);24 WebElement skipButton = driver.findElement(MobileBy.AndroidUIAutomator("text(\"SKIP\")"));25 skipButton.click();26 //or27 //driver.findElementByAccessibilityId("com.shawmedia.smglobal:id/left_button").click();28 //or29 //driver.findElement(MobileBy.AndroidUIAutomator("text(\"SKIP\")")).click();30 //navigate to Shows - Global brand31 driver.findElementByAccessibilityId("global").click();32 //or33 //driver.findElementByXPath("//android.widget.ImageView[@content-desc='history']").click()34 Thread.sleep(2000);35//click on show to get show details page36 WebElement show = driver.findElement(MobileBy.AndroidUIAutomator("description(\"A Little Late with Lilly Singh\")"));37 show.click();38 Thread.sleep(2000);39//click Back button to return to Shows screen - Global brand40 driver.findElementById("com.shawmedia.smglobal:id/detail_page_back_button").click();41// scroll screen42 // calculate bottom & top of the screen43 Dimension size = driver.manage().window().getSize();44 int middleX = (int) (size.getWidth() * 0.5);45 int bottomY = (int) (size.getHeight() * 0.8);46 int topY = (int) (size.getHeight() * 0.3);47// lookup for element to refresh appium48 List<AndroidElement> lst = driver.findElementsById("com.shawmedia.smglobal:id/shows_grid_view");49 System.out.println(lst.size());50 new TouchAction(driver).press(PointOption.point(middleX, bottomY))51 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000))).moveTo(PointOption.point(middleX, topY)).release()52 .perform();53 new TouchAction(driver).press(PointOption.point(middleX, bottomY))54 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000))).moveTo(PointOption.point(middleX, topY)).release()55 .perform();56 WebElement show1 = driver.findElement(MobileBy.AndroidUIAutomator("description(\"EVIL\")"));57 show1.click();58//click Shows navigation button to return to Shows screen - Global brand59 WebElement NavShow = driver.findElement(MobileBy.AndroidUIAutomator("text(\"SHOWS\")"));60 NavShow.click();61 //driver.findElementById("com.shawmedia.smglobal:id/detail_page_back_button").click();62 }63}...

Full Screen

Full Screen

BasePage.java

Source:BasePage.java Github

copy

Full Screen

1package Pages;2import Config.Test_Base;3import com.google.common.collect.ImmutableMap;4import io.appium.java_client.AppiumDriver;5import io.appium.java_client.MobileBy;6import io.appium.java_client.TouchAction;7import io.appium.java_client.android.AndroidDriver;8import io.appium.java_client.pagefactory.AppiumFieldDecorator;9import io.appium.java_client.touch.WaitOptions;10import io.appium.java_client.touch.offset.ElementOption;11import io.appium.java_client.touch.offset.PointOption;12import org.openqa.selenium.*;13import org.openqa.selenium.interactions.touch.TouchActions;14import org.openqa.selenium.remote.RemoteWebElement;15import org.openqa.selenium.support.PageFactory;16import org.openqa.selenium.support.ui.ExpectedConditions;17import org.openqa.selenium.support.ui.WebDriverWait;18import java.time.Duration;19import java.util.HashMap;20import static io.appium.java_client.touch.WaitOptions.waitOptions;21public class BasePage extends Test_Base {22 private static final int KEYBOARD_ANIMATION_DELAY = 1000;23 private static final int XML_REFRESH_DELAY = 1000;24 public static final String app_package = env + ":id/";25 protected final AppiumDriver driver;26 private WebElement element;27 protected BasePage(AppiumDriver driver) {28 this.driver = driver;29 // PageFactory.initElements(new AppiumFieldDecorator(driver, 120, TimeUnit.SECONDS), this);30 PageFactory.initElements(new AppiumFieldDecorator(driver, Duration.ofSeconds(120)), this);31 }32 public WebElement scroll_text_contains(String text) {33 return driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().textContains(\"" + text + "\"));"));34 }35 public WebElement verify_text(String Text) {36 return driver.findElement(MobileBy.xpath("//android.widget.TextView[@text =" + "\"" + Text + "\"]"));37 }38 public void touchActionPointer() {39 int heightOfScreen = driver.manage().window().getSize().getHeight();40 int widthOfScreen = driver.manage().window().getSize().getWidth();41 int x = (int) (widthOfScreen * 0.115);42 // System.out.println(x);43 int y = (int) (heightOfScreen * 0.92);44 // System.out.println(y);45 int end_x = (int) (widthOfScreen * 0.916);46 // System.out.println(end_x);47 int end_y = y;48 TouchAction action = new TouchAction(driver);49 action.press(PointOption.point(x, y))50 .waitAction(waitOptions(Duration.ofMillis(800)))...

Full Screen

Full Screen

apptest1.java

Source:apptest1.java Github

copy

Full Screen

...5import cucumber.api.java.en.Given;6import cucumber.api.java.en.Then;7import cucumber.api.java.en.When;8import java.net.URL;9import io.appium.java_client.MobileBy;10import io.appium.java_client.android.AndroidDriver;11import io.appium.java_client.android.AndroidElement;12import io.appium.java_client.android.nativekey.AndroidKey;13import io.appium.java_client.android.nativekey.KeyEvent;14public class apptest1 extends AppRunner {15 public AndroidDriver driver = this.connection;16 public String Status="failed";17 @Given("^user is on home Page$")18 public void user_already_on_home_page() {19 try{20 System.out.println(driver.getCapabilities());21 driver.findElement(MobileBy.AccessibilityId("Search Wikipedia")).click();22 driver.findElement(MobileBy.id("org.wikipedia.alpha:id/search_src_text")).sendKeys("Cristiano Ronaldo");23 driver.pressKey(new KeyEvent(AndroidKey.ENTER));24 Status = "passed";25 driver.executeScript("lambda-status=" + Status);26 driver.quit();27 } catch(Exception e){28 System.out.println(e.getMessage());29 }30 }31}...

Full Screen

Full Screen

MobileBy

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.MobileElement;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.android.AndroidElement;4import io.appium.java_client.remote.MobileCapabilityType;5import io.appium.java_client.service.local.AppiumDriverLocalService;6import io.appium.java_client.service.local.AppiumServiceBuilder;7import java.net.MalformedURLException;8import java.net.URL;9import java.util.concurrent.TimeUnit;10import org.openqa.selenium.remote.DesiredCapabilities;11public class appium {12public static AppiumDriverLocalService service;13public static AndroidDriver<AndroidElement> driver;14public static void startServer() {15service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()16.usingDriverExecutable(new File("C:\\Program Files\\nodejs\\node.exe"))17.withAppiumJS(new File("C:\\Users\\Saurabh\\AppData\\Roaming\\npm\\node_modules\\appium\\build\\lib\\main.js"))18.withIPAddress("

Full Screen

Full Screen

MobileBy

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.MobileBy;2By by = MobileBy.AccessibilityId("test-Username");3import org.openqa.selenium.By;4By by = By.id("test-Username");5import io.appium.java_client.MobileBy;6By by = MobileBy.AccessibilityId("test-Username");7import org.openqa.selenium.By;8By by = By.id("test-Username");9import io.appium.java_client.MobileBy;10By by = MobileBy.AccessibilityId("test-Username");11import org.openqa.selenium.By;12By by = By.id("test-Username");13import io.appium.java_client.MobileBy;14By by = MobileBy.AccessibilityId("test-Username");15import org.openqa.selenium.By;16By by = By.id("test-Username");17import io.appium.java_client.MobileBy;18By by = MobileBy.AccessibilityId("test-Username");19import org.openqa.selenium.By;20By by = By.id("test-Username");21import io.appium.java_client.MobileBy;22By by = MobileBy.AccessibilityId("test-Username");23import org.openqa.selenium.By;24By by = By.id("test-Username");25import io.appium.java_client.MobileBy;26By by = MobileBy.AccessibilityId("test-Username");27import org.openqa.selenium.By;28By by = By.id("test-Username");

Full Screen

Full Screen

MobileBy

Using AI Code Generation

copy

Full Screen

1MobileBy.ByAccessibilityId("Accessibility ID");2MobileBy.ByAndroidUIAutomator("UI Automator");3MobileBy.ByIosUIAutomation("UI Automation");4MobileBy.ByIosNsPredicate("iOS predicate string");5MobileBy.ByIosClassChain("iOS class chain");6MobileElement element = driver.findElement(MobileBy.ByAccessibilityId("Accessibility ID"));7MobileElement element = driver.findElement(MobileBy.ByAndroidUIAutomator("UI Automator"));8MobileElement element = driver.findElement(MobileBy.ByIosUIAutomation("UI Automation"));9MobileElement element = driver.findElement(MobileBy.ByIosNsPredicate("iOS predicate string"));10MobileElement element = driver.findElement(MobileBy.ByIosClassChain("iOS class chain"));11TouchAction action = new TouchAction(driver);12action.press(200,200).moveTo(200,300).release().perform();13TouchAction action = new TouchAction(driver);14action.tap(200,200).perform();15TouchAction action = new TouchAction(driver);16action.press(200,200).waitAction(2000).moveTo(200,300).release().perform();17TouchAction action = new TouchAction(driver);18action.longPress(200,200).release().perform();19TouchAction action = new TouchAction(driver);20action.press(200,200).moveTo(200,300).release().perform();

Full Screen

Full Screen

MobileBy

Using AI Code Generation

copy

Full Screen

1By myBy = MobileBy.AccessibilityId("myId");2By myBy = MobileBy.AndroidUIAutomator("new UiSelector().text(\"myText\")");3By myBy = MobileBy.IosUIAutomation(".elements()[0].cells()[1].textFields()[0]");4By myBy = MobileBy.AndroidUIAutomator("new UiSelector().text(\"myText\")");5By myBy = MobileBy.IosUIAutomation(".elements()[0].cells()[1].textFields()[0]");6@AndroidFindBy(className = "android.widget.TextView")7public WebElement myElement;8Map<String, String> myParams = new HashMap<>();9myParams.put("element", "myElement");10myParams.put("text", "myText");11myParams.put("multiple", "true");12myParams.put("ignoreCase", "true");13myParams.put("ignoreWhitespace", "true");14myParams.put("trim", "true");15myParams.put("allowRegex", "true");16myParams.put("strategy", "text");17myParams.put("context", "myContext");18myParams.put("packageName", "myPackageName");19myParams.put("resourceId", "myResourceId");20myParams.put("className", "myClassName");21myParams.put("index", "1");22myParams.put("name", "myName");23myParams.put("contentDesc", "myContentDesc");24myParams.put("xpath", "myXpath");25myParams.put("androidUIAutomator", "myAndroidUIAutomator");26myParams.put("iosUIAutomation", "myIosUIAutomation");27myParams.put("predicateString", "myPredicateString");28myParams.put("image", "myImage");29myParams.put("imageBase64", "myImageBase64

Full Screen

Full Screen

MobileBy

Using AI Code Generation

copy

Full Screen

1MobileBy element = MobileBy.AccessibilityId("test-Username");2WebElement username = driver.findElement(element);3MobileBy element = MobileBy.AccessibilityId("test-Password");4WebElement password = driver.findElement(element);5MobileBy element = MobileBy.AccessibilityId("test-LOGIN");6WebElement login = driver.findElement(element);7MobileBy element = MobileBy.AccessibilityId("test-LOGOUT");8WebElement logout = driver.findElement(element);9MobileBy element = MobileBy.AccessibilityId("test-Alerts");10WebElement alerts = driver.findElement(element);11MobileBy element = MobileBy.AccessibilityId("test-Activity Feed");12WebElement activityFeed = driver.findElement(element);13MobileBy element = MobileBy.AccessibilityId("test-New Note");14WebElement newNote = driver.findElement(element);15MobileBy element = MobileBy.AccessibilityId("test-Take Picture");16WebElement takePicture = driver.findElement(element);17MobileBy element = MobileBy.AccessibilityId("test-Choose from Library");18WebElement chooseFromLibrary = driver.findElement(element);19MobileBy element = MobileBy.AccessibilityId("test-Add Attachment");20WebElement addAttachment = driver.findElement(element);21MobileBy element = MobileBy.AccessibilityId("test-Save");22WebElement save = driver.findElement(element);23MobileBy element = MobileBy.AccessibilityId("test-

Full Screen

Full Screen

MobileBy

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.MobileBy;2import org.openqa.selenium.By;3By by = MobileBy.AccessibilityId("YourAccessibilityId");4var MobileBy = require('appium').MobileBy;5var by = MobileBy.AccessibilityId('YourAccessibilityId');6import MobileBy from 'appium';7const by = MobileBy.AccessibilityId('YourAccessibilityId');8from appium import MobileBy9by = MobileBy.AccessibilityId('YourAccessibilityId')10driver.findElement(by).click();11import io.appium.java_client.MobileBy;12import org.openqa.selenium.By;13By by = MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeButton' AND name == 'YourButtonName'");14var MobileBy = require('appium').MobileBy;15var by = MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeButton' AND name == 'YourButtonName'");16import MobileBy from 'appium';17const by = MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeButton' AND name == 'YourButtonName'");18from appium import MobileBy19by = MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeButton' AND name == 'YourButtonName'")20driver.findElement(by).click();

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