Skip to content

Commit 3c3ba6c

Browse files
authored
Merge pull request #15 from paragjain15/master
Added support for calling Dynamic App_ID
2 parents b74229f + 1b21b8d commit 3c3ba6c

21 files changed

Lines changed: 180 additions & 1457 deletions

.idea/runConfigurations.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/test/java/com/lambdatest/android.java

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,85 +11,64 @@
1111
import org.openqa.selenium.support.ui.ExpectedConditions;
1212
import org.openqa.selenium.support.ui.WebDriverWait;
1313

14-
import java.net.MalformedURLException;
1514
import java.net.URL;
1615

1716
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");
2421
public String status = "passed";
22+
23+
public static RemoteWebDriver driver = null;
24+
2525
@Before
2626
public void setUp() throws Exception {
2727
DesiredCapabilities capabilities = new DesiredCapabilities();
2828

2929
capabilities.setCapability("build", "JUNIT Native App automation");
30-
capabilities.setCapability("name", "Java JUnit Android Pixel 6");
30+
capabilities.setCapability("name", "Java JUnit Android");
3131
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
3333
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
3636
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);
5143
}
5244

5345
@Test
54-
public void testSimple() throws Exception
55-
{
56-
try
57-
{
46+
public void testSimple() throws Exception {
47+
try {
5848
WebDriverWait wait = new WebDriverWait(driver, 30);
5949
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();
6251
Thread.sleep(5000);
6352
driver.navigate().back();
64-
6553
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();
6955
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();
7257
Thread.sleep(10000);
73-
7458
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url"))).sendKeys("https://www.lambdatest.com/");
75-
7659
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("find"))).click();
7760
Thread.sleep(5000);
7861
driver.navigate().back();
79-
80-
status="passed";
62+
status = "passed";
63+
} catch (Exception e) {
64+
System.out.println(e.getMessage());
65+
status = "failed";
8166
}
82-
catch (Exception e)
83-
{
84-
System.out.println(e.getMessage());
85-
status="failed";
86-
}
8767
}
68+
8869
@After
89-
public void tearDown() throws Exception
90-
{
91-
if (driver != null)
92-
{
70+
public void tearDown() throws Exception {
71+
if (driver != null) {
9372
driver.executeScript("lambda-status=" + status);
9473
driver.quit();
9574
}

src/test/java/com/lambdatest/androidWeb.java

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.lambdatest;
22

3-
import io.appium.java_client.MobileBy;
43
import org.junit.After;
54
import org.junit.Before;
65
import org.junit.Test;
@@ -10,74 +9,59 @@
109
import org.openqa.selenium.support.ui.ExpectedConditions;
1110
import org.openqa.selenium.support.ui.WebDriverWait;
1211

13-
import java.net.MalformedURLException;
1412
import java.net.URL;
1513
import java.util.concurrent.TimeUnit;
1614

1715
public class androidWeb {
1816

19-
String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" //Enter the Username here
20-
: System.getenv("LT_USERNAME");
21-
String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" //Enter the Access key here
22-
: System.getenv("LT_ACCESS_KEY");
23-
public static RemoteWebDriver driver = null;
24-
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 grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL");
2520
public String status = "passed";
21+
22+
public static RemoteWebDriver driver = null;
23+
2624
@Before
2725
public void setUp() throws Exception {
2826
DesiredCapabilities capabilities = new DesiredCapabilities();
2927

3028
capabilities.setCapability("build", "JUNIT Native Web automation");
31-
capabilities.setCapability("name", "Java JUnit Android Pixel 6");
29+
capabilities.setCapability("name", "Java JUnit Android");
3230
capabilities.setCapability("platformName", "android");
3331
capabilities.setCapability("deviceName", "Pixel .*"); //Enter the name of the device here
3432
capabilities.setCapability("isRealMobile", true);
35-
capabilities.setCapability("platformVersion","12");
33+
capabilities.setCapability("platformVersion", "12");
3634
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-
}
35+
capabilities.setCapability("console", true);
36+
capabilities.setCapability("network", false);
37+
capabilities.setCapability("visual", true);
38+
39+
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"),
40+
capabilities);
5141
}
5242

5343
@Test
54-
public void testSimple() throws Exception
55-
{
56-
try
57-
{
44+
public void testSimple() throws Exception {
45+
try {
5846
driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);
5947
driver.get("https://mfml.in/api/getInfo");
6048
driver.getWindowHandles().forEach(handle -> System.out.println(handle));
6149
WebDriverWait wait = new WebDriverWait(driver, 30);
6250
wait.until(ExpectedConditions.elementToBeClickable(By.id("resolution"))).click();
63-
6451
wait.until(ExpectedConditions.elementToBeClickable(By.id("location"))).click();
6552
wait.until(ExpectedConditions.elementToBeClickable(By.id("details"))).click();
6653
wait.until(ExpectedConditions.elementToBeClickable(By.id("timezone"))).click();
6754

68-
status="passed";
69-
}
70-
catch (Exception e)
71-
{
55+
status = "passed";
56+
} catch (Exception e) {
7257
System.out.println(e.getMessage());
73-
status="failed";
58+
status = "failed";
7459
}
7560
}
61+
7662
@After
77-
public void tearDown() throws Exception
78-
{
79-
if (driver != null)
80-
{
63+
public void tearDown() throws Exception {
64+
if (driver != null) {
8165
driver.executeScript("lambda-status=" + status);
8266
driver.quit();
8367
}

src/test/java/com/lambdatest/ios.java

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,85 +11,64 @@
1111
import org.openqa.selenium.support.ui.ExpectedConditions;
1212
import org.openqa.selenium.support.ui.WebDriverWait;
1313

14-
import java.net.MalformedURLException;
1514
import java.net.URL;
1615

1716
public class ios {
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-ios" : 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");
2421
public String status = "passed";
22+
23+
public static RemoteWebDriver driver = null;
24+
25+
2526
@Before
2627
public void setUp() throws Exception {
2728
DesiredCapabilities capabilities = new DesiredCapabilities();
2829

2930
capabilities.setCapability("build", "JUNIT Native App automation");
30-
capabilities.setCapability("name", "Java JUnit iOS iPhone 12");
31+
capabilities.setCapability("name", "Java JUnit iOS");
3132
capabilities.setCapability("platformName", "ios");
32-
capabilities.setCapability("deviceName", "iPhone 12");
33+
capabilities.setCapability("deviceName", "iPhone.*");
3334
capabilities.setCapability("isRealMobile", true);
34-
capabilities.setCapability("platformVersion","15");
35-
capabilities.setCapability("app","lt://proverbial-ios"); //Enter the APP_ID here
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-
}
35+
capabilities.setCapability("platformVersion", "15");
36+
capabilities.setCapability("app", app_id); //Enter the APP_ID here
37+
capabilities.setCapability("network", false);
38+
capabilities.setCapability("visual", true);
39+
40+
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"),
41+
capabilities);
5142
}
5243

5344
@Test
54-
public void testSimple() throws Exception
55-
{
56-
try
57-
{
45+
public void testSimple() throws Exception {
46+
try {
5847
WebDriverWait wait = new WebDriverWait(driver, 30);
5948
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("color"))).click();
60-
6149
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("geoLocation"))).click();
6250
Thread.sleep(5000);
6351
driver.navigate().back();
64-
6552
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("Text"))).click();
66-
6753
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("notification"))).click();
68-
6954
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("toast"))).click();
70-
7155
wait.until(ExpectedConditions.elementToBeClickable(By.id("Browser"))).click();
7256
Thread.sleep(10000);
73-
74-
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url"))).sendKeys("https://www.lambdatest.com/");;
75-
57+
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url"))).sendKeys("https://www.lambdatest.com/");
7658
wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("find"))).click();
7759
Thread.sleep(5000);
7860
driver.navigate().back();
7961

80-
status="passed";
62+
status = "passed";
63+
} catch (Exception e) {
64+
System.out.println(e.getMessage());
65+
status = "failed";
8166
}
82-
catch (Exception e)
83-
{
84-
System.out.println(e.getMessage());
85-
status="failed";
86-
}
8767
}
68+
8869
@After
89-
public void tearDown() throws Exception
90-
{
91-
if (driver != null)
92-
{
70+
public void tearDown() throws Exception {
71+
if (driver != null) {
9372
driver.executeScript("lambda-status=" + status);
9473
driver.quit();
9574
}

0 commit comments

Comments
 (0)