Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,36 +124,21 @@ You can update your custom capabilities in test scripts. In this sample project,
<TabItem value="android-config" label="Android" default>

```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
...
```

</TabItem>

<TabItem value="ios-config" label="iOS" default>

```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
...
```

</TabItem>
Expand All @@ -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).

Expand All @@ -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/)

Expand Down
68 changes: 58 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
<version>4.5.0</version>
</dependency>


Expand All @@ -42,12 +42,12 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.52.0</version>
<version>4.16.1</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.6.0</version>
<version>8.3.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
Expand Down Expand Up @@ -86,7 +86,7 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.141.59</version>
<version>4.13.0</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
Expand Down Expand Up @@ -123,15 +123,39 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<version>3.0.0</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>vanilla_android</mainClass>
<mainClass>SmartuiAndroid</mainClass>
<classpathScope>test</classpathScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>androidweb</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>SmartuiAndroidWeb</mainClass>
<classpathScope>test</classpathScope>
</configuration>
</execution>
Expand All @@ -140,23 +164,47 @@
</plugins>
</build>
</profile>

<profile>
<id>ios</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<version>3.0.0</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>SmartuiIOS</mainClass>
<classpathScope>test</classpathScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>iosweb</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>vanilla_ios</mainClass>
<mainClass>SmartuiIOSWeb</mainClass>
<classpathScope>test</classpathScope>
</configuration>
</execution>
Expand All @@ -167,4 +215,4 @@
</profile>
</profiles>

</project>
</project>
66 changes: 66 additions & 0 deletions src/test/java/SmartuiAndroid.java
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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=<Name of your Screenshot>");
System.out.println("Screenshot Captured");
driver.quit();

} catch (AssertionError a) {
// ((JavascriptExecutor) driver).executeScript("lambda-status=failed");
a.printStackTrace();
}
}
}


45 changes: 45 additions & 0 deletions src/test/java/SmartuiAndroidWeb.java
Original file line number Diff line number Diff line change
@@ -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=<Name of your Screenshot>");
System.out.println("Screenshot Captured");
driver.quit();
} catch (AssertionError a) {
// ((JavascriptExecutor) driver).executeScript("lambda-status=failed");
a.printStackTrace();
}
}
}
70 changes: 70 additions & 0 deletions src/test/java/SmartuiIOS.java
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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=<Name of your Screenshot>");
System.out.println("Screenshot Captured");
// ((JavascriptExecutor) driver).executeScript("lambda-status=passed");
driver.quit();
} catch (Exception t) {
System.out.println(t);
driver.quit();
}
}
}
Loading