Skip to content

Commit c3fcd03

Browse files
committed
Fix issue with [issue/feature name]
1 parent 6346246 commit c3fcd03

15 files changed

Lines changed: 185 additions & 178 deletions

File tree

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 26 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -10,89 +10,46 @@
1010
<properties>
1111
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1212

13+
14+
<!-- Define Selenium version -->
15+
<selenium.version>4.11.0</selenium.version>
1316
</properties>
14-
<dependencies>
15-
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
16-
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
17-
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
18-
<dependency>
19-
<groupId>org.seleniumhq.selenium</groupId>
20-
<artifactId>selenium-java</artifactId>
21-
<version>3.141.59</version>
22-
</dependency>
17+
<dependencyManagement>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.seleniumhq.selenium</groupId>
21+
<artifactId>selenium-bom</artifactId>
22+
<version>${selenium.version}</version>
23+
<type>pom</type>
24+
<scope>import</scope>
25+
</dependency>
26+
</dependencies>
27+
</dependencyManagement>
2328

29+
<!-- Java version -->
2430

25-
<dependency>
26-
<groupId>com.github.lambdatest</groupId>
27-
<artifactId>lambdatest-tunnel-binary</artifactId>
28-
<version>1.0.10</version>
29-
</dependency>
3031

31-
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
32-
<dependency>
33-
<groupId>io.github.bonigarcia</groupId>
34-
<artifactId>webdrivermanager</artifactId>
35-
<version>4.3.1</version>
36-
</dependency>
32+
<dependencies>
33+
34+
<!-- Appium Java Client -->
3735
<dependency>
38-
<groupId>commons-io</groupId>
39-
<artifactId>commons-io</artifactId>
40-
<version>2.11.0</version>
36+
<groupId>io.appium</groupId>
37+
<artifactId>java-client</artifactId>
38+
<version>8.6.0</version>
4139
</dependency>
40+
4241
<dependency>
4342
<groupId>org.seleniumhq.selenium</groupId>
44-
<artifactId>selenium-support</artifactId>
45-
<version>2.52.0</version>
46-
</dependency>
47-
<dependency>
48-
<groupId>io.appium</groupId>
49-
<artifactId>java-client</artifactId>
50-
<version>7.6.0</version>
43+
<artifactId>selenium-java</artifactId>
5144
</dependency>
45+
46+
<!-- TestNG -->
5247
<dependency>
5348
<groupId>org.testng</groupId>
5449
<artifactId>testng</artifactId>
55-
<version>7.6.1</version>
56-
</dependency>
57-
<dependency>
58-
<groupId>commons-lang</groupId>
59-
<artifactId>commons-lang</artifactId>
60-
<version>2.6</version>
61-
</dependency>
62-
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
63-
<dependency>
64-
<groupId>org.apache.commons</groupId>
65-
<artifactId>commons-lang3</artifactId>
66-
<version>3.0</version>
67-
</dependency>
68-
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
69-
<dependency>
70-
<groupId>info.cukes</groupId>
71-
<artifactId>cucumber-java</artifactId>
72-
<version>1.2.5</version>
73-
</dependency>
74-
<!-- https://mvnrepository.com/artifact/junit/junit -->
75-
<dependency>
76-
<groupId>junit</groupId>
77-
<artifactId>junit</artifactId>
78-
<version>4.12</version>
50+
<version>7.9.0</version>
7951
<scope>test</scope>
8052
</dependency>
81-
<dependency>
82-
<groupId>org.json</groupId>
83-
<artifactId>json</artifactId>
84-
<version>20160810</version>
85-
</dependency>
86-
<dependency>
87-
<groupId>org.seleniumhq.selenium</groupId>
88-
<artifactId>selenium-remote-driver</artifactId>
89-
<version>3.141.59</version>
90-
</dependency>
91-
<dependency>
92-
<groupId>io.rest-assured</groupId>
93-
<artifactId>rest-assured</artifactId>
94-
<version>4.3.0</version>
95-
</dependency>
9653

9754
</dependencies>
9855

src/test/java/vanilla_android.java

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,96 @@
11
import io.appium.java_client.AppiumDriver;
22
import io.appium.java_client.MobileBy;
3-
import io.appium.java_client.MobileElement;
3+
//import io.appium.java_client.WebElement;
4+
import org.openqa.selenium.WebElement;
5+
import io.appium.java_client.AppiumBy;
6+
import io.appium.java_client.android.AndroidDriver;
47
import org.openqa.selenium.JavascriptExecutor;
58
import org.openqa.selenium.remote.DesiredCapabilities;
69
import java.net.MalformedURLException;
710
import java.net.URL;
11+
import java.util.HashMap;
812

