How to use image method of io.appium.java_client.MobileBy class

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

Demo.java

Source:Demo.java Github

copy

Full Screen

1package framework.appium_khan;23import static io.appium.java_client.touch.LongPressOptions.longPressOptions;4import static io.appium.java_client.touch.TapOptions.tapOptions;5import static io.appium.java_client.touch.offset.ElementOption.element;6import static java.time.Duration.ofSeconds;78import java.io.IOException;9import java.net.MalformedURLException;10import java.util.List;11import java.util.Set;12import java.util.concurrent.TimeUnit;1314import org.openqa.selenium.By;15import org.openqa.selenium.Keys;16import org.openqa.selenium.WebElement;17import org.openqa.selenium.logging.LogEntry;18import org.openqa.selenium.support.ui.Select;19import org.testng.Assert;20import org.testng.annotations.BeforeTest;21import org.testng.annotations.Test;2223import io.appium.java_client.MobileBy;24import io.appium.java_client.TouchAction;25import io.appium.java_client.android.AndroidDriver;26import io.appium.java_client.android.AndroidElement;27import io.appium.java_client.android.nativekey.AndroidKey;28import io.appium.java_client.android.nativekey.KeyEvent;2930 public class Demo extends Capability 31 {32 33 AndroidDriver<AndroidElement> driver;34 35 @BeforeTest36 public void bt() throws IOException, InterruptedException37 {38 Runtime.getRuntime().exec("taskkill /F /IM node.exe");39 Thread.sleep(5000);40 //driver = capabilities(appPackage, appActivity, deviceName, platformName, chromeExecutable);41 //driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);42 }43 4445 46 47 @Test48 public void testcase1() throws InterruptedException, IOException 49 {50 service = startServer();51 driver = capabilities(appPackage, appActivity, deviceName, platformName, chromeExecutable);52 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);53 54 Thread.sleep(2000);55 56 //Click on first dismiss57 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Dismiss\")")).click();58 59 60 //click on settings button61 WebElement b1 = driver.findElements(By.className("android.widget.ImageView")).get(0);62 b1.click();63 64 65 //Click on language66 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Language & region\")")).click();67 68 // select english default69 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"English (default)\")")).click();70 71 72 //go back73 driver.pressKey(new KeyEvent(AndroidKey.BACK));74 75 //click on sound effects76 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"OFF\")")).click();77 78 Thread.sleep(2000);79 80 //clicking on terms and service81 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Terms of service\")")).click();82 83 //clicking on google - only once84 driver.findElement(By.id("android:id/button_once")).click();85 86 87 //switching from native to web 88 Set<String> contextNames = driver.getContextHandles();89 for (String contextName : contextNames)90 {91 System.out.println(contextName); //prints out something like NATIVE_APP \n WEBVIEW_92 } 93 //this is used to switch between native app and web app in hybrid app94 driver.context("WEBVIEW_chrome");95 System.out.println("done");96 Thread.sleep(3000);97 98 //click on search button99 driver.findElement(By.xpath("//*[@id=\"app-shell-root\"]/div/div[1]/nav/div/div[3]/div[1]/a/div")).click();100 101 Thread.sleep(3000);102 103 //click on search option box104 driver.findElement(By.xpath("//*[@id=\"mobile-search-form-container\"]/form/div/input[2]")).click();105 106 Thread.sleep(3000);107 108 //enter school use in 109 driver.findElement(By.xpath("//*[@id=\"mobile-search-form-container\"]/form/div/input[2]")).sendKeys("Talks and Interviews");110 111 //press enter112 driver.findElement(By.xpath("//*[@id=\"mobile-search-form-container\"]/form/div/input[2]")).sendKeys(Keys.ENTER);113 114 Thread.sleep(7000);115 driver.pressKey(new KeyEvent(AndroidKey.BACK));116 Thread.sleep(2000);117 driver.pressKey(new KeyEvent(AndroidKey.BACK));118 Thread.sleep(2000);119 driver.pressKey(new KeyEvent(AndroidKey.BACK));120 driver.context("NATIVE_APP");121 122 Thread.sleep(3000);123 124 //Click on Sign in125 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Sign in\")")).click();126 127 Thread.sleep(3000);128 129 //click on sign up with email130 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Sign up with email\")")).click();131 132 Thread.sleep(2000);133 134 driver.hideKeyboard();135 136 //enter firstname137 driver.findElementByAccessibilityId("First name").sendKeys("king");138 139 //enter last name140 driver.findElementByAccessibilityId("Last name").sendKeys("kong");141 142 //click on brithday143 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Birthday\")")).click();144 145 //pikcing date from date picker146 driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollForward().scrollTextIntoView(\"Dec\")").click();147 driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(1)).scrollForward().scrollTextIntoView(\"05\")").click();148 driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(2)).scrollBackward().scrollTextIntoView(\"1995\")").click();149 150 151 //click on OK152 driver.findElement(By.id("android:id/button1")).click();153 154 //enter email address155 driver.findElementByAccessibilityId("Email address").sendKeys("kingspr76524@gmail.com");156 157 //enter password158 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Password\")")).sendKeys("Universal123");159 160 //click on Create161 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"CREATE\")")).click();162163 Thread.sleep(2000);164 165 //Click on dismiss on COVID 19166 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Dismiss\")")).click();167 168 169 Thread.sleep(3000);170 171 //scroll down till GET STARTED172 driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\"Get started\").instance(0))").click();173 174 Thread.sleep(3000);175 176 //select any class177 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Grade 2 / Year 2\")")).click();178 179 Thread.sleep(3000);180 181 //scroll down till computer programming and click182 driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\"Computer programming\").instance(0))").click();183 184 Thread.sleep(3000);185 186 //click on done187 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Done\")")).click();188 189 Thread.sleep(3000);190 191 //settings for logout192 //click on settings button193 WebElement b2 = driver.findElements(By.className("android.widget.ImageView")).get(0);194 b2.click();195 //click on sign out196 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Sign out\")")).click();197 //click on SIGN OUT on next signout pop198 driver.findElement(By.id("android:id/button1")).click();199 200 201 service.stop();202 } 203 }204 ...

Full Screen

Full Screen

AppiumHelper.java

Source:AppiumHelper.java Github

copy

Full Screen

1package com.appium.framework.helper;2import com.appium.framework.utility.PropertiesUtility;3import io.appium.java_client.AppiumDriver;4import io.appium.java_client.MobileBy;5import io.appium.java_client.MobileElement;6import org.openqa.selenium.By;7import org.openqa.selenium.NoSuchElementException;8import org.openqa.selenium.support.ui.WebDriverWait;9import java.util.List;10public class AppiumHelper {11 protected AppiumDriver<MobileElement> driver;12 protected WebDriverWait wait;13 public AppiumHelper(AppiumDriver<MobileElement> _driver) {14 this.driver = _driver;15 wait = new WebDriverWait(_driver, 30);16 }17 public By findBy(PropertiesUtility propUtilObj, String locatorKey) {18 try {19 String locatedBy = propUtilObj.getLocatorType(locatorKey);20 String locatedValue = propUtilObj.getLocatorValue(locatorKey);21 if(locatedBy != null && locatedValue != null) {22 switch (locatedBy.toUpperCase()) {23 case "ACCESSIBILITYID":24 return MobileBy.ByAccessibilityId.AccessibilityId(locatedValue);25 case "CLASSNAME":26 return MobileBy.ByClassName.className(locatedValue);27 case "ID":28 return MobileBy.ById.id(locatedValue);29 case "NAME":30 return MobileBy.ByName.name(locatedValue);31 case "XPATH":32 return MobileBy.ByXPath.xpath(locatedValue);33 case "LINKTEXT":34 return MobileBy.ByLinkText.linkText(locatedValue);35 case "PARTIALLINKTEXT":36 return MobileBy.ByPartialLinkText.partialLinkText(locatedValue);37 }38 }39 } catch (NoSuchElementException ex) {40 System.out.println("Exception at <AppiumHelper>.<findBy> for Locator Key : " + locatorKey);41 }42 return null;43 }44 public MobileElement findElementBy(PropertiesUtility propUtilObj, String locatorKey) {45 try {46 String locatedBy = propUtilObj.getLocatorType(locatorKey);47 String locatedValue = propUtilObj.getLocatorValue(locatorKey);48 if(locatedBy != null && locatedValue != null) {49 switch (locatedBy.toUpperCase()) {50 case "ACCESSIBILITYID":51 return driver.findElementByAccessibilityId(locatedValue);52 case "CLASSNAME":53 return driver.findElementByClassName(locatedValue);54 case "ID":55 return driver.findElementById(locatedValue);56 case "NAME":57 return driver.findElementByName(locatedValue);58 case "XPATH":59 return driver.findElementByXPath(locatedValue);60 case "IMAGE":61 return driver.findElementByImage(locatedValue);62 case "LINKTEXT":63 return driver.findElementByLinkText(locatedValue);64 case "PARTIALLINKTEXT":65 return driver.findElementByPartialLinkText(locatedValue);66 }67 }68 } catch (NoSuchElementException ex) {69 System.out.println("Exception at <AppiumHelper>.<findElementBy> for Locator Key : " + locatorKey);70 }71 return null;72 }73 public List<MobileElement> findElementsBy(PropertiesUtility propUtilObj, String locatorKey) {74 try {75 String locatedBy = propUtilObj.getLocatorType(locatorKey);76 String locatedValue = propUtilObj.getLocatorValue(locatorKey);77 if(locatedBy != null && locatedValue != null) {78 switch (locatedBy.toUpperCase()) {79 case "ACCESSIBILITYID":80 return driver.findElementsByAccessibilityId(locatedValue);81 case "CLASSNAME":82 return driver.findElementsByClassName(locatedValue);83 case "ID":84 return driver.findElementsById(locatedValue);85 case "NAME":86 return driver.findElementsByName(locatedValue);87 case "XPATH":88 return driver.findElementsByXPath(locatedValue);89 case "IMAGE":90 return driver.findElementsByImage(locatedValue);91 case "LINKTEXT":92 return driver.findElementsByLinkText(locatedValue);93 case "PARTIALLINKTEXT":94 return driver.findElementsByPartialLinkText(locatedValue);95 }96 }97 } catch (NoSuchElementException ex) {98 System.out.println("Exception at <AppiumHelper>.<findElementsBy> for Locator Key : " + locatorKey);99 }100 return null;101 }102 public boolean isElementPresent(MobileBy by) {103 try {104 driver.findElement(by);105 return true;106 } catch (Exception ex) {107 return false;108 }109 }110 public boolean isElementPresent(By by) {111 try {112 driver.findElement(by);113 return true;114 } catch (Exception ex) {115 return false;116 }117 }118 public void sleep (long time) {119 try {120 Thread.sleep(time);121 } catch (InterruptedException e) {122 e.printStackTrace();123 }124 }125 public void hideKeyboard() {126 driver.hideKeyboard();127 }128 public void navigateBack() {129 driver.navigate().back();130 }131 public void navigateForward() {132 driver.navigate().forward();133 }134 public String getText(MobileElement element) {135 return element.getText();136 }137 public String getAtrribute(MobileElement element, String attributeName) {138 return element.getAttribute(attributeName);139 }140 public boolean isDisplayed(MobileElement element) {141 return element.isDisplayed();142 }143 public boolean isEnabled(MobileElement element) {144 return element.isEnabled();145 }146}...

Full Screen

Full Screen

AppiumTest4.java

Source:AppiumTest4.java Github

copy

Full Screen

1package Appium;2import java.io.File;3import java.net.MalformedURLException;4import java.net.URL;5import java.time.Duration;6import java.util.NoSuchElementException;7import java.util.concurrent.TimeUnit;8import java.util.function.Function;9import org.openqa.selenium.By;10import org.openqa.selenium.Dimension;11import org.openqa.selenium.WebElement;12import org.openqa.selenium.interactions.touch.TouchActions;13import org.openqa.selenium.remote.DesiredCapabilities;14import org.openqa.selenium.support.ui.ExpectedConditions;15import org.openqa.selenium.support.ui.FluentWait;16import org.openqa.selenium.support.ui.Wait;17import com.sun.corba.se.impl.orbutil.threadpool.TimeoutException;18import io.appium.java_client.MobileBy;19import io.appium.java_client.MobileElement;20import io.appium.java_client.TouchAction;21import io.appium.java_client.android.AndroidDriver;22import io.appium.java_client.android.AndroidElement;23import io.appium.java_client.android.AndroidTouchAction;24import io.appium.java_client.android.nativekey.AndroidKey;25import io.appium.java_client.android.nativekey.KeyEvent;26import io.appium.java_client.service.local.AppiumDriverLocalService;27import io.appium.java_client.service.local.AppiumServiceBuilder;28import io.appium.java_client.service.local.flags.GeneralServerFlag;29import io.appium.java_client.touch.LongPressOptions;30import io.appium.java_client.touch.WaitOptions;31import io.appium.java_client.touch.offset.ElementOption;32import io.appium.java_client.touch.offset.PointOption;33public class AppiumTest4 {34 public static void main(String[] args) throws MalformedURLException, InterruptedException {35 // TODO Auto-generated method stub36 AppiumDriverLocalService service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()37 38 .usingDriverExecutable(new File("C:\\Program Files\\nodejs\\node.exe"))39 .withAppiumJS(new File("C:\\Users\\Sanjay\\AppData\\Local\\Programs\\Appium\\resources\\app\\node_modules\\appium\\build\\lib\\main.js"))40 .withLogFile(new File("C:\\Users\\Sanjay\\Appium\\eclipse-workspace\\AppiumTest1\\src\\test\\resources\\Logs\\AppiumLogs\\Logs.log"))41 .withArgument(GeneralServerFlag.LOCAL_TIMEZONE));42 43 service.start(); 44 45 DesiredCapabilities dc = new DesiredCapabilities();46 dc.setCapability("deviceName", "65f651f31e00");47 dc.setCapability("platformName", "Android");48 dc.setCapability("automationName", "uiAutomator2");49 dc.setCapability("appPackage","in.amazon.mShop.android.shopping");50 dc.setCapability("appActivity","com.amazon.mShop.home.HomeActivity");51 52 AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),dc);53 driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);54 Thread.sleep(6000);55 driver.findElement(By.xpath("//android.widget.ImageView[@content-desc=\"Continue in English\"]")).click();56 driver.findElement(By.id("in.amazon.mShop.android.shopping:id/skip_sign_in_button")).click();57 58 Thread.sleep(2000);59 60 61 62 63 64 driver.findElement(MobileBy.AndroidUIAutomator(65 "new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().textContains(\"Deals of the Day\"))"));66 67 68 Wait<AndroidDriver> wait= new FluentWait(driver)69 .pollingEvery(Duration.ofMillis(300))70 .withTimeout(Duration.ofSeconds(10))71 .ignoring(NoSuchElementException.class)72 .ignoring(TimeoutException.class);73 74 MobileElement dealOftheDayELement= wait.until(new Function<AndroidDriver,MobileElement>(){75 @Override76 public MobileElement apply(AndroidDriver t) {77 // TODO Auto-generated method stub78 MobileElement element = driverfindElement(MobileBy.AndroidUIAutomator("new UiSelector().textContains(\"iQOO Z3 Series | India s first SD 768G 5G ₹ 19,990.00 - ₹ 22,990.00\")"));79 System.out.println(element.getAttribute("content-desc"));80 if(element.getAttribute("content-desc").equals("iQOO Z3 Series | India s first SD 768G 5G ₹ 19,990.00 - ₹ 22,990.00"))81 return element;82 else 83 return null;84 }85 private MobileElement driverfindElement(By androidUIAutomator) {86 // TODO Auto-generated method stub87 return null;88 }89 90 });91 92 93 TouchAction actions = new TouchAction(driver);94 actions.press(ElementOption.element(dealOftheDayELement)).release().perform();95 96 97 //driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).flingForward()"));98 99 Thread.sleep(6000);100 101 102 //scrollDown(driver); 103 //scrollUp(driver); 104 105 driver.quit();106 service.stop();107 108 }109 110 111 public static void scrollDown(AndroidDriver<AndroidElement> driver)112 {113 114 Dimension size = driver.manage().window().getSize();115 int center_x = (int) (size.width*0.5);116 int bottom_y = (int) (size.height*0.8);117 118 int top_y=(int) (size.height*0.2);119 120 121 for(int i=1;i<=10;i++) {122 123 AndroidTouchAction action = new AndroidTouchAction(driver);124 action.press(PointOption.point(center_x, bottom_y)).moveTo(PointOption.point(center_x, top_y)).release().perform();125 126 } 127 }128 129 130 public static void scrollUp(AndroidDriver<AndroidElement> driver)131 {132 Dimension size = driver.manage().window().getSize();133 int center= size.width/2;134 int top = 20;135 int bottom = size.height-10;136 for(int i=1;i<=10;i++) {137 138 AndroidTouchAction action = new AndroidTouchAction(driver);139 action.press(PointOption.point(center, top)).moveTo(PointOption.point(center, bottom)).release().perform();140 141 }142 }143 144}...

Full Screen

Full Screen

appiumTest.java

Source:appiumTest.java Github

copy

Full Screen

1package framework.appium;2import java.io.IOException;3import java.net.MalformedURLException;4import java.util.List;5import java.util.Set;6import java.util.concurrent.TimeUnit;7import org.openqa.selenium.By;8import org.openqa.selenium.Keys;9import org.openqa.selenium.WebElement;10import org.openqa.selenium.support.ui.Select;11import org.testng.Assert;12import org.testng.annotations.AfterTest;13import org.testng.annotations.BeforeMethod;14import org.testng.annotations.Test;15import io.appium.java_client.MobileBy;16import io.appium.java_client.TouchAction;17import io.appium.java_client.android.AndroidDriver;18import io.appium.java_client.android.AndroidElement;19import io.appium.java_client.android.nativekey.AndroidKey;20import io.appium.java_client.android.nativekey.KeyEvent;21import static io.appium.java_client.touch.TapOptions.tapOptions;22import static io.appium.java_client.touch.offset.ElementOption.element;23import static io.appium.java_client.touch.LongPressOptions.longPressOptions;24import static java.time.Duration.ofSeconds;25import static org.testng.Assert.assertEquals;26public class appiumTest extends capability{27 AndroidDriver<AndroidElement> driver;28 29 30 31 @BeforeMethod32 public void LaunchDevice() throws IOException, InterruptedException {33 service=startServer();34 driver =capabilities(appPacckage, appActivity, deviceName, platformName, chromeExecutable);35 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);36 Thread.sleep(4000);37 }38 39 @Test(priority=1)40 public void dismiss() throws InterruptedException {41 System.out.println("Khan Academy launched");42 //Thread.sleep(7000);43 //driver.findElement(MobileBy.AndroidUIAutomator(" UiSelector().text(\"Dismiss\")")).click();44 Thread.sleep(4000);45 driver.findElement(MobileBy.AndroidUIAutomator(" UiSelector().text(\"Dismiss\")")).click();46 Thread.sleep(6000);47 }48 @Test(priority=2)49 public void SignIn() throws InterruptedException {50 51 System.out.println("Khan Academy launched");52 driver.findElement(MobileBy.AndroidUIAutomator(" UiSelector().text(\"Sign in\")")).click();53 driver.findElement(By.xpath("//android.widget.Button[@content-desc=\"Continue with Google\"]/android.view.ViewGroup")).click();54 Thread.sleep(5000);55 driver.findElement(MobileBy.AndroidUIAutomator(" UiSelector().text(\"Add another account\")")).click();56 Thread.sleep(6000);57 driver.findElement(MobileBy.AndroidUIAutomator(" UiSelector().text(\"Email or phone\")")).sendKeys("thiagoragabrosh2012");58 driver.findElement(By.xpath("//android.widget.Button[@content-desc=\"Next \"]")).click();59 driver.findElement(By.xpath("//*[@class='android.view.View']")).sendKeys("Rupam@1995");60 driver.findElement(By.xpath("//android.widget.Button[@content-desc=\"Next \"]")).click();61 driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Yes, I’m in \"))").click();62 Thread.sleep(3000);63 //driver.findElement(By.xpath("//android.widget.Button[@content-desc=\"Yes, I’m in \"]")).click();64 //Thread.sleep(3000);65 driver.findElement(By.xpath("//android.widget.Button[@content-desc=\"I agree \"]")).click();66 Thread.sleep(6000);67 driver.findElement(By.xpath("//*[@class='android.widget.ImageView']")).click();68 String id = driver.findElement(MobileBy.AndroidUIAutomator(" UiSelector().text(\"thiagoragabrosh2012\")")).getText();69 System.out.println(id);70 }71 72 @Test(priority=3)73 public void SelectCourse() throws InterruptedException {74 driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Get started\"))").click();75 driver.findElement(MobileBy.AndroidUIAutomator(" UiSelector().text(\"Class 7\")")).click();76 driver.findElement(MobileBy.AndroidUIAutomator(" UiSelector().text(\"Algebra 1\")")).click();77 driver.findElement(MobileBy.AndroidUIAutomator(" UiSelector().text(\"Done\")")).click();78 Thread.sleep(4000);79 }80 81 82 @Test(priority=4)83 public void LanguageCheck() throws InterruptedException {84 driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Select language\"))").click();85 driver.findElement(By.xpath("//*[@class='android.widget.ImageView']")).click();86 Thread.sleep(4000);87 }88 89 @Test(priority=5)90 public void SignOut() throws InterruptedException {91 driver.findElement(By.xpath("//android.widget.ImageView[@content-desc=\"Settings\"]")).click();92 driver.findElement(MobileBy.AndroidUIAutomator(" UiSelector().text(\"Sign out\")")).click();93 }94 95 96 @AfterTest97 public void afterExecution() throws IOException, InterruptedException {98 service.stop();99 }100}...

Full Screen

Full Screen

Activity1_3GoogleKeep.java

Source:Activity1_3GoogleKeep.java Github

copy

Full Screen

1package Appium_Project_activities;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.By;5import org.openqa.selenium.remote.DesiredCapabilities;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8import org.testng.Assert;9import org.testng.annotations.AfterClass;10import org.testng.annotations.BeforeClass;11import org.testng.annotations.Test;12import io.appium.java_client.AppiumDriver;13import io.appium.java_client.MobileBy;14import io.appium.java_client.MobileElement;15import io.appium.java_client.android.AndroidDriver;16public class Activity1_3GoogleKeep {17 18 AppiumDriver<MobileElement> driver = null;19 WebDriverWait wait;20 @BeforeClass21 public void beforeClass() throws MalformedURLException {22 // Set the Desired Capabilities23 DesiredCapabilities caps = new DesiredCapabilities();24 caps.setCapability("deviceId", "f7bace58");25 caps.setCapability("deviceName", "OnePlus 7");26 caps.setCapability("platformName", "android");27 caps.setCapability("appPackage", "com.google.android.keep");28 caps.setCapability("appActivity", ".activities.BrowseActivity");29 caps.setCapability("noReset", true);30 // Instantiate Appium Driver31 URL appServer = new URL("http://0.0.0.0:4723/wd/hub");32 driver = new AndroidDriver<MobileElement>(appServer, caps);33 wait = new WebDriverWait(driver, 5);34 }35 @Test36 public void addNote_GoolgleNote() throws InterruptedException {37 MobileElement addNote = driver.findElementByXPath("//android.widget.ImageButton[@content-desc=\"New text note\"]");38 addNote.click();39 wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("com.google.android.keep:id/editable_title")));40 String Title = "resourceId(\"com.google.android.keep:id/editable_title\")"; 41 MobileElement NewTitle = driver.findElement(MobileBy.AndroidUIAutomator(Title));42 NewTitle.sendKeys("Appium Testing");43 wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("com.google.android.keep:id/edit_note_text")));44 String Text = "resourceId(\"com.google.android.keep:id/edit_note_text\")"; 45 MobileElement NewText = driver.findElement(MobileBy.AndroidUIAutomator(Text));46 NewText.sendKeys("We are learning mobile testing using Appium tool ");47 MobileElement Reminder = driver.findElementByXPath("//android.widget.TextView[@content-desc=\"Reminder\"]");48 Reminder.click();49 wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("com.google.android.keep:id/dialog_title")));50 MobileElement timeSlot =driver.findElement(By.xpath("//android.widget.TextView[contains(@text, '8:00 am')]"));51 timeSlot.click();52 wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("com.google.android.keep:id/text")));53 MobileElement Time =driver.findElement(By.xpath("//android.widget.TextView[contains(@text, 'Afternoon')]"));54 Time.click();55 Thread.sleep(300);56 driver.findElementById("com.google.android.keep:id/save").click();57 wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("com.google.android.keep:id/editable_title")));58 MobileElement Back = driver.findElementByXPath("//android.widget.ImageButton[@content-desc=\"Navigate up\"]");59 Back.click();60 wait.until(ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Open navigation drawer")));61 MobileElement NavigationDrawer = driver.findElementByXPath("//android.widget.ImageButton[@content-desc=\"Open navigation drawer\"]");62 NavigationDrawer.click();63 wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("com.google.android.keep:id/drawer_navigation_reminders")));64 MobileElement ReminderNavigation = driver.findElementById("com.google.android.keep:id/drawer_navigation_reminders");65 ReminderNavigation.click();66 MobileElement Note =driver.findElement(By.xpath("//android.widget.TextView[contains(@text, 'Appium Testing')]"));67 String NoteTitle = Note.getText();68 Assert.assertEquals(NoteTitle, "Appium Testing");69 70 71 72 }73 @AfterClass74 public void afterClass() {75 driver.quit();76 }77}...

Full Screen

Full Screen

AmazonShopByCategory.java

Source:AmazonShopByCategory.java Github

copy

Full Screen

1package com.mobile.tests;2import java.net.MalformedURLException;3import java.net.URL;4import java.time.Duration;5import java.util.concurrent.TimeUnit;6import org.openqa.selenium.Dimension;7import org.openqa.selenium.interactions.Actions;8import org.openqa.selenium.remote.DesiredCapabilities;9import io.appium.java_client.MobileBy;10import io.appium.java_client.TouchAction;11import io.appium.java_client.android.AndroidDriver;12import io.appium.java_client.android.AndroidElement;13import io.appium.java_client.remote.AndroidMobileCapabilityType;14import io.appium.java_client.remote.MobileCapabilityType;15import io.appium.java_client.touch.WaitOptions;16import io.appium.java_client.touch.offset.PointOption;17public class AmazonShopByCategory {18 public static void main(String args[]) throws MalformedURLException {19 DesiredCapabilities cap = new DesiredCapabilities();20 cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Pixel");21 cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");22 cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "in.amazon.mShop.android.shopping");23 cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.amazon.windowshop.home.HomeLauncherActivity");24 AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://0.0.0.0:4723/wd/hub"),25 cap);26 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);27 driver.findElement(MobileBy.xpath("//android.widget.GridLayout/android.widget.ImageView[1]")).click();28 driver.findElement(MobileBy.id("in.amazon.mShop.android.shopping:id/skip_sign_in_button")).click();29 driver.findElement(MobileBy.id("in.amazon.mShop.android.shopping:id/action_bar_burger_icon")).click();30 if (driver.findElements(MobileBy.AndroidUIAutomator("UiSelector().text(\"Explore all categories\")"))31 .size()!=0) {32 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Explore all categories\")")).click();33 } else {34 driver.findElement(MobileBy.xpath(35 "//android.widget.TextView[@resource-id='in.amazon.mShop.android.shopping:id/drawer_item_title' and @text='Shop by Category']"))36 .click();37 }38 Actions act = new Actions(driver);39 act.moveToElement(driver.findElement(MobileBy.xpath("//android.view.View[@text='Fire TV Stick']"))).click()40 .perform();41 // driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Fire TV42 // Stick\")")).click();43 driver.findElement(44 MobileBy.AndroidUIAutomator("UiSelector().text(\"Fire TV Stick with all-new Alexa Voice Remote\")"))45 .click();46 TouchAction action = new TouchAction(driver);47 Dimension d = driver.manage().window().getSize();48 int width = d.width;49 int height = d.height;50 int x1 = width / 2;51 int y1 = 4 * height / 5;52 int x2 = width / 2;53 int y2 = height / 2;54 action.press(PointOption.point(x1, y1)).waitAction(new WaitOptions().withDuration(Duration.ofMillis(3000)))55 .moveTo(PointOption.point(x2, y2)).release().perform();56 driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);57 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"Configuration: Fire TV Stick\")")).click();58 driver.findElement(59 MobileBy.AndroidUIAutomator("UiSelector().text(\"Fire TV Stick + Echo Dot 6999.00 In stock.\")"))60 .click();61 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"DONE\")")).click();62 driver.findElement(63 MobileBy.xpath("//android.view.View[@content-desc=\"ADD TO WISH LIST\"]/android.widget.TextView"))64 .click();65 }66}...

Full Screen

Full Screen

SwipeDemo.java

Source:SwipeDemo.java Github

copy

Full Screen

1package ca.testng.practice.testcases;2import java.net.MalformedURLException;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

AmazonAddProduct.java

Source:AmazonAddProduct.java Github

copy

Full Screen

1package com.mobile.tests;2import java.net.MalformedURLException;3import java.net.URL;4import java.time.Duration;5import java.util.concurrent.TimeUnit;6import org.openqa.selenium.Dimension;7import org.openqa.selenium.interactions.Actions;8import org.openqa.selenium.remote.DesiredCapabilities;9import io.appium.java_client.MobileBy;10import io.appium.java_client.TouchAction;11import io.appium.java_client.android.AndroidDriver;12import io.appium.java_client.android.AndroidElement;13import io.appium.java_client.android.nativekey.AndroidKey;14import io.appium.java_client.android.nativekey.KeyEvent;15import io.appium.java_client.remote.AndroidMobileCapabilityType;16import io.appium.java_client.remote.MobileCapabilityType;17import io.appium.java_client.touch.WaitOptions;18import io.appium.java_client.touch.offset.PointOption;19public class AmazonAddProduct {20 public static void main(String args[]) throws MalformedURLException {21 String searchKey = "iphone 7";22 DesiredCapabilities cap = new DesiredCapabilities();23 cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Pixel");24 cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");25 cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "in.amazon.mShop.android.shopping");26 cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.amazon.windowshop.home.HomeLauncherActivity");27 AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://0.0.0.0:4723/wd/hub"),28 cap);29 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);30 driver.findElement(MobileBy.xpath("//android.widget.GridLayout/android.widget.ImageView[1]")).click();31 driver.findElement(MobileBy.id("in.amazon.mShop.android.shopping:id/skip_sign_in_button")).click();32 driver.findElement(MobileBy.id("in.amazon.mShop.android.shopping:id/rs_search_src_text")).sendKeys(searchKey);33 driver.longPressKey(new KeyEvent(AndroidKey.ENTER));34 driver.findElement(MobileBy.AccessibilityId("Apple iPhone 7 (32GB) - Black")).click();35 if (driver.findElement(MobileBy.id("in.amazon.mShop.android.shopping:id/loc_ux_gps_enter_pincode"))36 .isDisplayed()) {37 driver.findElement(MobileBy.id("in.amazon.mShop.android.shopping:id/touch_outside")).click();38 }39 TouchAction action = new TouchAction(driver);40 Dimension d = driver.manage().window().getSize();41 int width = d.width;42 int height = d.height;43 int x1 = width / 2;44 int y1 = 4 * height / 5;45 int x2 = width / 2;46 int y2 = height / 2;47 action.press(PointOption.point(x1, y1)).waitAction(new WaitOptions().withDuration(Duration.ofMillis(3000)))48 .moveTo(PointOption.point(x2, y2)).release().perform();49 driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);50 Actions act = new Actions(driver);51 act.doubleClick(driver52 .findElement(MobileBy.xpath("//android.view.View[3]/android.view.View[4]/android.widget.Button")));53 driver.findElement(MobileBy.xpath("(//android.widget.Button)[2]")).click();54 driver.findElement(MobileBy.AndroidUIAutomator("UiSelector().text(\"DONE\")")).click();55 driver.findElement(MobileBy.id("add-to-cart-button")).click();56 }57}...

