diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..e6f7b76 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..74cb00e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..276516c --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,33 @@ +trigger: + branches: + include: + - main + - master + - fix/appium-tests # Add any other branches you want to trigger the pipeline + +pool: + name: 'Default' + +# ============================== +# Variable Group +# ============================== +variables: + - group: LambdaTest-Credentials # Assuming you have a variable group for credentials + +# ============================== +# Steps +# ============================== +steps: + + # Checkout the repo to get the latest changes + - checkout: self + clean: true + + # Run Android tests with the 'android' profile + - script: | + echo Running Android Tests with Appium + mvn test -P android + displayName: 'Run Android Tests' + env: + LT_USERNAME: $(LT_USERNAME) # LambdaTest username (securely injected from variable group) + LT_ACCESS_KEY: $(LT_ACCESS_KEY) # LambdaTest access key (securely injected from variable group) diff --git a/pom.xml b/pom.xml index 8e2731f..968716f 100644 --- a/pom.xml +++ b/pom.xml @@ -10,89 +10,46 @@ UTF-8 + + + 4.11.0 - - - - - - org.seleniumhq.selenium - selenium-java - 3.141.59 - + + + + org.seleniumhq.selenium + selenium-bom + ${selenium.version} + pom + import + + + + - - com.github.lambdatest - lambdatest-tunnel-binary - 1.0.10 - - - - io.github.bonigarcia - webdrivermanager - 4.3.1 - + + + - commons-io - commons-io - 2.11.0 + io.appium + java-client + 8.6.0 + org.seleniumhq.selenium - selenium-support - 2.52.0 - - - io.appium - java-client - 7.6.0 + selenium-java + + org.testng testng - 7.6.1 - - - commons-lang - commons-lang - 2.6 - - - - org.apache.commons - commons-lang3 - 3.0 - - - - info.cukes - cucumber-java - 1.2.5 - - - - junit - junit - 4.12 + 7.9.0 test - - org.json - json - 20160810 - - - org.seleniumhq.selenium - selenium-remote-driver - 3.141.59 - - - io.rest-assured - rest-assured - 4.3.0 - diff --git a/src/test/java/vanilla_android.java b/src/test/java/vanilla_android.java index 6009380..1ad8b52 100644 --- a/src/test/java/vanilla_android.java +++ b/src/test/java/vanilla_android.java @@ -1,91 +1,96 @@ import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileBy; -import io.appium.java_client.MobileElement; +//import io.appium.java_client.WebElement; +import org.openqa.selenium.WebElement; +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.MalformedURLException; import java.net.URL; +import java.util.HashMap; public class vanilla_android { - public static String userName = System.getenv("LT_USERNAME") == null ? "YOUR_USERNAME" // Add username here - : System.getenv("LT_USERNAME"); - public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_ACCESS_KEY" // Add accessKey here - : System.getenv("LT_ACCESS_KEY"); + public static String userName = System.getenv("LT_USERNAME") == null ? "YOUR_USERNAME" : System.getenv("LT_USERNAME"); + public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); - private static AppiumDriver driver; + static AppiumDriver driver; public static void main(String args[]) throws MalformedURLException, InterruptedException { try { DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("deviceName", "Galaxy S20"); - capabilities.setCapability("platformVersion", "11"); - capabilities.setCapability("platformName", "Android"); - capabilities.setCapability("isRealMobile", true); - capabilities.setCapability("app", "APP_URL"); // Enter your app url - capabilities.setCapability("deviceOrientation", "PORTRAIT"); - capabilities.setCapability("build", "Java Vanilla - Android"); - capabilities.setCapability("name", "Sample Test Java"); - capabilities.setCapability("console", true); - capabilities.setCapability("network", false); - capabilities.setCapability("visual", true); - capabilities.setCapability("devicelog", true); - - driver = new AppiumDriver( + HashMap ltOptions = new HashMap(); + ltOptions.put("deviceName", "Galaxy.*"); // You can specify a particular model, or use a wildcard. + ltOptions.put("platformVersion", "14"); // Make sure this matches the device's OS version. + ltOptions.put("platformName", "Android"); + ltOptions.put("isRealMobile", true); // Ensures that the test runs on a real device. + ltOptions.put("app", "lt://APP10160622431766424164986229"); // Your app URL from LambdaTest. + ltOptions.put("deviceOrientation", "PORTRAIT"); + ltOptions.put("build", "Java Vanilla - Android"); + ltOptions.put("name", "Sample Test Java"); + ltOptions.put("console", true); + ltOptions.put("autoGrantPermissions", true); // Auto grants permissions on the app. + ltOptions.put("network", false); + ltOptions.put("visual", true); + ltOptions.put("devicelog", true); + capabilities.setCapability("lt:options", ltOptions); + + // Initialize Appium driver with the LambdaTest server URL and capabilities + driver = new AndroidDriver( new URL("https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), capabilities); - MobileElement color = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/color")); + // Interact with elements using their IDs + WebElement color = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/color")); color.click(); - MobileElement text = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/Text")); - // Changes the text to proverbial + WebElement text = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/Text")); text.click(); - // toast is visible - MobileElement toast = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/toast")); + // Interact with Toast message element + WebElement toast = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/toast")); toast.click(); - // notification is visible - MobileElement notification = (MobileElement) driver - .findElement(MobileBy.id("com.lambdatest.proverbial:id/notification")); + // Interact with Notification element + WebElement notification = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/notification")); notification.click(); - // Open the geolocation page - MobileElement geo = (MobileElement) driver - .findElement(MobileBy.id("com.lambdatest.proverbial:id/geoLocation")); + // Open the Geolocation page + WebElement geo = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/geoLocation")); geo.click(); Thread.sleep(5000); - // takes back to home page - MobileElement el3 = (MobileElement) driver.findElementByAccessibilityId("Home"); - + // Go back to the home page driver.navigate().back(); Thread.sleep(2000); - // Takes to speed test page - MobileElement speedtest = (MobileElement) driver - .findElement(MobileBy.id("com.lambdatest.proverbial:id/speedTest")); + // Navigate to the Speed Test page + WebElement speedtest = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/speedTest")); speedtest.click(); Thread.sleep(5000); driver.navigate().back(); - // Opens the browser - MobileElement browser = (MobileElement) driver.findElement(MobileBy.AccessibilityId("Browser")); + // Open the Browser and perform actions + WebElement browser = driver.findElement(MobileBy.AccessibilityId("Browser")); browser.click(); - MobileElement url = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/url")); + WebElement url = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/url")); url.sendKeys("https://www.lambdatest.com"); - MobileElement find = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/find")); + + WebElement find = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/find")); find.click(); } catch (AssertionError a) { + // Mark the status as failed if there's an error ((JavascriptExecutor) driver).executeScript("lambda-status=failed"); a.printStackTrace(); + } finally { + // Ensure the driver quits to avoid the session hanging + if (driver != null) { + driver.quit(); + } } - // The driver.quit statement is required, otherwise the test continues to - // execute, leading to a timeout. - driver.quit(); } } diff --git a/src/test/java/vanilla_ios.java b/src/test/java/vanilla_ios.java index cb51dd4..bbf8556 100644 --- a/src/test/java/vanilla_ios.java +++ b/src/test/java/vanilla_ios.java @@ -1,100 +1,77 @@ -import io.appium.java_client.MobileBy; -import io.appium.java_client.MobileElement; +import io.appium.java_client.AppiumBy; 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; public class vanilla_ios { - public static String userName = System.getenv("LT_USERNAME") == null ? "YOUR_USERNAME" // Add username here - : System.getenv("LT_USERNAME"); - public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_ACCESS_KEY" // Add accessKey here - : System.getenv("LT_ACCESS_KEY"); + public static String userName = System.getenv("LT_USERNAME") == null ? "YOUR_USERNAME" : System.getenv("LT_USERNAME"); + public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); - public static final String URL = "https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"; public static IOSDriver driver = null; public static void main(String[] args) throws Exception { try { DesiredCapabilities caps = new DesiredCapabilities(); - caps.setCapability("platformVersion", "15"); - caps.setCapability("deviceName", "iPhone 12"); - caps.setCapability("isRealMobile", true); - caps.setCapability("app", "APP_URL"); // Enter your app url - caps.setCapability("platformName", "iOS"); - caps.setCapability("build", "Java Vanilla - iOS"); - caps.setCapability("name", "Sample Test Java"); - caps.setCapability("devicelog", true); - caps.setCapability("network", false); + HashMap ltOptions = new HashMap(); + + ltOptions.put("w3c", true); + ltOptions.put("platformName", "iOS"); + ltOptions.put("deviceName", "iPhone.*"); // Updated to a newer model for better stability + ltOptions.put("platformVersion", "17"); + ltOptions.put("isRealMobile", true); + ltOptions.put("app", "lt://APP1016018631760361477812757"); // Use your iOS App URL + ltOptions.put("build", "Java Vanilla - iOS"); + ltOptions.put("name", "Sample Test Java iOS"); + ltOptions.put("devicelog", true); + ltOptions.put("autoAcceptAlerts", true); + ltOptions.put("network", false); + ltOptions.put("visual", true); + + caps.setCapability("lt:options", ltOptions); driver = new IOSDriver( new URL("https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), caps); - Thread.sleep(2000); - - // Changes color + // Wait utility + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); - driver.findElement(MobileBy.id("color")).click(); - Thread.sleep(1000); - - // Back to black color - driver.navigate().back(); + // 1. Changes color + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("color"))).click(); - Thread.sleep(1000); + // 2. Changes the text + driver.findElement(AppiumBy.id("Text")).click(); - // Changes the text to proverbial - driver.findElement(MobileBy.id("Text")).click(); - Thread.sleep(1000); + // 3. Toast + driver.findElement(AppiumBy.id("toast")).click(); - // toast is visible - driver.findElement(MobileBy.id("toast")).click(); - Thread.sleep(1000); + // 4. Notification + driver.findElement(AppiumBy.id("notification")).click(); +// Thread.sleep(2000); - // notification is visible - driver.findElement(MobileBy.id("notification")).click(); - Thread.sleep(2000); - - // Open the geolocation page - driver.findElement(MobileBy.id("geoLocation")).click(); - Thread.sleep(4000); - driver.navigate().back(); - Thread.sleep(1000); - - // Takes to speed test page - driver.findElement(MobileBy.id("speedTest")).click(); + // 5. Geolocation + driver.findElement(AppiumBy.id("geoLocation")).click(); Thread.sleep(5000); driver.navigate().back(); - Thread.sleep(1000); - // Opens the browser - MobileElement browser = (MobileElement) driver.findElementByAccessibilityId("Browser"); - browser.click(); - Thread.sleep(3000); - WebDriverWait el7 = new WebDriverWait(driver, 30); - el7.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url"))); - driver.findElementById("url").sendKeys("https://www.lambdatest.com/"); - // Clicks on the text box - WebDriverWait el = new WebDriverWait(driver, 90); - MobileElement el4 = (MobileElement) driver.findElementByAccessibilityId("find"); - el.until(ExpectedConditions.elementToBeClickable(el4)); - el4.click(); - el4.sendKeys("Lambdatest"); - // ((JavascriptExecutor) driver).executeScript("lambda-status=passed"); - driver.quit(); } catch (Exception t) { - System.out.println(t); - driver.quit(); - + System.out.println("Test Failed: " + t.getMessage()); + t.printStackTrace(); + } finally { + if (driver != null) { + driver.quit(); + } } } -} +} \ No newline at end of file diff --git a/target/AppTesting-1.0-SNAPSHOT.jar b/target/AppTesting-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..6824ff7 Binary files /dev/null and b/target/AppTesting-1.0-SNAPSHOT.jar differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 0000000..e8780e7 --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=AppTesting +groupId=App +version=1.0-SNAPSHOT diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..9d6976f --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1,2 @@ +vanilla_ios.class +vanilla_android.class diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..0038495 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1,2 @@ +D:\LT-appium-java-ADO\src\test\java\vanilla_ios.java +D:\LT-appium-java-ADO\src\test\java\vanilla_android.java diff --git a/target/test-classes/vanilla_android.class b/target/test-classes/vanilla_android.class new file mode 100644 index 0000000..0f554d0 Binary files /dev/null and b/target/test-classes/vanilla_android.class differ diff --git a/target/test-classes/vanilla_ios.class b/target/test-classes/vanilla_ios.class new file mode 100644 index 0000000..ca665f2 Binary files /dev/null and b/target/test-classes/vanilla_ios.class differ