From 14b86191764ea757dd2545c40356f45fe434a62f Mon Sep 17 00:00:00 2001 From: utkarsh Date: Fri, 23 Jan 2026 13:31:09 +0530 Subject: [PATCH 1/4] Refactor and other changes --- pom.xml | 166 +++++++++-------------------- src/main/java/AndroidApp.java | 98 ----------------- src/main/java/iOSApp.java | 89 ---------------- src/test/java/AndroidApp.java | 84 +++++++++++++++ src/test/java/android-parallel.xml | 14 ++- src/test/java/android-single.xml | 2 +- src/test/java/iOSApp.java | 69 ++++++++++++ src/test/java/ios-single.xml | 2 +- 8 files changed, 217 insertions(+), 307 deletions(-) delete mode 100644 src/main/java/AndroidApp.java delete mode 100644 src/main/java/iOSApp.java create mode 100644 src/test/java/AndroidApp.java create mode 100644 src/test/java/iOSApp.java diff --git a/pom.xml b/pom.xml index 7e3be79..828732c 100644 --- a/pom.xml +++ b/pom.xml @@ -1,154 +1,88 @@ - + + 4.0.0 org.example AppTest 1.0-SNAPSHOT + - 8 - 8 + 17 + 17 + 4.11.0 + + + + + org.seleniumhq.selenium + selenium-bom + ${selenium.version} + pom + import + + + + + + - - - org.seleniumhq.selenium - selenium-java - 3.141.59 - - + io.appium java-client - 7.6.0 - - - - org.testng - testng - 7.4.0 - test + 8.6.0 - - com.mashape.unirest - unirest-java - 1.4.9 - - - - org.webjars.npm - xmlhttprequest-ssl - 2.0.0 - + + org.seleniumhq.selenium + selenium-java + - - - org.json - json - 20211205 - + org.testng testng - 7.4.0 - compile + 7.9.0 + test + + + org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M5 + maven-compiler-plugin + 3.11.0 - - true - + 17 + 17 + + org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 + maven-surefire-plugin + 3.1.2 - 1.8 - 1.8 + + src/test/java/android-single.xml + + - - - android-single - - - - org.apache.maven.plugins - maven-surefire-plugin - - - src/test/java/android-single.xml - - - - - - - - - android-parallel - - - - org.apache.maven.plugins - maven-surefire-plugin - - - src/test/java/android-parallel.xml - - - - - - - - - ios-single - - - - org.apache.maven.plugins - maven-surefire-plugin - - - src/test/java/ios-single.xml - - - - - - - - ios-parallel - - - - org.apache.maven.plugins - maven-surefire-plugin - - - src/test/java/ios-parallel.xml - - - - - - - - - \ No newline at end of file + + diff --git a/src/main/java/AndroidApp.java b/src/main/java/AndroidApp.java deleted file mode 100644 index 8d940d6..0000000 --- a/src/main/java/AndroidApp.java +++ /dev/null @@ -1,98 +0,0 @@ -import io.appium.java_client.AppiumDriver; -import io.appium.java_client.MobileBy; -import io.appium.java_client.MobileElement; -import io.appium.java_client.android.AndroidElement; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.testng.annotations.Test; - -import java.net.URL; -import java.util.List; - -public class AndroidApp { - - String userName = System.getenv("LT_USERNAME") == null ? "username" : System.getenv("LT_USERNAME"); //Add username here - String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "accessKey" : System.getenv("LT_ACCESS_KEY"); //Add accessKey here - String app_id = System.getenv("LT_APP_ID") == null ? "lt://proverbial-android" : System.getenv("LT_APP_ID"); //Enter your LambdaTest App ID at the place of lt://proverbial-android - String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); - - AppiumDriver driver; - - @Test - @org.testng.annotations.Parameters(value = {"device", "version", "platform"}) - public void AndroidApp1(String device, String version, String platform) { - try { - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("build", "Java TestNG"); - capabilities.setCapability("name", platform + " " + device + " " + version); - capabilities.setCapability("deviceName", device); - capabilities.setCapability("platformVersion", version); - capabilities.setCapability("platformName", platform); - capabilities.setCapability("isRealMobile", true); - //AppURL (Create from Wikipedia.apk sample in project) - capabilities.setCapability("app", app_id); //Enter your app url - capabilities.setCapability("deviceOrientation", "PORTRAIT"); - capabilities.setCapability("network", false); - capabilities.setCapability("visual", true); - capabilities.setCapability("devicelog", true); - capabilities.setCapability("autoGrantPermissions", true); - - //capabilities.setCapability("geoLocation", "HK"); - - String hub = "https://" + userName + ":" + accessKey + "@" + grid_url + "/wd/hub"; - driver = new AppiumDriver(new URL(hub), capabilities); - - MobileElement color = (MobileElement) driver.findElementById("com.lambdatest.proverbial:id/color"); - //Changes color to pink - color.click(); - Thread.sleep(1000); - //Back to orginal color - color.click(); - - MobileElement text = (MobileElement) driver.findElementById("com.lambdatest.proverbial:id/Text"); - //Changes the text to "Proverbial" - text.click(); - - //toast will be visible - MobileElement toast = (MobileElement) driver.findElementById("com.lambdatest.proverbial:id/toast"); - toast.click(); - - //notification will be visible - MobileElement notification = (MobileElement) driver.findElementById("com.lambdatest.proverbial:id/notification"); - notification.click(); - Thread.sleep(2000); - - //Opens the geolocation page - MobileElement geo = (MobileElement) driver.findElementById("com.lambdatest.proverbial:id/geoLocation"); - geo.click(); - Thread.sleep(5000); - - //takes back to home page - MobileElement home = (MobileElement) driver.findElementByAccessibilityId("Home"); - home.click(); - - //Takes to speed test page - MobileElement speedtest = (MobileElement) driver.findElementById("com.lambdatest.proverbial:id/speedTest"); - speedtest.click(); - Thread.sleep(5000); - - MobileElement Home = (MobileElement) driver.findElementByAccessibilityId("Home"); - Home.click(); - - //Opens the browser - MobileElement browser = (MobileElement) driver.findElementByAccessibilityId("Browser"); - browser.click(); - - MobileElement url = (MobileElement) driver.findElementById("com.lambdatest.proverbial:id/url"); - url.sendKeys("https://www.lambdatest.com"); - - MobileElement find = (MobileElement) driver.findElementById("com.lambdatest.proverbial:id/find"); - find.click(); - driver.quit(); - } catch (Exception e) { - e.printStackTrace(); - } - - } -} diff --git a/src/main/java/iOSApp.java b/src/main/java/iOSApp.java deleted file mode 100644 index bd28a71..0000000 --- a/src/main/java/iOSApp.java +++ /dev/null @@ -1,89 +0,0 @@ -import io.appium.java_client.AppiumDriver; -import io.appium.java_client.MobileBy; -import io.appium.java_client.MobileElement; -import io.appium.java_client.android.AndroidElement; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.remote.DesiredCapabilities; - -import java.net.URL; - -import org.testng.annotations.Test; - -public class iOSApp { - - String userName = System.getenv("LT_USERNAME") == null ? "username" : System.getenv("LT_USERNAME"); //Add username here - String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "accessKey" : System.getenv("LT_ACCESS_KEY"); //Add accessKey here - String app_id = System.getenv("LT_APP_ID") == null ? "lt://proverbial-ios" : System.getenv("LT_APP_ID"); //Enter your LambdaTest App ID at the place of lt://proverbial-android - String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); - - AppiumDriver driver; - - @Test - @org.testng.annotations.Parameters(value = {"device", "version", "platform"}) - public void iOSApp1(String device, String version, String platform) { - - try { - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("build", "Java TestNG"); - capabilities.setCapability("name", platform + " " + device + " " + version); - capabilities.setCapability("deviceName", device); - capabilities.setCapability("platformVersion", version); - capabilities.setCapability("platformName", platform); - capabilities.setCapability("isRealMobile", true); - capabilities.setCapability("app", app_id); //Enter your app url - capabilities.setCapability("network", false); - capabilities.setCapability("visual", true); - capabilities.setCapability("devicelog", true); - //capabilities.setCapability("geoLocation", "HK"); - - String hub = "https://" + userName + ":" + accessKey + "@" + grid_url + "/wd/hub"; - driver = new AppiumDriver(new URL(hub), capabilities); - - WebDriverWait Wait = new WebDriverWait(driver, 30); - - //Changes the color of the text - Wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("color"))).click(); - Thread.sleep(1000); - - //Changes the text to "Proverbial" - Wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("Text"))).click(); - Thread.sleep(1000); - - //Toast will be visible - Wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("toast"))).click(); - Thread.sleep(1000); - - //Notification will be visible - Wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("notification"))).click(); - Thread.sleep(4000); - - //Opens the geolocation page - Wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("geoLocation"))).click(); - Thread.sleep(4000); - - //Takes back - driver.navigate().back(); - - //Takes to speedtest page - Wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("speedTest"))).click(); - Thread.sleep(4000); - driver.navigate().back(); - - //Opens the browser - Wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("Browser"))).click(); - Thread.sleep(1000); - MobileElement url = (MobileElement) driver.findElementByAccessibilityId("url"); - url.click(); - url.sendKeys("https://www.lambdatest.com"); - Wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("find"))).click(); - Thread.sleep(1000); - driver.quit(); - } catch (Exception e) { - e.printStackTrace(); - } - - } -} diff --git a/src/test/java/AndroidApp.java b/src/test/java/AndroidApp.java new file mode 100644 index 0000000..e028bc2 --- /dev/null +++ b/src/test/java/AndroidApp.java @@ -0,0 +1,84 @@ +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; +//import org.openqa.selenium.By; +import org.openqa.selenium.By; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +import java.net.URL; +import java.util.HashMap; + +public class AndroidApp { + + private AndroidDriver driver; + + String userName = System.getenv("LT_USERNAME"); + String accessKey = System.getenv("LT_ACCESS_KEY"); + String grid_url = "mobile-hub.lambdatest.com"; + + @Test + @Parameters({"device", "version", "platform"}) + public void AndroidApp1(String device, String version, String platform) { + + try { + // -------- Appium Options (W3C compliant) -------- + + + DesiredCapabilities capabilities = new DesiredCapabilities(); + HashMap ltOptions = new HashMap(); + ltOptions.put("w3c", true); + ltOptions.put("build", "Java TestNG"); + ltOptions.put("name", platform + " " + device + " " + version); + ltOptions.put("deviceName", device); + ltOptions.put("platformVersion", version); + ltOptions.put("platformName", platform); + ltOptions.put("app", "lt://APP1016054801767535388174642"); + ltOptions.put("autoGrantPermissions", true); + ltOptions.put("isRealMobile", true); + capabilities.setCapability("lt:options", ltOptions); + + + String hub = "https://" + userName + ":" + accessKey + "@" + + grid_url + "/wd/hub"; + + driver = new AndroidDriver(new URL(hub), capabilities); + + // -------- App Actions -------- + driver.findElement(By.id("com.lambdatest.proverbial:id/color")).click(); + Thread.sleep(1000); + driver.findElement(By.id("com.lambdatest.proverbial:id/color")).click(); + + driver.findElement(By.id("com.lambdatest.proverbial:id/Text")).click(); + driver.findElement(By.id("com.lambdatest.proverbial:id/toast")).click(); + + driver.findElement(By.id("com.lambdatest.proverbial:id/notification")).click(); + Thread.sleep(2000); + + driver.findElement(By.id("com.lambdatest.proverbial:id/geoLocation")).click(); + Thread.sleep(5000); + + driver.findElement(AppiumBy.accessibilityId("Home")).click(); + + driver.findElement(By.id("com.lambdatest.proverbial:id/speedTest")).click(); + Thread.sleep(5000); + + driver.findElement(AppiumBy.accessibilityId("Home")).click(); + + driver.findElement(AppiumBy.accessibilityId("Browser")).click(); + + driver.findElement(By.id("com.lambdatest.proverbial:id/url")) + .sendKeys("https://www.lambdatest.com"); + + driver.findElement(By.id("com.lambdatest.proverbial:id/find")).click(); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (driver != null) { + driver.quit(); + } + } + } +} diff --git a/src/test/java/android-parallel.xml b/src/test/java/android-parallel.xml index 5d21678..3ea06bf 100644 --- a/src/test/java/android-parallel.xml +++ b/src/test/java/android-parallel.xml @@ -3,7 +3,7 @@ - + @@ -12,7 +12,17 @@ - + + + + + + + + + + + diff --git a/src/test/java/android-single.xml b/src/test/java/android-single.xml index fe5d38c..10f09a5 100644 --- a/src/test/java/android-single.xml +++ b/src/test/java/android-single.xml @@ -4,7 +4,7 @@ - + diff --git a/src/test/java/iOSApp.java b/src/test/java/iOSApp.java new file mode 100644 index 0000000..5dcb445 --- /dev/null +++ b/src/test/java/iOSApp.java @@ -0,0 +1,69 @@ +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.ios.IOSDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +import java.net.URL; +import java.time.Duration; +import java.util.HashMap; + +public class iOSApp { + + String userName = System.getenv("LT_USERNAME") != null ? System.getenv("LT_USERNAME") : "username"; + String accessKey = System.getenv("LT_ACCESS_KEY") != null ? System.getenv("LT_ACCESS_KEY") : "accessKey"; + String appId = System.getenv("LT_APP_ID") != null ? System.getenv("LT_APP_ID") : "lt://proverbial-ios"; + String gridUrl = System.getenv("LT_GRID_URL") != null ? System.getenv("LT_GRID_URL") : "mobile-hub.lambdatest.com"; + + AppiumDriver driver; + + @Test + @Parameters({ "device", "version", "platform" }) + public void iOSApp1(String device, String version, String platform) { + + try { + DesiredCapabilities capabilities = new DesiredCapabilities(); + HashMap ltOptions = new HashMap(); + ltOptions.put("w3c", true); + ltOptions.put("build", "Java TestNG"); + ltOptions.put("name", platform + " " + device + " " + version); + ltOptions.put("deviceName", device); + ltOptions.put("platformVersion", version); + ltOptions.put("platformName", platform); + ltOptions.put("app", "lt://APP1016018631760361477812757"); + ltOptions.put("autoGrantPermissions", true); + ltOptions.put("isRealMobile", true); + capabilities.setCapability("lt:options", ltOptions); + + + String hub = "https://" + userName + ":" + accessKey + "@" + gridUrl + "/wd/hub"; + driver = new IOSDriver(new URL(hub), capabilities); // Use IOSDriver for iOS + + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + + // Use AppiumBy for all locators + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("color"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("toast"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("notification"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("geoLocation"))).click(); + driver.navigate().back(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("speedTest"))).click(); + driver.navigate().back(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Browser"))).click(); + + WebElement url = wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("url"))); + url.sendKeys("https://www.lambdatest.com"); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("find"))).click(); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (driver != null) driver.quit(); + } + } +} diff --git a/src/test/java/ios-single.xml b/src/test/java/ios-single.xml index 75a4e25..fb9d53e 100644 --- a/src/test/java/ios-single.xml +++ b/src/test/java/ios-single.xml @@ -4,7 +4,7 @@ - + From 675808face0db2872454765cbf06f4253a709fd4 Mon Sep 17 00:00:00 2001 From: utkarshbh785 Date: Mon, 9 Mar 2026 19:24:29 +0530 Subject: [PATCH 2/4] changes the appium version to 9^ and selenium version 4^ --- .gitignore | 60 +++---- README.md | 116 ++++++------- pom.xml | 264 +++++++++++++++++++---------- src/test/java/AndroidApp.java | 189 ++++++++++++--------- src/test/java/android-parallel.xml | 63 +++---- src/test/java/android-single.xml | 28 +-- src/test/java/iOSApp.java | 170 +++++++++++-------- src/test/java/ios-parallel.xml | 42 ++--- src/test/java/ios-single.xml | 26 +-- 9 files changed, 550 insertions(+), 408 deletions(-) diff --git a/.gitignore b/.gitignore index a5a78b6..f97dc16 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +1,30 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -/.idea/ -/.DS_Store -src/.DS_Store -.DS_Store -/target/ -/AppTest.iml -/apache-maven-3.8.5/ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +/.idea/ +/.DS_Store +src/.DS_Store +.DS_Store +/target/ +/AppTest.iml +/apache-maven-3.8.5/ diff --git a/README.md b/README.md index 118b775..c59f0e5 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,58 @@ -# LT-appium-java-testng - -Sample repo to run app automation on real device on LambdaTest. - -**Below is the curl request to upload the app for automation** - -``` -curl --location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \ ---header 'Authorization: Basic ' \ ---form 'name="lambda1"' \ ---form 'appFile=@"/path/to/file"' -``` - -### **Step-1: Upload your application** - -```bash -curl -u "YOUR_LAMBDATEST_USERNAME":"YOUR_LAMBDATEST_ACCESS_KEY" \ ---location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \ ---form 'name="Android_App"' \ ---form 'appFile=@"/Users/macuser/Downloads/proverbial_android.apk"' -``` - -> **Note:** -> -> - If you do not have any **.apk** or **.ipa** file, you can run your sample tests on LambdaTest by using our sample [Android app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk) or sample [iOS app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_ios.ipa). -> - Response of above cURL will be a **JSON** object containing the `App URL` of the format - and will be used in the next step. - -### **Step 2: Write Your Automation Script** - -Write your automation script in the client language of your choice from the ones [supported by Appium](https://appium.io/downloads.html). In the sample automation script in Java for the sample app downloaded above. Ensure to update the `app_url`, `username` and `accesskey` in the below code. - -### **Step 3: Execute Your Test Case** - -Debug and run your code. Run iOSApp.java or AndroidApp.java in your editor. - -**Android:** - -``` -mvn test -P android-single -``` - -``` -mvn test -P android-parallel -``` - -**IOS:** - -``` -mvn test -P ios-single -``` - -``` -mvn test -P ios-parallel -``` - -### **Step 4: View Test Execution** - -Once you have run your tests, you can view the test execution along with logs. You will be able to see the test cases passing or failing. You can view the same at [LambdaTest Automation](https://accounts.lambdatest.com/login). +# LT-appium-java-testng + +Sample repo to run app automation on real device on LambdaTest. + +**Below is the curl request to upload the app for automation** + +``` +curl --location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \ +--header 'Authorization: Basic ' \ +--form 'name="lambda1"' \ +--form 'appFile=@"/path/to/file"' +``` + +### **Step-1: Upload your application** + +```bash +curl -u "YOUR_LAMBDATEST_USERNAME":"YOUR_LAMBDATEST_ACCESS_KEY" \ +--location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \ +--form 'name="Android_App"' \ +--form 'appFile=@"/Users/macuser/Downloads/proverbial_android.apk"' +``` + +> **Note:** +> +> - If you do not have any **.apk** or **.ipa** file, you can run your sample tests on LambdaTest by using our sample [Android app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk) or sample [iOS app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_ios.ipa). +> - Response of above cURL will be a **JSON** object containing the `App URL` of the format - and will be used in the next step. + +### **Step 2: Write Your Automation Script** + +Write your automation script in the client language of your choice from the ones [supported by Appium](https://appium.io/downloads.html). In the sample automation script in Java for the sample app downloaded above. Ensure to update the `app_url`, `username` and `accesskey` in the below code. + +### **Step 3: Execute Your Test Case** + +Debug and run your code. Run iOSApp.java or AndroidApp.java in your editor. + +**Android:** + +``` +mvn test -P android-single +``` + +``` +mvn test -P android-parallel +``` + +**IOS:** + +``` +mvn test -P ios-single +``` + +``` +mvn test -P ios-parallel +``` + +### **Step 4: View Test Execution** + +Once you have run your tests, you can view the test execution along with logs. You will be able to see the test cases passing or failing. You can view the same at [LambdaTest Automation](https://accounts.lambdatest.com/login). diff --git a/pom.xml b/pom.xml index 828732c..ea9f7bb 100644 --- a/pom.xml +++ b/pom.xml @@ -1,88 +1,176 @@ - - - - 4.0.0 - - org.example - AppTest - 1.0-SNAPSHOT - - - - 17 - 17 - 4.11.0 - - - - - - org.seleniumhq.selenium - selenium-bom - ${selenium.version} - pom - import - - - - - - - - - - - - io.appium - java-client - 8.6.0 - - - - org.seleniumhq.selenium - selenium-java - - - - - org.testng - testng - 7.9.0 - test - - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.11.0 - - 17 - 17 - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.1.2 - - - src/test/java/android-single.xml - - - - - - - - + + + + 4.0.0 + + org.example + AppTest + 1.0-SNAPSHOT + + + UTF-8 + 22 + ${java.version} + ${java.version} + + + + + org.seleniumhq.selenium + selenium-java + 4.27.0 + + + + io.appium + java-client + 9.3.0 + + + + org.testng + testng + 7.10.2 + compile + + + + com.konghq + unirest-java + 3.14.5 + + + + org.json + json + 20240303 + + + + org.webjars.npm + xmlhttprequest-ssl + 2.1.2 + + + + org.slf4j + slf4j-simple + 2.0.13 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + ${java.version} + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.2 + + + true + + + + + + + + + android-single + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/java/android-single.xml + + + + + + + + + android-app-profiling + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/java/android-app-profiling.xml + + + + + + + + + android-parallel + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/java/android-parallel.xml + + + + + + + + + ios-single + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/java/ios-single.xml + + + + + + + + + ios-parallel + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/java/ios-parallel.xml + + + + + + + + + diff --git a/src/test/java/AndroidApp.java b/src/test/java/AndroidApp.java index e028bc2..63aebee 100644 --- a/src/test/java/AndroidApp.java +++ b/src/test/java/AndroidApp.java @@ -1,84 +1,105 @@ -import io.appium.java_client.AppiumBy; -import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.options.UiAutomator2Options; -//import org.openqa.selenium.By; -import org.openqa.selenium.By; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -import java.net.URL; -import java.util.HashMap; - -public class AndroidApp { - - private AndroidDriver driver; - - String userName = System.getenv("LT_USERNAME"); - String accessKey = System.getenv("LT_ACCESS_KEY"); - String grid_url = "mobile-hub.lambdatest.com"; - - @Test - @Parameters({"device", "version", "platform"}) - public void AndroidApp1(String device, String version, String platform) { - - try { - // -------- Appium Options (W3C compliant) -------- - - - DesiredCapabilities capabilities = new DesiredCapabilities(); - HashMap ltOptions = new HashMap(); - ltOptions.put("w3c", true); - ltOptions.put("build", "Java TestNG"); - ltOptions.put("name", platform + " " + device + " " + version); - ltOptions.put("deviceName", device); - ltOptions.put("platformVersion", version); - ltOptions.put("platformName", platform); - ltOptions.put("app", "lt://APP1016054801767535388174642"); - ltOptions.put("autoGrantPermissions", true); - ltOptions.put("isRealMobile", true); - capabilities.setCapability("lt:options", ltOptions); - - - String hub = "https://" + userName + ":" + accessKey + "@" - + grid_url + "/wd/hub"; - - driver = new AndroidDriver(new URL(hub), capabilities); - - // -------- App Actions -------- - driver.findElement(By.id("com.lambdatest.proverbial:id/color")).click(); - Thread.sleep(1000); - driver.findElement(By.id("com.lambdatest.proverbial:id/color")).click(); - - driver.findElement(By.id("com.lambdatest.proverbial:id/Text")).click(); - driver.findElement(By.id("com.lambdatest.proverbial:id/toast")).click(); - - driver.findElement(By.id("com.lambdatest.proverbial:id/notification")).click(); - Thread.sleep(2000); - - driver.findElement(By.id("com.lambdatest.proverbial:id/geoLocation")).click(); - Thread.sleep(5000); - - driver.findElement(AppiumBy.accessibilityId("Home")).click(); - - driver.findElement(By.id("com.lambdatest.proverbial:id/speedTest")).click(); - Thread.sleep(5000); - - driver.findElement(AppiumBy.accessibilityId("Home")).click(); - - driver.findElement(AppiumBy.accessibilityId("Browser")).click(); - - driver.findElement(By.id("com.lambdatest.proverbial:id/url")) - .sendKeys("https://www.lambdatest.com"); - - driver.findElement(By.id("com.lambdatest.proverbial:id/find")).click(); - - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (driver != null) { - driver.quit(); - } - } - } -} +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.AppiumBy; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.Test; + +import java.net.URL; +import java.time.Duration; +import java.util.HashMap; + +public class AndroidApp { + + String userName = System.getenv("LT_USERNAME") == null ? "username" : System.getenv("LT_USERNAME"); + String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "accessKey" : System.getenv("LT_ACCESS_KEY"); + String app_id = System.getenv("LT_APP_ID") == null ? "lt://proverbial-android" : System.getenv("LT_APP_ID"); + String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); + + AppiumDriver driver; + + @Test + @org.testng.annotations.Parameters(value = {"device", "version", "platform"}) + public void AndroidApp1(String device, String version, String platform) { + try { + DesiredCapabilities options = new DesiredCapabilities(); + HashMap ltOptions = new HashMap<>(); + ltOptions.put("w3c", true); + ltOptions.put("isRealMobile", true); + ltOptions.put("build", "Java TestNG Build"); + ltOptions.put("name", "Android Test"); + ltOptions.put("visual", true); + ltOptions.put("devicelog", true); + ltOptions.put("autoGrantPermissions", true); + ltOptions.put("platformName", "android"); + ltOptions.put("platformVersion", "15"); + ltOptions.put("deviceName", "Galaxy.*"); + ltOptions.put("app", "lt://APP 10160502491773060447490389"); + options.setCapability("lt:options", ltOptions); + + + String hub = "https://" + userName + ":" + accessKey + "@" + grid_url + "/wd/hub"; + + System.out.println("USERNAME: " + System.getenv("LT_USERNAME")); + System.out.println("ACCESS_KEY: " + System.getenv("LT_ACCESS_KEY")); + + driver = new AppiumDriver(new URL(hub), options); + + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + + // Changes color to pink + WebElement color = wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.id("com.lambdatest.proverbial:id/color"))); + color.click(); + Thread.sleep(1000); + color.click(); + + // Changes the text to "Proverbial" + WebElement text = wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.id("com.lambdatest.proverbial:id/Text"))); + text.click(); + + // Toast will be visible + WebElement toast = wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.id("com.lambdatest.proverbial:id/toast"))); + toast.click(); + + // Notification will be visible + WebElement notification = wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.id("com.lambdatest.proverbial:id/notification"))); + notification.click(); + Thread.sleep(2000); + + // Opens the geolocation page + WebElement geo = wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.id("com.lambdatest.proverbial:id/geoLocation"))); + geo.click(); + Thread.sleep(5000); + + // Takes back to home page + WebElement home = wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("Home"))); + home.click(); + + // Takes to speed test page + WebElement speedtest = wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.id("com.lambdatest.proverbial:id/speedTest"))); + speedtest.click(); + Thread.sleep(5000); + + // Back to home page + WebElement home2 = wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("Home"))); + home2.click(); + + // Opens the browser + WebElement browser = wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("Browser"))); + browser.click(); + + WebElement url = wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.id("com.lambdatest.proverbial:id/url"))); + url.click(); + url.sendKeys("https://www.lambdatest.com"); + + WebElement find = wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.id("com.lambdatest.proverbial:id/find"))); + find.click(); + + driver.quit(); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/test/java/android-parallel.xml b/src/test/java/android-parallel.xml index 3ea06bf..9044c4d 100644 --- a/src/test/java/android-parallel.xml +++ b/src/test/java/android-parallel.xml @@ -1,32 +1,33 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/android-single.xml b/src/test/java/android-single.xml index 10f09a5..919c1db 100644 --- a/src/test/java/android-single.xml +++ b/src/test/java/android-single.xml @@ -1,15 +1,15 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/iOSApp.java b/src/test/java/iOSApp.java index 5dcb445..49a3fe5 100644 --- a/src/test/java/iOSApp.java +++ b/src/test/java/iOSApp.java @@ -1,69 +1,101 @@ -import io.appium.java_client.AppiumBy; -import io.appium.java_client.AppiumDriver; -import io.appium.java_client.ios.IOSDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -import java.net.URL; -import java.time.Duration; -import java.util.HashMap; - -public class iOSApp { - - String userName = System.getenv("LT_USERNAME") != null ? System.getenv("LT_USERNAME") : "username"; - String accessKey = System.getenv("LT_ACCESS_KEY") != null ? System.getenv("LT_ACCESS_KEY") : "accessKey"; - String appId = System.getenv("LT_APP_ID") != null ? System.getenv("LT_APP_ID") : "lt://proverbial-ios"; - String gridUrl = System.getenv("LT_GRID_URL") != null ? System.getenv("LT_GRID_URL") : "mobile-hub.lambdatest.com"; - - AppiumDriver driver; - - @Test - @Parameters({ "device", "version", "platform" }) - public void iOSApp1(String device, String version, String platform) { - - try { - DesiredCapabilities capabilities = new DesiredCapabilities(); - HashMap ltOptions = new HashMap(); - ltOptions.put("w3c", true); - ltOptions.put("build", "Java TestNG"); - ltOptions.put("name", platform + " " + device + " " + version); - ltOptions.put("deviceName", device); - ltOptions.put("platformVersion", version); - ltOptions.put("platformName", platform); - ltOptions.put("app", "lt://APP1016018631760361477812757"); - ltOptions.put("autoGrantPermissions", true); - ltOptions.put("isRealMobile", true); - capabilities.setCapability("lt:options", ltOptions); - - - String hub = "https://" + userName + ":" + accessKey + "@" + gridUrl + "/wd/hub"; - driver = new IOSDriver(new URL(hub), capabilities); // Use IOSDriver for iOS - - WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); - - // Use AppiumBy for all locators - wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("color"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("toast"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("notification"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("geoLocation"))).click(); - driver.navigate().back(); - wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("speedTest"))).click(); - driver.navigate().back(); - wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Browser"))).click(); - - WebElement url = wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("url"))); - url.sendKeys("https://www.lambdatest.com"); - wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("find"))).click(); - - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (driver != null) driver.quit(); - } - } -} +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.options.UiAutomator2Options; +import io.appium.java_client.ios.IOSDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import java.net.URL; +import java.time.Duration; +import java.util.HashMap; +import org.testng.annotations.Test; + +public class iOSApp { + + String userName = System.getenv("LT_USERNAME") == null ? "username" : System.getenv("LT_USERNAME"); //Add username here + String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "accessKey" : System.getenv("LT_ACCESS_KEY"); //Add accessKey here + String app_id = System.getenv("LT_APP_ID") == null ? "lt://proverbial-ios" : System.getenv("LT_APP_ID"); //Enter your LambdaTest App ID at the place of lt://proverbial-android + String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); + + AppiumDriver driver; + + @Test + @org.testng.annotations.Parameters(value = {"device", "version", "platform"}) + public void iOSApp1(String device, String version, String platform) { + + try { +// UiAutomator2Options options = new UiAutomator2Options(); +// + + // LambdaTest Specific Options + DesiredCapabilities options = new DesiredCapabilities(); + HashMap ltOptions = new HashMap<>(); + ltOptions.put("w3c", true); + ltOptions.put("isRealMobile", true); + ltOptions.put("build", "Java TestNG iPad Build"); + ltOptions.put("name", "iOS iPad Test"); + ltOptions.put("visual", true); + ltOptions.put("devicelog", true); + ltOptions.put("platformName", "ios"); + ltOptions.put("platformVersion", "17"); + ltOptions.put("deviceName", "iPhone.*"); + ltOptions.put("app", "lt://APP10160171061769556365611264"); + options.setCapability("lt:options", ltOptions); + + String hub = "https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"; + + System.out.println("USERNAME: " + System.getenv("LT_USERNAME")); + System.out.println("ACCESS_KEY: " + System.getenv("LT_ACCESS_KEY")); + + driver = new IOSDriver(new URL(hub), options); + + + WebDriverWait Wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + + //Changes the color of the text + Wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("color"))).click(); + Thread.sleep(1000); + + //Changes the text to "Proverbial" + Wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("Text"))).click(); + Thread.sleep(1000); + + //Toast will be visible + Wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("toast"))).click(); + Thread.sleep(1000); + + //Notification will be visible + Wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("notification"))).click(); + Thread.sleep(8000); + + //Opens the geolocation page + Wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("geoLocation"))).click(); + Thread.sleep(4000); + + //Takes back + driver.navigate().back(); + + //Takes to speedtest page + Wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("speedTest"))).click(); + Thread.sleep(4000); + driver.navigate().back(); + + //Opens the browser + Wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("Browser"))).click(); + Thread.sleep(1000); + + WebElement url = Wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("url"))); + Thread.sleep(1000); + + url.click(); + url.sendKeys("https://www.lambdatest.com"); + Wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy.accessibilityId("find"))).click(); + Thread.sleep(1000); + driver.quit(); + } catch (Exception e) { + e.printStackTrace(); + } + + } +} \ No newline at end of file diff --git a/src/test/java/ios-parallel.xml b/src/test/java/ios-parallel.xml index 9a66b1b..95125e1 100644 --- a/src/test/java/ios-parallel.xml +++ b/src/test/java/ios-parallel.xml @@ -1,22 +1,22 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/ios-single.xml b/src/test/java/ios-single.xml index fb9d53e..77608df 100644 --- a/src/test/java/ios-single.xml +++ b/src/test/java/ios-single.xml @@ -1,14 +1,14 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file From fa1b52516d91058872512a584de2c69aaf3c6574 Mon Sep 17 00:00:00 2001 From: utkarshbh785 Date: Wed, 15 Apr 2026 01:47:03 +0530 Subject: [PATCH 3/4] Update src/test/java/AndroidApp.java Co-authored-by: Saurabh <86821971+Saurabh-LT@users.noreply.github.com> --- src/test/java/AndroidApp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/AndroidApp.java b/src/test/java/AndroidApp.java index 63aebee..8f1f9cf 100644 --- a/src/test/java/AndroidApp.java +++ b/src/test/java/AndroidApp.java @@ -35,7 +35,7 @@ public void AndroidApp1(String device, String version, String platform) { ltOptions.put("platformName", "android"); ltOptions.put("platformVersion", "15"); ltOptions.put("deviceName", "Galaxy.*"); - ltOptions.put("app", "lt://APP 10160502491773060447490389"); + ltOptions.put("app", ",{app_id}"); options.setCapability("lt:options", ltOptions); From 9af8dc028087705546f7e8277ac9876e9974192c Mon Sep 17 00:00:00 2001 From: utkarshbh785 Date: Wed, 15 Apr 2026 01:47:14 +0530 Subject: [PATCH 4/4] Update src/test/java/iOSApp.java Co-authored-by: Saurabh <86821971+Saurabh-LT@users.noreply.github.com> --- src/test/java/iOSApp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/iOSApp.java b/src/test/java/iOSApp.java index 49a3fe5..c184534 100644 --- a/src/test/java/iOSApp.java +++ b/src/test/java/iOSApp.java @@ -40,7 +40,7 @@ public void iOSApp1(String device, String version, String platform) { ltOptions.put("platformName", "ios"); ltOptions.put("platformVersion", "17"); ltOptions.put("deviceName", "iPhone.*"); - ltOptions.put("app", "lt://APP10160171061769556365611264"); + ltOptions.put("app", ""); options.setCapability("lt:options", ltOptions); String hub = "https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub";