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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -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)
95 changes: 26 additions & 69 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,89 +10,46 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>


<!-- Define Selenium version -->
<selenium.version>4.11.0</selenium.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-bom</artifactId>
<version>${selenium.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<!-- Java version -->

<dependency>
<groupId>com.github.lambdatest</groupId>
<artifactId>lambdatest-tunnel-binary</artifactId>
<version>1.0.10</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.3.1</version>
</dependency>
<dependencies>

<!-- Appium Java Client -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.6.0</version>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.52.0</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.6.0</version>
<artifactId>selenium-java</artifactId>
</dependency>

<!-- TestNG -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.6.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>7.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.3.0</version>
</dependency>

</dependencies>

Expand Down
93 changes: 49 additions & 44 deletions src/test/java/vanilla_android.java
Original file line number Diff line number Diff line change
@@ -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<String, Object> ltOptions = new HashMap<String, Object>();
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();
}
}
Loading