Full Screen

Full Screen

image

Using AI Code Generation

copy

Full Screen

1MobileElement element = (MobileElement) driver.findElement(MobileBy.image("path_to_image"));2MobileElement element = (MobileElement) driver.findElement(By.image("path_to_image"));3MobileElement element = (MobileElement) driver.findElement(MobileBy.image("path_to_image"));4MobileElement element = (MobileElement) driver.findElement(By.image("path_to_image"));5MobileElement element = (MobileElement) driver.findElement(MobileBy.image("path_to_image"));6MobileElement element = (MobileElement) driver.findElement(By.image("path_to_image"));7MobileElement element = (MobileElement) driver.findElement(MobileBy.image("path_to_image"));8MobileElement element = (MobileElement) driver.findElement(By.image("path_to_image"));9MobileElement element = (MobileElement) driver.findElement(MobileBy.image("path_to_image"));10MobileElement element = (MobileElement) driver.findElement(By.image("path_to_image"));11MobileElement element = (MobileElement) driver.findElement(MobileBy.image("path_to_image"));12MobileElement element = (MobileElement) driver.findElement(By.image("path_to_image"));13MobileElement element = (MobileElement) driver.findElement(MobileBy.image("path_to_image"));14MobileElement element = (MobileElement) driver.findElement(By.image("path_to_image"));

