|
11 | 11 | import org.openqa.selenium.support.ui.ExpectedConditions; |
12 | 12 | import org.openqa.selenium.support.ui.WebDriverWait; |
13 | 13 |
|
14 | | -import java.net.MalformedURLException; |
15 | 14 | import java.net.URL; |
16 | 15 |
|
17 | 16 | public class android { |
18 | | - String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" //Enter the Username here |
19 | | - : System.getenv("LT_USERNAME"); |
20 | | - String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" //Enter the Access key here |
21 | | - : System.getenv("LT_ACCESS_KEY"); |
22 | | - public static RemoteWebDriver driver = null; |
23 | | - public String gridURL = "@mobile-hub.lambdatest.com/wd/hub"; |
| 17 | + String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME"); //Enter the Username here |
| 18 | + String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); //Enter the Access key here |
| 19 | + 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 |
| 20 | + public String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); |
24 | 21 | public String status = "passed"; |
| 22 | + |
| 23 | + public static RemoteWebDriver driver = null; |
| 24 | + |
25 | 25 | @Before |
26 | 26 | public void setUp() throws Exception { |
27 | 27 | DesiredCapabilities capabilities = new DesiredCapabilities(); |
28 | 28 |
|
29 | 29 | capabilities.setCapability("build", "JUNIT Native App automation"); |
30 | | - capabilities.setCapability("name", "Java JUnit Android Pixel 6"); |
| 30 | + capabilities.setCapability("name", "Java JUnit Android"); |
31 | 31 | capabilities.setCapability("platformName", "android"); |
32 | | - capabilities.setCapability("deviceName", "Pixel 6"); //Enter the name of the device here |
| 32 | + capabilities.setCapability("deviceName", "Pixel.*"); //Enter the name of the device here |
33 | 33 | capabilities.setCapability("isRealMobile", true); |
34 | | - capabilities.setCapability("platformVersion","12"); |
35 | | - capabilities.setCapability("app","lt://proverbial-android"); //Enter the App ID here |
| 34 | + capabilities.setCapability("platformVersion", "12"); |
| 35 | + capabilities.setCapability("app", app_id); //Enter the App ID here |
36 | 36 | capabilities.setCapability("deviceOrientation", "PORTRAIT"); |
37 | | - capabilities.setCapability("console",true); |
38 | | - capabilities.setCapability("network",false); |
39 | | - capabilities.setCapability("visual",true); |
40 | | - try |
41 | | - { |
42 | | - driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + gridURL), capabilities); |
43 | | - } |
44 | | - catch (MalformedURLException e) |
45 | | - { |
46 | | - System.out.println("Invalid grid URL"); |
47 | | - } catch (Exception e) |
48 | | - { |
49 | | - System.out.println(e.getMessage()); |
50 | | - } |
| 37 | + capabilities.setCapability("network", false); |
| 38 | + capabilities.setCapability("visual", true); |
| 39 | + capabilities.setCapability("autoGrantPermissions", true); |
| 40 | + |
| 41 | + driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), |
| 42 | + capabilities); |
51 | 43 | } |
52 | 44 |
|
53 | 45 | @Test |
54 | | - public void testSimple() throws Exception |
55 | | - { |
56 | | - try |
57 | | - { |
| 46 | + public void testSimple() throws Exception { |
| 47 | + try { |
58 | 48 | WebDriverWait wait = new WebDriverWait(driver, 30); |
59 | 49 | wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("color"))).click(); |
60 | | - |
61 | | - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("geoLocation"))).click();; |
| 50 | + wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("geoLocation"))).click(); |
62 | 51 | Thread.sleep(5000); |
63 | 52 | driver.navigate().back(); |
64 | | - |
65 | 53 | wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("Text"))).click(); |
66 | | - |
67 | | - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("notification"))).click();; |
68 | | - |
| 54 | + wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("notification"))).click(); |
69 | 55 | wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("toast"))).click(); |
70 | | - |
71 | | - wait.until(ExpectedConditions.elementToBeClickable(By.id("webview"))).click();; |
| 56 | + wait.until(ExpectedConditions.elementToBeClickable(By.id("webview"))).click(); |
72 | 57 | Thread.sleep(10000); |
73 | | - |
74 | 58 | wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url"))).sendKeys("https://www.lambdatest.com/"); |
75 | | - |
76 | 59 | wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("find"))).click(); |
77 | 60 | Thread.sleep(5000); |
78 | 61 | driver.navigate().back(); |
79 | | - |
80 | | - status="passed"; |
| 62 | + status = "passed"; |
| 63 | + } catch (Exception e) { |
| 64 | + System.out.println(e.getMessage()); |
| 65 | + status = "failed"; |
81 | 66 | } |
82 | | - catch (Exception e) |
83 | | - { |
84 | | - System.out.println(e.getMessage()); |
85 | | - status="failed"; |
86 | | - } |
87 | 67 | } |
| 68 | + |
88 | 69 | @After |
89 | | - public void tearDown() throws Exception |
90 | | - { |
91 | | - if (driver != null) |
92 | | - { |
| 70 | + public void tearDown() throws Exception { |
| 71 | + if (driver != null) { |
93 | 72 | driver.executeScript("lambda-status=" + status); |
94 | 73 | driver.quit(); |
95 | 74 | } |
|
0 commit comments