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

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

AppiumAppTest.java

Source:AppiumAppTest.java Github

copy

Full Screen

...3import org.openqa.selenium.WebElement;4import org.openqa.selenium.interactions.Actions;5import org.openqa.selenium.remote.DesiredCapabilities;6import io.appium.java_client.AppiumBy;7import io.appium.java_client.android.AndroidDriver;8public class AppiumAppTest {9 static DesiredCapabilities dc = new DesiredCapabilities();10 static {11 dc.setCapability("deviceName", "Nexus_5_API_30");12 dc.setCapability("udid", "emulator-5554");13 dc.setCapability("platformName", "Android");14 dc.setCapability("platformVersion", "11.0");15 dc.setCapability("appPackage", "com.example.myapp");16 dc.setCapability("appActivity", "com.example.myapp.MainActivity");17 }18 static final String url = "http://127.0.0.1:4723/wd/hub";19 static int successfulTestCount;20 private AndroidDriver driver;21 22 public boolean isConnected() {23 if(driver == null)24 return false;25 return true;26 }27 28 public void connectServer() throws MalformedURLException {29 driver = new AndroidDriver(new URL(AppiumAppTest.url), dc);30 System.out.println("Connection established to server");31 32 }33 /** // 1. test: Anasayfa */34 public void test1() {35 // 1. test: Anasayfa36 if(!this.isConnected()) {37 System.err.println("Once server'a baglanin lutfen");38 return;39 }40 WebElement element = null;41 String currentPageText = new String();42 try {43 // tek erisim elemani xpath oldugundan onu kullandik, tavsiye edilmez44 element = driver.findElement(AppiumBy.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.view.ViewGroup/android.widget.TextView"));45 currentPageText = element.getText();46 if (currentPageText.equalsIgnoreCase("anasayfa"))47 System.out.println("Anasayfa Testi Basarili");48 else49 System.out.println("Anasayfa Testi Basarisiz");50 } catch (Exception e) {51 System.err.println("Anasayfa Yazisi Bulunamadi");52 }53 }54 /** // 2.1. Test: Anasayfa slayt // 2.2 Bilgi Yazisi */55 public void test2() {56 57 if(!this.isConnected()) {58 System.err.println("Once server'a baglanin lutfen");59 return;60 }61 Actions actions = new Actions(driver);62 WebElement element = null;63 try {64 element = driver.findElement(AppiumBy.accessibilityId("Slayt"));65 String elementClass = element.getAttribute("class");66 if (elementClass.equalsIgnoreCase("android.widget.imageview")) {67 System.out.println("Slayt Bulundu, Butonlar Deneniyor...");68 try {69 WebElement btn = driver.findElement(AppiumBy.id("com.example.myapp:id/btnSlideLeft"));70 if (btn.getAttribute("clickable").equalsIgnoreCase("True")) {71 actions.moveToElement(btn).click().perform();72 System.out.println("Sol Buton Calisiyor");73 } else {74 System.out.println("Sol Buton Calismiyor");75 }76 btn = driver.findElement(AppiumBy.id("com.example.myapp:id/btnSlideRight"));77 if (btn.getAttribute("clickable").equalsIgnoreCase("True")) {78 actions.moveToElement(btn).click().perform();79 System.out.println("Sag Buton Calisiyor");80 } else {81 System.out.println("Sag Buton Calismiyor");82 }83 } catch (Exception e) {84 System.out.println("Butonlar bulunurken hata");85 }86 }87 } catch (Exception e) {88 System.err.println("Anasayfa Slayti bulunamadi");89 } 90 91 try {92 element = driver.findElement(AppiumBy.id("com.example.myapp:id/tvMainAbout"));93 String text = "Bölümümüzün misyonu Bilgisayar Mühendisliği alanında bilgi "94 + "ve teknoloji üretmek, üretilen değerleri medeniyetlerin "95 + "ilerlemesi için kullanmak, ve yenilikçi ve araştırma eksenli "96 + "bir eğitim vererek kendine güvenen, girişimci, eleştirel analiz "97 + "yapabilen, teknik ve etik bilgilerle donatılmış, bilgisayar yazılım, "98 + "donanım ve bilgi sistemleri tasarlayabilen, geliştirebilen ve "99 + "sürdürebilen mühendisler yetiştirmektir.";100 101 if(element.getAttribute("text").equals(text)) {102 System.out.println("Bilgi yazisi dogru bir sekilde bulundu.");103 System.out.println("Yazi sinirlari: " + element.getAttribute("bounds"));104 }105 } catch (Exception e) {106 System.err.println("Bilgi Yazisi Bulunamadi");107 }108 }109 110 /** //open dropdown */111 public void test3a() {112 if(!this.isConnected()) {113 System.err.println("Once server'a baglanin lutfen");114 return;115 }116 WebElement element = null;117 try {118 System.out.println("Dropdown acilisi test ediliyor...");119 element = driver.findElement(AppiumBy.accessibilityId("Open navigation"));120 element.click();121 System.out.println("Dropdown aciliyor.");122 } catch (Exception e) {123 System.err.println("Dropdown Acilmiyor.");124 }125 }126 /** /close dropdown */127 public void test3b() {128 if(!this.isConnected()) {129 System.err.println("Once server'a baglanin lutfen");130 return;131 }132 WebElement element = null;133 try {134 System.out.println("Dropdown kapanisi test ediliyor...");135 element = driver.findElement(AppiumBy.accessibilityId("Close navigation"));136 element.click();137 System.out.println("Dropdown kapaniyor.");138 } catch (Exception e) {139 System.err.println("Dropdown Kapanmiyor.");140 }141 }142 /**143 //urun secenekleri144 //dropdown acmadan kullanmayin145 */146 public void test4() {147 if(!this.isConnected()) {148 System.err.println("Once server'a baglanin lutfen");149 return;150 }151 WebElement urun1 = null;152 WebElement urun2 = null;153 try { 154 System.out.println("Urunler kontrol ediliyor...");155 //yetiskin urun156 urun1 = driver.findElement(AppiumBy.id("com.example.myapp:id/miProductAdult"));157 158 if(urun1.getAttribute("clickable").equalsIgnoreCase("true"))159 System.out.println("Yetiskin urunleri bulundu");160 161 urun2 = driver.findElement(AppiumBy.id("com.example.myapp:id/miProductChild"));162 if(urun2.getAttribute("clickable").equalsIgnoreCase("true"))163 System.out.println("Cocuk urunleri bulundu");164 165 System.out.println("Urun secenekleri basarili.");166 } catch (Exception e) {167 System.err.println("Urunler Sekmesi Elemanlari Yetersiz ya da Bulunamadi");168 }169 }170 /**171 yetiskin urun sayfa sol-sag butonlari172 dropdown acmadan kullanmayin173 */174 public void test5a() {175 WebElement adltBtnLeft = null;176 WebElement adltBtnRight = null;177 WebElement urun1 = null;178 try {179 urun1 = driver.findElement(AppiumBy.id("com.example.myapp:id/miProductAdult"));180 urun1.click();181 System.out.println("Yetiskin butonlari deneniyor...");182 try {183 adltBtnRight = driver.findElement(AppiumBy.id("com.example.myapp:id/btnRight"));184 for (int i = 0; i < 6; i++) {185 adltBtnRight.click();186 }187 188 if(driver.findElement(AppiumBy.xpath("/hierarchy/android.widget.Toast")).getText().equalsIgnoreCase("zaten son sayfadasınız."))189 System.out.println("Ileri buton calisiyor");190 191 192 } catch (Exception e) {193 System.err.println("Ileri butonu bulunurken hata");194 }195 System.out.println("Geri butonu bekleniyor");196 try { 197 Thread.sleep(5000);198 adltBtnLeft = driver.findElement(AppiumBy.id("com.example.myapp:id/btnLeft"));199 200 for (int i = 0; i < 6; i++) {201 adltBtnLeft.click();202 }203 204 if(driver.findElement(AppiumBy.xpath("/hierarchy/android.widget.Toast")).getText().equalsIgnoreCase("zaten ilk sayfadasınız."))205 System.out.println("Geri buton calisiyor");206 207 } catch (Exception e) {208 System.err.println("Geri buton bulunurken hata");209 }210 } catch (Exception e) {211 System.err.println("Yetiskin ekranina gidilemedi");212 }213 }214 /**215 cocuk urun sayfa sol-sag butonlari216 dropdown acmadan kullanmayin217 */218 public void test5b() {219 WebElement urun2 = null;220 WebElement chldBtnLeft = null;221 WebElement chldBtnRight = null;222 try {223 urun2 = driver.findElement(AppiumBy.id("com.example.myapp:id/miProductChild"));224 urun2.click();225 System.out.println("Cocuk butonlari deneniyor...");226 try {227 chldBtnLeft = driver.findElement(AppiumBy.id("com.example.myapp:id/btnLeftChild"));228 chldBtnRight = driver.findElement(AppiumBy.id("com.example.myapp:id/btnRightChild"));229 230 for (int i = 0; i < 6; i++) {231 chldBtnRight.click();232 }233 if(driver.findElement(AppiumBy.xpath("/hierarchy/android.widget.Toast")).getText().equalsIgnoreCase("zaten son sayfadasınız."))234 System.out.println("Ileri buton calisiyor");235 } catch (Exception e) {236 System.err.println("Ileri butonu bulunurken hata");237 }238 System.out.println("Geri butonu bekleniyor");239 try {240 Thread.sleep(5000);241 for (int i = 0; i < 6; i++) {242 chldBtnLeft.click();243 }244 245 if(driver.findElement(AppiumBy.xpath("/hierarchy/android.widget.Toast")).getText().equalsIgnoreCase("zaten ilk sayfadasınız."))246 System.out.println("Geri buton calisiyor");247 } catch (Exception e) {248 System.err.println("Geri butonu bulunurken hata");249 }250 } catch (Exception e) {251 System.err.println("Cocuk ekranina gidilemedi");252 }253 }254 public static void main(String[] args) {255 AppiumAppTest a1 = new AppiumAppTest();256 try {257 a1.connectServer();258 a1.test1();259 a1.test2();260 a1.test3a();261 a1.test4();262 a1.test5a();263 //dropdown acmak icin264 try {265 Thread.sleep(5000);266 } catch (Exception e) {267 System.out.println("Beklenmesi gereken sure atlandi");268 }...

Full Screen

Full Screen

NotePadTest.java

Source:NotePadTest.java Github

copy

Full Screen

1import java.time.Duration;2import java.util.Iterator;3import java.util.List;4import io.appium.java_client.AppiumBy;5import io.appium.java_client.android.Activity;6import org.openqa.selenium.By;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.support.ui.ExpectedConditions;9import org.openqa.selenium.support.ui.WebDriverWait;10import org.testng.annotations.Test;11import static org.testng.Assert.assertEquals;12public class NotePadTest extends BaseAndroidTest{13 @Test14 //verifying the menu options are displayed15 public void verifyMenuOptions() {16 final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));17 Activity activity = new Activity("com.farmerbb.notepad", "com.farmerbb.notepad.MainActivity");18 driver.startActivity(activity);19 wait.until(ExpectedConditions.visibilityOfElementLocated(20 AppiumBy.accessibilityId("More options"))).click();21 wait.until(ExpectedConditions.visibilityOfElementLocated(22 AppiumBy.className("android.widget.ListView")));23 List<WebElement> listElements = driver.findElements(AppiumBy.id("com.farmerbb.notepad:id/title"));24 assertEquals(listElements.size(), 3);25 assertEquals(listElements.get(0).getText(), "Settings");26 assertEquals(listElements.get(1).getText(), "Import notes");27 assertEquals(listElements.get(2).getText(), "About Notepad");28 }29 @Test30 //verify selecting checkbox in setting option31 public void verifySettings() {32 final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));33 Activity activity = new Activity("com.farmerbb.notepad", "com.farmerbb.notepad.MainActivity");34 driver.startActivity(activity);35 wait.until(ExpectedConditions.visibilityOfElementLocated(36 AppiumBy.accessibilityId("More options"))).click();37 wait.until(ExpectedConditions.visibilityOfElementLocated(38 AppiumBy.className("android.widget.ListView")));39 wait.until(ExpectedConditions.visibilityOfElementLocated(40 By.xpath(".//*[@text='Settings']"))).click();41 wait.until(ExpectedConditions.visibilityOfElementLocated(42 AppiumBy.className("android.widget.ListView")));43 List<WebElement> listElements = driver.findElements(AppiumBy.id("android:id/checkbox"));44 assertEquals(listElements.size(), 4);45 Iterator<WebElement> elementIterator = listElements.iterator();46 while(elementIterator.hasNext()) {47 WebElement element = elementIterator.next();48 if (element.getAttribute("enabled").equals("true")) {49 element.click();50 }51 }52 driver.navigate().back();53 wait.until(ExpectedConditions.visibilityOfElementLocated(54 AppiumBy.accessibilityId("More options"))).click();55 wait.until(ExpectedConditions.visibilityOfElementLocated(56 AppiumBy.className("android.widget.ListView")));57 wait.until(ExpectedConditions.visibilityOfElementLocated(58 By.xpath(".//*[@text='Settings']"))).click();59 wait.until(ExpectedConditions.visibilityOfElementLocated(60 AppiumBy.className("android.widget.ListView")));61 listElements = driver.findElements(AppiumBy.id("android:id/checkbox"));62 elementIterator = listElements.iterator();63 while(elementIterator.hasNext()) {64 WebElement element = elementIterator.next();65 if (element.getAttribute("enabled").equals("true")) {66 assertEquals(element.getAttribute("checked"), "true");67 }68 }69 }70 @Test71 //verify creating notes72 public void verifyCreateNotes() {73 final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));74 Activity activity = new Activity("com.farmerbb.notepad", "com.farmerbb.notepad.MainActivity");75 driver.startActivity(activity);76 wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("com.farmerbb.notepad:id/button_floating_action"))).click();77 wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("com.farmerbb.notepad:id/editText1"))).sendKeys("mynotes 1");78 driver.navigate().back();79 driver.navigate().back();80 String expectedText=wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("com.farmerbb.notepad:id/noteTitle"))).getText();81 assertEquals(expectedText,"mynotes 1");82 }83 @Test84 //same verifySettings test using page objects85 public void verifySettingsUsingPageObject() {86 Activity activity = new Activity("com.farmerbb.notepad", "com.farmerbb.notepad.MainActivity");87 driver.startActivity(activity);88 HomePage homePage = new HomePage(driver);89 homePage.openSettings();90 SettingsPage settingsPage = new SettingsPage(driver);91 assertEquals(settingsPage.getCheckBoxesCount(), 4);92 settingsPage.selectAllCheckBoxes();93 driver.navigate().back();94 homePage.openSettings();95 settingsPage.verifyAllCheckBoxesAreSelected();96 }97}...

Full Screen

Full Screen

sampleTestAOSapp_Android.java

Source:sampleTestAOSapp_Android.java Github

copy

Full Screen

1import io.appium.java_client.AppiumBy;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.android.options.UiAutomator2Options;4import org.junit.*;5import org.openqa.selenium.support.ui.ExpectedConditions;6import org.openqa.selenium.support.ui.WebDriverWait;78import java.net.URL;9import java.time.Duration;10import java.util.concurrent.TimeUnit;1112public class sampleTestAOSapp_Android {13 private AndroidDriver driver;14 private String SERVER = "http://uftm-server:8080";1516 @Before17 public void setUp() throws Exception {18 UiAutomator2Options caps = new UiAutomator2Options();19 caps.setCapability("platformName", "Android");20 caps.setCapability("udid", "RF8N879MPYH");21 caps.setCapability("automationName", "UiAutomator2");22 caps.setCapability("appPackage", "com.Advantage.aShopping");23 caps.setCapability("appActivity", "com.Advantage.aShopping.SplashActivity");24 caps.setCapability("uftm:oauthClientId", "oauth2-m2pbTT3wUdAvsdBJXr0w@microfocus.com");25 caps.setCapability("uftm:oauthClientSecret", "tcNG3V5YVdjbgJhPl3Vl");26 caps.setCapability("uftm:tenantId", "999999999");27 driver = new AndroidDriver(new URL(SERVER + "/wd/hub"), caps);28 }2930 @After31 public void teardown(){32 if (driver != null) {33 driver.quit();34 }35 }3637 @Test38 public void testAOSapp(){39 //Implicit wait40 driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));41 driver.findElement(AppiumBy.xpath(42 "//android.view.ViewGroup[@content-desc=\"Home Page\"]/android.widget.LinearLayout[2]/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.RelativeLayout[1]/android.widget.TextView"))43 .click();44 driver.findElement(AppiumBy.xpath(45 "//android.widget.RelativeLayout[@content-desc=\"Laptops\"]/android.widget.LinearLayout/android.widget.GridView/android.widget.RelativeLayout[4]/android.widget.TextView[1]"))46 .click();47 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/linearLayoutProductDetails")).click();48 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/imageViewProductDetailsClose")).click();49 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/linearLayoutProductQuantity")).click();50 driver.findElement(AppiumBy.xpath(51 "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[2]/android.widget.ImageView[2]"))52 .click();53 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/textViewApply")).click();54 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/buttonProductAddToCart")).click();55 driver.findElement(AppiumBy.xpath(56 "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[2]/android.widget.RelativeLayout[3]/android.widget.EditText"))57 .sendKeys("Username");58 driver.findElement(AppiumBy.xpath(59 "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[2]/android.widget.RelativeLayout[4]/android.widget.EditText"))60 .sendKeys("password");61 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/buttonLogin")).click();62 String ErrorMessage = driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/textViewFailed")).getText();63 assert ErrorMessage.contains("Incorrect user");64 driver.navigate().back();65 driver.navigate().back();66 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/imageViewMenu")).click();67 driver.findElement(AppiumBy.id("com.Advantage.aShopping:id/textViewMenuHome")).click();6869 }7071}7273 ...

Full Screen

Full Screen

GestureTest.java

Source:GestureTest.java Github

copy

Full Screen

1package com.example.gestures;2import com.google.common.collect.ImmutableMap;3import io.appium.java_client.AppiumBy;4import io.appium.java_client.AppiumDriver;5import io.appium.java_client.android.AndroidDriver;6import io.appium.java_client.android.options.UiAutomator2Options;7import org.openqa.selenium.Point;8import org.openqa.selenium.Rectangle;9import org.openqa.selenium.WebElement;10import org.openqa.selenium.interactions.Pause;11import org.openqa.selenium.interactions.PointerInput;12import org.openqa.selenium.interactions.Sequence;13import org.openqa.selenium.logging.LogType;14import org.openqa.selenium.logging.LoggingPreferences;15import org.openqa.selenium.remote.RemoteWebElement;16import org.openqa.selenium.remote.http.HttpMethod;17import org.openqa.selenium.support.ui.ExpectedConditions;18import org.openqa.selenium.support.ui.WebDriverWait;19import org.testng.annotations.BeforeClass;20import org.testng.annotations.Test;21import java.net.URL;22import java.time.Duration;23import java.util.logging.Level;24import static java.time.Duration.*;25import static java.time.Duration.ofMillis;26import static java.util.Collections.singletonList;27import static org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable;28import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;29public class GestureTest {30 public AppiumDriver driver;31 public WebDriverWait wait;32 @BeforeClass33 public void beforeClass() throws Exception {34 UiAutomator2Options options = new UiAutomator2Options()35 .setDeviceName("Android Emulator")36 .setApp(System.getProperty("user.dir") + "/apps/VodQA.apk");37 driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), options);38 wait = new WebDriverWait(driver, ofSeconds(30));39 }40 @Test41 public void dragAndDropTest() {42 wait.until(elementToBeClickable(AppiumBy.accessibilityId("login"))).click();43 wait.until(elementToBeClickable(AppiumBy.accessibilityId("dragAndDrop"))).click();44 final WebElement dragMe = wait.until(presenceOfElementLocated(AppiumBy.accessibilityId("dragMe")));45 final WebElement dropzone = wait.until(elementToBeClickable(AppiumBy.accessibilityId("dropzone")));46 final Point point = dragMe.getRect().getPoint();47 final Rectangle rect = dropzone.getRect();48 final int targetX = rect.getX() + rect.getWidth() / 2;49 final int targetY = rect.getY() + rect.getHeight() / 2;50 PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");51 Sequence dragAndDrop = new Sequence(finger, 1);52 // pointerMove, pointerDown, pause, pointerMove, pointerUp53 dragAndDrop.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(),54 point.getX(), point.getY()));55 dragAndDrop.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));56 dragAndDrop.addAction(new Pause(finger, Duration.ofMillis(600)));57 dragAndDrop.addAction(finger.createPointerMove(Duration.ofMillis(600), PointerInput.Origin.viewport(),58 targetX, targetY));59 dragAndDrop.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));60 driver.perform(singletonList(dragAndDrop));61 }62 @Test63 public void dragAndDropUsingAppiumPluginTest() {64 wait.until(elementToBeClickable(AppiumBy.accessibilityId("login"))).click();65 wait.until(elementToBeClickable(AppiumBy.accessibilityId("dragAndDrop"))).click();66 final WebElement dragMe = wait.until(presenceOfElementLocated(AppiumBy.accessibilityId("dragMe")));67 final WebElement dropzone = wait.until(elementToBeClickable(AppiumBy.accessibilityId("dropzone")));68 driver.addCommand(HttpMethod.POST, String.format("/session/%s/plugin/actions/dragAndDrop",69 driver.getSessionId()), "dragAndDrop");70 driver.execute("dragAndDrop", ImmutableMap.of("sourceId", ((RemoteWebElement) dragMe).getId(),71 "destinationId", ((RemoteWebElement) dropzone).getId()));72 }73}...

Full Screen

Full Screen

SwagLabsLoginIos.java

Source:SwagLabsLoginIos.java Github

copy

Full Screen

...12import java.net.URL;13import java.time.Duration;14public class SwagLabsLoginIos {15 @Test16 public void login() throws MalformedURLException, InterruptedException {17 DesiredCapabilities capabilities=new DesiredCapabilities();18 capabilities.setCapability("platformName", "iOS");19 capabilities.setCapability("deviceName", "iPhone 13");20 capabilities.setCapability("automationName", "XCUITest");21 capabilities.setCapability("udid", "CB3931EC-0B2F-4763-AF77-723B5751DC2E");22 capabilities.setCapability("bundleId", "com.saucelabs.SwagLabsMobileApp");23 capabilities.setCapability("app", "/Users/gowthamipv/IdeaProjects/LoginPageios/src/test/resources/app/iOS.Simulator.SauceLabs.Mobile.Sample.app.2.7.1.app");24 IOSDriver driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);25 Thread.sleep(3000);26 driver.findElement(By.xpath("//XCUIElementTypeTextField[@name=\"test-Username\"]")).sendKeys("standard_user");27 Thread.sleep(3000);28 driver.findElement(By.xpath("//XCUIElementTypeSecureTextField[@name=\"test-Password\"]")).sendKeys("secret_sauce");29 Thread.sleep(3000);30 driver.findElement(By.xpath("//XCUIElementTypeOther[@name=\"test-LOGIN\"]")).click();31 Thread.sleep(3000);32 driver.findElement(By.xpath("(//XCUIElementTypeOther[@name=\"test-ADD TO CART\"])[2]")).click();33 Thread.sleep(3000);34 driver.findElement(By.xpath("(//XCUIElementTypeOther[@name=\"1\"])[4]")).click();35 Thread.sleep(3000);...

Full Screen

Full Screen

AndroidAbilityToUseSupplierTest.java

Source:AndroidAbilityToUseSupplierTest.java Github

copy

Full Screen

1package io.appium.java_client.android;2import static io.appium.java_client.TestUtils.getCenter;3import static io.appium.java_client.touch.WaitOptions.waitOptions;4import static io.appium.java_client.touch.offset.ElementOption.element;5import static java.time.Duration.ofSeconds;6import static org.junit.Assert.assertNotEquals;7import io.appium.java_client.AppiumBy;8import io.appium.java_client.functions.ActionSupplier;9import io.appium.java_client.touch.offset.ElementOption;10import org.junit.Test;11import org.openqa.selenium.By;12import org.openqa.selenium.Point;13import org.openqa.selenium.WebElement;14import java.util.List;15public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {16 private final ActionSupplier<AndroidTouchAction> horizontalSwipe = () -> {17 driver.findElement(By.id("io.appium.android.apis:id/gallery"));18 WebElement gallery = driver.findElement(By.id("io.appium.android.apis:id/gallery"));19 List<WebElement> images = gallery.findElements(AppiumBy.className("android.widget.ImageView"));20 Point location = gallery.getLocation();21 Point center = getCenter(gallery, location);22 ElementOption pressOption = element(images.get(2),-10,center.y - location.y);23 ElementOption moveOption = element(gallery, 10,center.y - location.y);24 return new AndroidTouchAction(driver)25 .press(pressOption)26 .waitAction(waitOptions(ofSeconds(2)))27 .moveTo(moveOption)28 .release();29 };30 private final ActionSupplier<AndroidTouchAction> verticalSwiping = () ->31 new AndroidTouchAction(driver)32 .press(element(driver.findElement(AppiumBy.accessibilityId("Gallery"))))33 .waitAction(waitOptions(ofSeconds(2)))34 .moveTo(element(driver.findElement(AppiumBy.accessibilityId("Auto Complete"))))35 .release();36 @Test public void horizontalSwipingWithSupplier() {37 Activity activity = new Activity("io.appium.android.apis", ".view.Gallery1");38 driver.startActivity(activity);39 WebElement gallery = driver.findElement(By.id("io.appium.android.apis:id/gallery"));40 List<WebElement> images = gallery.findElements(AppiumBy.className("android.widget.ImageView"));41 int originalImageCount = images.size();42 horizontalSwipe.get().perform();43 assertNotEquals(originalImageCount,44 gallery.findElements(AppiumBy.className("android.widget.ImageView")).size());45 }46 @Test public void verticalSwipingWithSupplier() throws Exception {47 driver.resetApp();48 driver.findElement(AppiumBy.accessibilityId("Views")).click();49 Point originalLocation = driver.findElement(AppiumBy.accessibilityId("Gallery")).getLocation();50 verticalSwiping.get().perform();51 Thread.sleep(5000);52 assertNotEquals(originalLocation, driver.findElement(AppiumBy.accessibilityId("Gallery")).getLocation());53 }54}...

Full Screen

Full Screen

sampleTestAOSapp_iOS.java

Source:sampleTestAOSapp_iOS.java Github

copy

Full Screen

...13 private IOSDriver driver;14 private String SERVER = "http://uftm-server:8080";1516 @Before17 public void setUp() throws Exception {18 XCUITestOptions caps = new XCUITestOptions();19 caps.setCapability("platformName", "iOS");20 caps.setCapability("udid", "3ecdf8889a8b18cb8858410d1540f3e6b22a2cb1");21 caps.setCapability("bundleId", "com.mf.iShopping");22 caps.setCapability("uftm:oauthClientId", "oauth2-m2pbTT3wUdAvsdBJXr0w@microfocus.com");23 caps.setCapability("uftm:oauthClientSecret", "tcNG3V5YVdjbgJhPl3Vl");24 caps.setCapability("uftm:tenantId", "999999999");25 driver = new IOSDriver(new URL(SERVER + "/wd/hub"), caps);26 }2728 @After29 public void teardown(){30 if (driver != null) {31 driver.quit();32 }33 }3435 @Test36 public void testAOSapp(){37 WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));38 driver.findElement(AppiumBy.xpath("//XCUIElementTypeStaticText[@name=\"LAPTOPS\"]")).click();39 driver.findElement(AppiumBy.accessibilityId("HP ENVY x360 - 15t Laptop")).click();40 wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("productDetailsButton"))).click();41 driver.findElement(AppiumBy.accessibilityId("Close2")).click();42 driver.findElement(AppiumBy.accessibilityId("quantityButtonId")).click();43 driver.findElement(AppiumBy.accessibilityId("Plus")).click();44 driver.findElement(AppiumBy.accessibilityId("APPLY")).click();45 driver.findElement(AppiumBy.accessibilityId("ADD TO CART")).click();46 driver.findElement(AppiumBy.accessibilityId("Ok")).click();47 driver.findElement(AppiumBy.accessibilityId("userNameLabel")).sendKeys("Username");48 driver.findElement(AppiumBy.accessibilityId("passwordLabel")).sendKeys("password");49 driver.findElement(AppiumBy.accessibilityId("LOGIN")).click();50 WebElement loginErrorText = wait.until(ExpectedConditions.presenceOfElementLocated( ...

Full Screen

Full Screen

AndroidSampleWithSelenium4Tests.java

Source:AndroidSampleWithSelenium4Tests.java Github

copy

Full Screen

2//3//import io.appium.java_client.AppiumBy;4//import io.appium.java_client.MobileBy;5//6//import io.appium.java_client.android.AndroidDriver;7//import org.junit.jupiter.api.Test;8//import org.openqa.selenium.WebElement;9//import org.openqa.selenium.remote.DesiredCapabilities;10//import org.openqa.selenium.support.ui.ExpectedConditions;11//import org.openqa.selenium.support.ui.WebDriverWait;12//13//import java.net.MalformedURLException;14//import java.net.URL;15//import java.util.List;16//17//public class AndroidSampleWithSelenium4Tests {18// @Test19// void searchTest() throws MalformedURLException, InterruptedException {20//21// DesiredCapabilities caps = new DesiredCapabilities();22//23// // Set your access credentials24// caps.setCapability("browserstack.user", "tpuretest_lSVWc2");25// caps.setCapability("browserstack.key", "Ggd5nW19cyeGseGGn2m6");26//27// // Set URL of the application under test28// caps.setCapability("app", "bs://c700ce60cf13ae8ed97705a55b8e022f13c5827c");29//30// // Specify device and os_version for testing31// caps.setCapability("device", "Google Pixel 3");32// caps.setCapability("os_version", "9.0");33//34// // Set other BrowserStack capabilities35// caps.setCapability("project", "First Java Project");36// caps.setCapability("build", "browserstack-build-1");37// caps.setCapability("name", "first_test");38//39//40// // Initialise the remote Webdriver using BrowserStack remote URL41// // and desired capabilities defined above42// AndroidDriver driver = new AndroidDriver(43// new URL("http://hub.browserstack.com/wd/hub"), caps);44//45// // Test case for the BrowserStack sample Android app.46// // If you have uploaded your app, update the test case here.47// WebElement searchElement = (WebElement) new WebDriverWait(driver, 30).until(48// ExpectedConditions.elementToBeClickable(49// AppiumBy.accessibilityId("Search Wikipedia")));50// searchElement.click();51// WebElement insertTextElement = (WebElement) new WebDriverWait(driver, 30).until(52// ExpectedConditions.elementToBeClickable(53// AppiumBy.id("org.wikipedia.alpha:id/search_src_text")));54// insertTextElement.sendKeys("BrowserStack");55// Thread.sleep(5000);56//// List<WebElement> allProductsName = driver.findElementsByClassName(57//// "android.widget.TextView");58//// assert(allProductsName.size() > 0);59//60//61// // Invoke driver.quit() after the test is done to indicate that the test is completed.62// driver.quit();63//64// }65//}...

Full Screen

Full Screen

id

Using AI Code Generation

copy

Full Screen

1WebElement element = driver.findElement(AppiumBy.id("id"));2WebElement element = driver.findElement(AppiumBy.className("className"));3WebElement element = driver.findElement(AppiumBy.AccessibilityId("accessibilityId"));4WebElement element = driver.findElement(AppiumBy.xpath("xpath"));5WebElement element = driver.findElement(AppiumBy.name("name"));6WebElement element = driver.findElement(AppiumBy.AndroidUIAutomator("androidUIAutomator"));7WebElement element = driver.findElement(AppiumBy.iOSUIAutomation("iOSUIAutomation"));8WebElement element = driver.findElement(AppiumBy.image("image"));9WebElement element = driver.findElement(AppiumBy.custom("custom"));10WebElement element = driver.findElement(AppiumBy.cssSelector("cssSelector"));11WebElement element = driver.findElement(AppiumBy.linkText("linkText"));12WebElement element = driver.findElement(AppiumBy.partialLinkText("partialLinkText"));13WebElement element = driver.findElement(AppiumBy.tagName("tagName"));14WebElement element = driver.findElement(AppiumBy.iosNsPredicateString("iosNsPredicateString"));15WebElement element = driver.findElement(AppiumBy.iosClassChain("iosClassChain"));16WebElement element = driver.findElement(AppiumBy.windowsAutomation("windowsAutomation

Full Screen

Full Screen

id

Using AI Code Generation

copy

Full Screen

1WebElement element = driver.findElement(AppiumBy.id("id"));2WebElement element = driver.findElement(AppiumBy.name("name"));3WebElement element = driver.findElement(AppiumBy.className("className"));4WebElement element = driver.findElement(AppiumBy.linkText("linkText"));5WebElement element = driver.findElement(AppiumBy.partialLinkText("partialLinkText"));6WebElement element = driver.findElement(AppiumBy.tagName("tagName"));7WebElement element = driver.findElement(AppiumBy.xpath("xpath"));8WebElement element = driver.findElement(AppiumBy.cssSelector("cssSelector"));9WebElement element = driver.findElement(AndroidBy.androidUIAutomator("androidUIAutomator"));10WebElement element = driver.findElement(AndroidBy.accessibilityId("accessibilityId"));11WebElement element = driver.findElement(AndroidBy.className("className"));12WebElement element = driver.findElement(AndroidBy.id("id"));13WebElement element = driver.findElement(AndroidBy.linkText("linkText"));14WebElement element = driver.findElement(AndroidBy.name("name"));15WebElement element = driver.findElement(AndroidBy.partialLinkText("partialLinkText"));16WebElement element = driver.findElement(AndroidBy.tagName("tagName"));

Full Screen

Full Screen

id

Using AI Code Generation

copy

Full Screen

1WebElement element = driver.findElement(AppiumBy.id("my_id"));2WebElement element = driver.findElement(AppiumBy.name("my_name"));3WebElement element = driver.findElement(AppiumBy.tagName("my_tag_name"));4WebElement element = driver.findElement(AppiumBy.xpath("my_xpath"));5WebElement element = driver.findElement(AppiumBy.cssSelector("my_css_selector"));6WebElement element = driver.findElement(AppiumBy.className("my_class_name"));7WebElement element = driver.findElement(AppiumBy.linkText("my_link_text"));8WebElement element = driver.findElement(AppiumBy.partialLinkText("my_partial_link_text"));9WebElement element = driver.findElement(AppiumBy.accessibilityId("my_accessibility_id"));10WebElement element = driver.findElement(AppiumBy.androidUIAutomator("my_android_uiautomator"));

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