diff --git a/README.md b/README.md index 747aeeb..e565a57 100644 --- a/README.md +++ b/README.md @@ -124,19 +124,10 @@ You can update your custom capabilities in test scripts. In this sample project, ```java -DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("deviceName", "Galaxy S20"); - capabilities.setCapability("platformVersion", "11"); - capabilities.setCapability("platformName", "Android"); - capabilities.setCapability("isRealMobile", true); - capabilities.setCapability("app", "YOUR_APP_URL"); //Enter your app url - capabilities.setCapability("deviceOrientation", "PORTRAIT"); - capabilities.setCapability("build", "Java Vanilla - iOS"); - capabilities.setCapability("name", "Sample Test Java"); - capabilities.setCapability("console", true); - capabilities.setCapability("network", false); - capabilities.setCapability("visual", true); - capabilities.setCapability("devicelog", true); + ... + ltOptions.put("smartUI.project", "Real_Device_Project"); // Enter your smartUI Project name + ltOptions.put("smartUI.build": ""); // Enter your smartUI build name + ... ``` @@ -144,16 +135,10 @@ DesiredCapabilities capabilities = new DesiredCapabilities(); ```java -DesiredCapabilities caps = new DesiredCapabilities(); - caps.setCapability("platformVersion", "15"); - caps.setCapability("deviceName", "iPhone 12"); - caps.setCapability("isRealMobile", true); - caps.setCapability("app", "YOUR_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", true); + ... + ltOptions.put("smartUI.project", "Real_Device_Project"); // Enter your smartUI Project name + ltOptions.put("smartUI.build": ""); // Enter your smartUI build name + ... ``` @@ -180,12 +165,22 @@ The tests can be executed in the terminal using the following command: ```bash mvn test -P android ``` +**AndroidWeb:** + +```bash +mvn test -P androidweb +``` **iOS:** ```bash mvn test -P ios ``` +**iOSWeb:** + +```bash +mvn test -P iosweb +``` **Info:** Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on the :link: [LambdaTest App Automation Dashboard](https://appautomation.lambdatest.com/build?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java). @@ -207,7 +202,7 @@ Visit the following links to learn more about LambdaTest's features, setup and t The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎 -## What's New At LambdaTest ❓ +## What's New At LambdaTest To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) diff --git a/pom.xml b/pom.xml index 8e2731f..8503a75 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ org.seleniumhq.selenium selenium-java - 3.141.59 + 4.5.0 @@ -42,12 +42,12 @@ org.seleniumhq.selenium selenium-support - 2.52.0 + 4.16.1 io.appium java-client - 7.6.0 + 8.3.0 org.testng @@ -86,7 +86,7 @@ org.seleniumhq.selenium selenium-remote-driver - 3.141.59 + 4.13.0 io.rest-assured @@ -123,7 +123,7 @@ org.codehaus.mojo exec-maven-plugin - 1.1.1 + 3.0.0 test @@ -131,7 +131,31 @@ java - vanilla_android + SmartuiAndroid + test + + + + + + + + + androidweb + + + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 + + + test + + java + + + SmartuiAndroidWeb test @@ -140,7 +164,6 @@ - ios @@ -148,7 +171,32 @@ org.codehaus.mojo exec-maven-plugin - 1.1.1 + 3.0.0 + + + test + + java + + + SmartuiIOS + test + + + + + + + + + + iosweb + + + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 test @@ -156,7 +204,7 @@ java - vanilla_ios + SmartuiIOSWeb test @@ -167,4 +215,4 @@ - + \ No newline at end of file diff --git a/src/test/java/SmartuiAndroid.java b/src/test/java/SmartuiAndroid.java new file mode 100644 index 0000000..250f1f5 --- /dev/null +++ b/src/test/java/SmartuiAndroid.java @@ -0,0 +1,66 @@ +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.remote.DesiredCapabilities; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +public class SmartuiAndroid { + public static String userName = System.getenv("LT_USERNAME") == null ? "YOUR_LT_USERNAME" // Add username here + : System.getenv("LT_USERNAME"); + public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_LT_ACCESS_KEY" // Add accessKey here + : System.getenv("LT_ACCESS_KEY"); + public static void main(String[] args) throws MalformedURLException, InterruptedException { + + DesiredCapabilities capabilities = new DesiredCapabilities(); + Map ltOptions = new HashMap<>(); + ltOptions.put("deviceName", "Galaxy S21+ 5G"); + ltOptions.put("app", "lt://proverbial-android"); // Enter your app url + ltOptions.put("isRealMobile", true); + ltOptions.put("platformName", "Android"); + ltOptions.put("build", "Java - Android"); + ltOptions.put("name", "Sample Test Java-Android"); + ltOptions.put("w3c", true); + ltOptions.put("video", true); + ltOptions.put("visual", true); + ltOptions.put("smartUI.project", "Real-Device-Project-Android"); // Enter your smartUI Project name + capabilities.setCapability("lt:options", ltOptions); + + AppiumDriver driver = new AppiumDriver( + new URL("https://"+userName+":"+accessKey+"@mobile-hub.lambdatest.com/wd/hub"), capabilities); + try { + driver.findElement(AppiumBy.id("com.lambdatest.proverbial:id/color")).click(); + + //Changes the text to proverbial + driver.findElement(AppiumBy.id("com.lambdatest.proverbial:id/Text")).click(); + + //toast is visible + driver.findElement(AppiumBy.id("com.lambdatest.proverbial:id/toast")).click(); + + //notification is visible + driver.findElement(AppiumBy.id("com.lambdatest.proverbial:id/notification")).click(); + + //takes back to home page + driver.findElement(AppiumBy.accessibilityId("Home")).click(); + driver.navigate().back(); + Thread.sleep(2000); + + //Takes to speed test page + driver.findElement(AppiumBy.id("com.lambdatest.proverbial:id/speedTest")).click(); + Thread.sleep(5000); + driver.navigate().back(); + + driver.executeScript("smartui.takeScreenshot="); + System.out.println("Screenshot Captured"); + driver.quit(); + + } catch (AssertionError a) { + // ((JavascriptExecutor) driver).executeScript("lambda-status=failed"); + a.printStackTrace(); + } + } +} + + diff --git a/src/test/java/SmartuiAndroidWeb.java b/src/test/java/SmartuiAndroidWeb.java new file mode 100644 index 0000000..0ef9067 --- /dev/null +++ b/src/test/java/SmartuiAndroidWeb.java @@ -0,0 +1,45 @@ +import io.appium.java_client.AppiumDriver; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.remote.DesiredCapabilities; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +public class SmartuiAndroidWeb { + public static String userName = System.getenv("LT_USERNAME") == null ? "YOUR_LT_USERNAME" // Add username here + : System.getenv("LT_USERNAME"); + public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_LT_ACCESS_KEY" // Add accessKey here + : System.getenv("LT_ACCESS_KEY"); + + public static void main(String[] args) throws MalformedURLException, InterruptedException { + + DesiredCapabilities capabilities = new DesiredCapabilities(); + Map < String, Object > ltOptions = new HashMap < > (); + ltOptions.put("deviceName", "Galaxy S21+ 5G"); + ltOptions.put("isRealMobile", true); + ltOptions.put("platformName", "Android"); + ltOptions.put("build", "Java - Android-Web"); + ltOptions.put("name", "Sample Test Java-Android"); + ltOptions.put("w3c", true); + ltOptions.put("video", true); + ltOptions.put("visual", true); + ltOptions.put("smartUI.project", "Real-Device-Project-Android-Web"); // Enter your smartUI Project name + capabilities.setCapability("lt:options", ltOptions); + + AppiumDriver driver = new AppiumDriver( + new URL("https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), + capabilities); + + try { + driver.get("https://www.lambdatest.com/"); + Thread.sleep(10000); + driver.executeScript("smartui.takeScreenshot="); + System.out.println("Screenshot Captured"); + driver.quit(); + } catch (AssertionError a) { + // ((JavascriptExecutor) driver).executeScript("lambda-status=failed"); + a.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/test/java/SmartuiIOS.java b/src/test/java/SmartuiIOS.java new file mode 100644 index 0000000..f30f3c3 --- /dev/null +++ b/src/test/java/SmartuiIOS.java @@ -0,0 +1,70 @@ + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +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.time.Duration; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +public class SmartuiIOS { + + public static String userName = System.getenv("LT_USERNAME") == null ? "YOUR_LT_USERNAME" // Add username here + : System.getenv("LT_USERNAME"); + public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_LT_ACCESS_KEY" // Add accessKey here + : System.getenv("LT_ACCESS_KEY"); + + public static void main(String[] args) throws Exception { + + DesiredCapabilities capabilities = new DesiredCapabilities(); + Map ltOptions = new HashMap<>(); + ltOptions.put("app", "lt://proverbial-ios"); // Enter your app url + ltOptions.put("deviceName", "iPhone 14"); + ltOptions.put("platformName", "iOS"); + ltOptions.put("isRealMobile", true); + ltOptions.put("build", "Java Test - iOS"); + ltOptions.put("name", "Sample Test Java-iOS"); + ltOptions.put("w3c", true); + ltOptions.put("video", true); + ltOptions.put("visual", true); + ltOptions.put("smartUI.project", "Real-Device-Project-IOS"); //Enter your smartUI Project name + capabilities.setCapability("lt:options", ltOptions); + + AppiumDriver driver = new AppiumDriver( + new URL("https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"),capabilities); + + try { + Thread.sleep(2000); + // Changes color + driver.findElement(AppiumBy.id("color")).click(); + Thread.sleep(1000); + + //Back to black color + driver.navigate().back(); + Thread.sleep(1000); + + //Changes the text to proverbial + driver.findElement(AppiumBy.id("Text")).click(); + Thread.sleep(1000); + + //toast is visible + driver.findElement(AppiumBy.id("toast")).click(); + Thread.sleep(1000); + + //notification is visible + driver.findElement(AppiumBy.id("notification")).click(); + Thread.sleep(2000); + + driver.executeScript("smartui.takeScreenshot="); + System.out.println("Screenshot Captured"); + // ((JavascriptExecutor) driver).executeScript("lambda-status=passed"); + driver.quit(); + } catch (Exception t) { + System.out.println(t); + driver.quit(); + } + } +} \ No newline at end of file diff --git a/src/test/java/SmartuiIOSWeb.java b/src/test/java/SmartuiIOSWeb.java new file mode 100644 index 0000000..392b901 --- /dev/null +++ b/src/test/java/SmartuiIOSWeb.java @@ -0,0 +1,44 @@ +import io.appium.java_client.AppiumDriver; +import org.openqa.selenium.remote.DesiredCapabilities; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +public class SmartuiIOSWeb { + + public static String userName = System.getenv("LT_USERNAME") == null ? "YOUR_LT_USERNAME" // Add username here + : System.getenv("LT_USERNAME"); + public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_LT_ACCESS_KEY" // Add accessKey here + : System.getenv("LT_ACCESS_KEY"); + + public static void main(String[] args) throws Exception { + + DesiredCapabilities capabilities = new DesiredCapabilities(); + Map ltOptions = new HashMap<>(); + ltOptions.put("deviceName", "iPhone 12"); + ltOptions.put("platformName", "iOS"); + ltOptions.put("isRealMobile", true); + ltOptions.put("build", "Java - iOS-Web"); + ltOptions.put("name", "Sample Test Java-iOS"); + ltOptions.put("w3c", true); + ltOptions.put("video", true); + ltOptions.put("visual", true); + ltOptions.put("smartUI.project", "Real-Device-Project-IOS-Web"); //Enter your smartUI Project name + capabilities.setCapability("lt:options", ltOptions); + + AppiumDriver driver = new AppiumDriver( + new URL("https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"),capabilities); + + try { + driver.get("https://www.lambdatest.com/"); + Thread.sleep(10000); + driver.executeScript("smartui.takeScreenshot="); + System.out.println("Screenshot Captured"); +// ((JavascriptExecutor) driver).executeScript("lambda-status=passed"); + driver.quit(); + } catch (Exception t) { + System.out.println(t); + driver.quit(); + } + } +} \ No newline at end of file diff --git a/src/test/java/vanilla_android.java b/src/test/java/vanilla_android.java deleted file mode 100644 index 6009380..0000000 --- a/src/test/java/vanilla_android.java +++ /dev/null @@ -1,91 +0,0 @@ -import io.appium.java_client.AppiumDriver; -import io.appium.java_client.MobileBy; -import io.appium.java_client.MobileElement; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.remote.DesiredCapabilities; -import java.net.MalformedURLException; -import java.net.URL; - -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"); - - private 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( - new URL("https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), - capabilities); - - MobileElement color = (MobileElement) 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 - text.click(); - - // toast is visible - MobileElement toast = (MobileElement) 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")); - notification.click(); - - // Open the geolocation page - MobileElement geo = (MobileElement) 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"); - - driver.navigate().back(); - Thread.sleep(2000); - - // Takes to speed test page - MobileElement speedtest = (MobileElement) 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")); - browser.click(); - - MobileElement url = (MobileElement) 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")); - find.click(); - - } catch (AssertionError a) { - ((JavascriptExecutor) driver).executeScript("lambda-status=failed"); - a.printStackTrace(); - } - // 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 deleted file mode 100644 index cb51dd4..0000000 --- a/src/test/java/vanilla_ios.java +++ /dev/null @@ -1,100 +0,0 @@ -import io.appium.java_client.MobileBy; -import io.appium.java_client.MobileElement; -import io.appium.java_client.ios.IOSDriver; - -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.net.URL; - -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 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); - - driver = new IOSDriver( - new URL("https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), - caps); - - Thread.sleep(2000); - - // Changes color - - driver.findElement(MobileBy.id("color")).click(); - Thread.sleep(1000); - - // Back to black color - driver.navigate().back(); - - Thread.sleep(1000); - - // Changes the text to proverbial - driver.findElement(MobileBy.id("Text")).click(); - Thread.sleep(1000); - - // toast is visible - driver.findElement(MobileBy.id("toast")).click(); - Thread.sleep(1000); - - // 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(); - 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(); - - } - } -} diff --git a/target/AppTesting-1.0-SNAPSHOT.jar b/target/AppTesting-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..a9b834d 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..e062a71 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1,4 @@ +SmartuiIOSWeb.class +SmartuiAndroid.class +SmartuiAndroidWeb.class +SmartuiIOS.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..e5694f1 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1,4 @@ +/Users/haiderk/AppiumRepos/LT-appium-java/src/test/java/SmartuiAndroidWeb.java +/Users/haiderk/AppiumRepos/LT-appium-java/src/test/java/SmartuiIOS.java +/Users/haiderk/AppiumRepos/LT-appium-java/src/test/java/SmartuiAndroid.java +/Users/haiderk/AppiumRepos/LT-appium-java/src/test/java/SmartuiIOSWeb.java diff --git a/target/test-classes/SmartuiAndroid.class b/target/test-classes/SmartuiAndroid.class new file mode 100644 index 0000000..7cbac00 Binary files /dev/null and b/target/test-classes/SmartuiAndroid.class differ diff --git a/target/test-classes/SmartuiAndroidWeb.class b/target/test-classes/SmartuiAndroidWeb.class new file mode 100644 index 0000000..9b11e56 Binary files /dev/null and b/target/test-classes/SmartuiAndroidWeb.class differ diff --git a/target/test-classes/SmartuiIOS.class b/target/test-classes/SmartuiIOS.class new file mode 100644 index 0000000..fe779f8 Binary files /dev/null and b/target/test-classes/SmartuiIOS.class differ diff --git a/target/test-classes/SmartuiIOSWeb.class b/target/test-classes/SmartuiIOSWeb.class new file mode 100644 index 0000000..dfb52ba Binary files /dev/null and b/target/test-classes/SmartuiIOSWeb.class differ