-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathvanilla_android.java
91 lines (74 loc) · 4.13 KB
/
vanilla_android.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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();
}
}