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 @@ - +