-
Notifications
You must be signed in to change notification settings - Fork 20
/
android.java
77 lines (66 loc) · 3.59 KB
/
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
package com.lambdatest;
import io.appium.java_client.MobileBy;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.net.URL;
public class android {
String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME"); //Enter the Username here
String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); //Enter the Access key here
public String app_id = System.getenv("LT_APP_ID") == null ? "lt://proverbial-android" : System.getenv("LT_APP_ID"); //Enter your LambdaTest App ID at the place of lt://proverbial-android
public String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL");
public String status = "passed";
public static RemoteWebDriver driver = null;
@Before
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("build", "JUNIT Native App automation");
capabilities.setCapability("name", "Java JUnit Android");
capabilities.setCapability("platformName", "android");
capabilities.setCapability("deviceName", "Pixel.*"); //Enter the name of the device here
capabilities.setCapability("isRealMobile", true);
capabilities.setCapability("platformVersion", "12");
capabilities.setCapability("app", app_id); //Enter the App ID here
capabilities.setCapability("deviceOrientation", "PORTRAIT");
capabilities.setCapability("network", false);
capabilities.setCapability("visual", true);
capabilities.setCapability("autoGrantPermissions", true);
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"),
capabilities);
}
@Test
public void testSimple() throws Exception {
try {
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("color"))).click();
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("geoLocation"))).click();
Thread.sleep(5000);
driver.navigate().back();
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("Text"))).click();
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("notification"))).click();
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("toast"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("webview"))).click();
Thread.sleep(10000);
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url"))).sendKeys("https://www.lambdatest.com/");
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("find"))).click();
Thread.sleep(5000);
driver.navigate().back();
status = "passed";
} catch (Exception e) {
System.out.println(e.getMessage());
status = "failed";
}
}
@After
public void tearDown() throws Exception {
if (driver != null) {
driver.executeScript("lambda-status=" + status);
driver.quit();
}
}
}