913
public class vanilla_android {
10-
public static String userName = System.getenv("LT_USERNAME") == null ? "YOUR_USERNAME" // Add username here
11-
: System.getenv("LT_USERNAME");
12-
public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_ACCESS_KEY" // Add accessKey here
13-
: System.getenv("LT_ACCESS_KEY");
14+
public static String userName = System.getenv("LT_USERNAME") == null ? "YOUR_USERNAME" : System.getenv("LT_USERNAME");
15+
public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY");
1416

15-
private static AppiumDriver driver;
17+
static AppiumDriver driver;
1618

1719
public static void main(String args[]) throws MalformedURLException, InterruptedException {
1820

1921
try {
2022
DesiredCapabilities capabilities = new DesiredCapabilities();
21-
capabilities.setCapability("deviceName", "Galaxy S20");
22-
capabilities.setCapability("platformVersion", "11");
23-
capabilities.setCapability("platformName", "Android");
24-
capabilities.setCapability("isRealMobile", true);
25-
capabilities.setCapability("app", "APP_URL"); // Enter your app url
26-
capabilities.setCapability("deviceOrientation", "PORTRAIT");
27-
capabilities.setCapability("build", "Java Vanilla - Android");
28-
capabilities.setCapability("name", "Sample Test Java");
29-
capabilities.setCapability("console", true);
30-
capabilities.setCapability("network", false);
31-
capabilities.setCapability("visual", true);
32-
capabilities.setCapability("devicelog", true);
33-
34-
driver = new AppiumDriver(
23+
HashMap<String, Object> ltOptions = new HashMap<String, Object>();
24+
ltOptions.put("deviceName", "Galaxy.*"); // You can specify a particular model, or use a wildcard.
25+
ltOptions.put("platformVersion", "14"); // Make sure this matches the device's OS version.
26+
ltOptions.put("platformName", "Android");
27+
ltOptions.put("isRealMobile", true); // Ensures that the test runs on a real device.
28+
ltOptions.put("app", "lt://APP10160622431766424164986229"); // Your app URL from LambdaTest.
29+
ltOptions.put("deviceOrientation", "PORTRAIT");
30+
ltOptions.put("build", "Java Vanilla - Android");
31+
ltOptions.put("name", "Sample Test Java");
32+
ltOptions.put("console", true);
33+
ltOptions.put("autoGrantPermissions", true); // Auto grants permissions on the app.
34+
ltOptions.put("network", false);
35+
ltOptions.put("visual", true);
36+
ltOptions.put("devicelog", true);
37+
capabilities.setCapability("lt:options", ltOptions);
38+
39+
// Initialize Appium driver with the LambdaTest server URL and capabilities
40+
driver = new AndroidDriver(
3541
new URL("https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"),
3642
capabilities);
3743

38-
MobileElement color = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/color"));
44+
// Interact with elements using their IDs
45+
WebElement color = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/color"));
3946
color.click();
4047

41-
MobileElement text = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/Text"));
42-
// Changes the text to proverbial
48+
WebElement text = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/Text"));
4349
text.click();
4450

45-
// toast is visible
46-
MobileElement toast = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/toast"));
51+
// Interact with Toast message element
52+
WebElement toast = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/toast"));
4753
toast.click();
4854

49-
// notification is visible
50-
MobileElement notification = (MobileElement) driver
51-
.findElement(MobileBy.id("com.lambdatest.proverbial:id/notification"));
55+
// Interact with Notification element
56+
WebElement notification = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/notification"));
5257
notification.click();
5358

54-
// Open the geolocation page
55-
MobileElement geo = (MobileElement) driver
56-
.findElement(MobileBy.id("com.lambdatest.proverbial:id/geoLocation"));
59+
// Open the Geolocation page
60+
WebElement geo = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/geoLocation"));
5761
geo.click();
5862
Thread.sleep(5000);
5963

60-
// takes back to home page
61-
MobileElement el3 = (MobileElement) driver.findElementByAccessibilityId("Home");
62-
64+
// Go back to the home page
6365
driver.navigate().back();
6466
Thread.sleep(2000);
6567

66-
// Takes to speed test page
67-
MobileElement speedtest = (MobileElement) driver
68-
.findElement(MobileBy.id("com.lambdatest.proverbial:id/speedTest"));
68+
// Navigate to the Speed Test page
69+
WebElement speedtest = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/speedTest"));
6970
speedtest.click();
7071
Thread.sleep(5000);
7172

7273
driver.navigate().back();
7374

74-
// Opens the browser
75-
MobileElement browser = (MobileElement) driver.findElement(MobileBy.AccessibilityId("Browser"));
75+
// Open the Browser and perform actions
76+
WebElement browser = driver.findElement(MobileBy.AccessibilityId("Browser"));
7677
browser.click();
7778

78-
MobileElement url = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/url"));
79+
WebElement url = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/url"));
7980
url.sendKeys("https://www.lambdatest.com");
80-
MobileElement find = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/find"));
81+
82+
WebElement find = driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/find"));
8183
find.click();
8284

8385
} catch (AssertionError a) {
86+
// Mark the status as failed if there's an error
8487
((JavascriptExecutor) driver).executeScript("lambda-status=failed");
8588
a.printStackTrace();
89+
} finally {
90+
// Ensure the driver quits to avoid the session hanging
91+
if (driver != null) {
92+
driver.quit();
93+
}
8694
}
87-
// The driver.quit statement is required, otherwise the test continues to
88-
// execute, leading to a timeout.
89-
driver.quit();
9095
}
9196
}

0 commit comments

Comments
 (0)