Full Screen

Full Screen

image

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.support.ui.ExpectedConditions;4import org.openqa.selenium.support.ui.WebDriverWait;5import org.testng.annotations.AfterTest;6import org.testng.annotations.BeforeTest;7import org.testng.annotations.Test;8import io.appium.java_client.AppiumDriver;9import io.appium.java_client.MobileElement;10import io.appium.java_client.android.AndroidDriver;11import io.appium.java_client.android.AndroidElement;12import io.appium.java_client.remote.MobileCapabilityType;13import io.appium.java_client.service.local.AppiumDriverLocalService;14import io.appium.java_client.service.local.AppiumServiceBuilder;15import io.appium.java_client.service.local.AppiumServiceBuilder;16import io.appium.java_client.service.local.flags.GeneralServerFlag;

Full Screen

Full Screen

image

Using AI Code Generation

copy

Full Screen

1MobileElement element = driver.findElement(MobileBy.Image("path of image file"));2MobileElement element = driver.findElement(MobileBy.Image("path of image file", options));3MobileElement element = driver.findElement(MobileBy.Image("path of image file", options, 30000));4MobileElement element = driver.findElement(MobileBy.Image("path of image file", options, 30000));5MobileElement element = driver.findElement(MobileBy.Image("path of image file", options, 30000));6MobileElement element = driver.findElement(MobileBy.Image("path of image file", options, 30000));7MobileElement element = driver.findElement(MobileBy.Image("path of image file", options, 30000));8MobileElement element = driver.findElement(MobileBy.Image("path of image file", options, 30000));9MobileElement element = driver.findElement(MobileBy.Image("path of image file", options, 30000));10MobileElement element = driver.findElement(MobileBy.Image("path of image file", options, 30000));

Full Screen

Full Screen

image

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.MobileBy;2MobileElement element = (MobileElement) driver.findElement(MobileBy.image("/path/to/image.png"));3#First we will import the MobileBy class4from appium.webdriver.common.mobileby import MobileBy5element = driver.find_element(MobileBy.IMAGE, "/path/to/image.png")6var MobileBy = require('appium').MobileBy;7var element = driver.findElement(MobileBy.image("/path/to/image.png"));8#First we will import the MobileBy class9element = driver.find_element(:image, "/path/to/image.png")10using OpenQA.Selenium.Appium.Android;11IWebElement element = driver.FindElement(MobileBy.Image("/path/to/image.png"));12use Appium\WebDriver\By;

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