Skip to content

Commit 162ac9d

Browse files
authored
Add files via upload
1 parent 2b75877 commit 162ac9d

File tree

7 files changed

+61
-63
lines changed

7 files changed

+61
-63
lines changed

Config.properties

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ version=11.0
55
os=Windows 8.1
66
resolution=1024x768
77

8-
98
#Lambdatest Credentails
10-
LambdaTest_UserName=<YOUR LT USERNAME>
11-
LambdaTest_AppKey=<YOUR LT ACCESS KEY>
9+
LambdaTest_UserName=<YOUR LT_USERNAME>
10+
LambdaTest_AppKey=<YOUR LT_ACCESS_KEY>

src/test/java/com/lambdatest/Tests/Configuration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static String readConfig(String key) throws Exception {
1414
try {
1515
Properties prop = new Properties();
1616
File f = new File(path + "/Config.properties");
17+
System.out.println(path);
1718
if (f.exists()) {
1819
prop.load(new FileInputStream(f));
1920
value = prop.getProperty(key);

src/test/java/com/lambdatest/Tests/LocalTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.testng.annotations.Test;
44
import org.testng.annotations.BeforeMethod;
5+
import org.testng.annotations.BeforeTest;
56
import org.testng.AssertJUnit;
67
import java.net.URL;
78

@@ -22,7 +23,7 @@ public class LocalTest {
2223
public WebDriver driver;
2324
public static String status = "failed";
2425

25-
@BeforeMethod
26+
@BeforeTest
2627
@BeforeClass
2728
public void setUp() throws Exception {
2829

@@ -31,8 +32,8 @@ public void setUp() throws Exception {
3132
String os = Configuration.readConfig("os");
3233
String res = Configuration.readConfig("resolution");
3334

34-
String username = Configuration.readConfig("LambdaTest_UserName");
35-
String accesskey = Configuration.readConfig("LambdaTest_AppKey");
35+
String username = System.getenv("LT_USERNAME") != null ?System.getenv("LT_USERNAME"): Configuration.readConfig("LambdaTest_UserName");
36+
String accesskey = System.getenv("LT_ACCESS_KEY") != null ?System.getenv("LT_ACCESS_KEY"):Configuration.readConfig("LambdaTest_AppKey");
3637

3738
DesiredCapabilities capability = new DesiredCapabilities();
3839
capability.setCapability(CapabilityType.BROWSER_NAME, browser);
@@ -56,7 +57,7 @@ public void setUp() throws Exception {
5657
public void test() {
5758

5859
// Launch the app
59-
driver.get("https://lambdatest.github.io/sample-todo-app/");
60+
driver.get("https//localhost.lambdatest.com/todo.html");
6061

6162
// Click on First Item
6263
driver.findElement(By.name("li1")).click();

src/test/java/com/lambdatest/Tests/ParallelJenkinsTest.java

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.testng.annotations.Test;
44
import org.testng.annotations.BeforeMethod;
5+
import org.testng.annotations.BeforeTest;
56
import org.testng.AssertJUnit;
67
import org.testng.ITestContext;
78

@@ -33,53 +34,52 @@ public class ParallelJenkinsTest {
3334
public static String status = "failed";
3435
public String buildTag = System.getenv("LT_BUILD_NAME");
3536
public String gridURL = System.getenv("LT_GRID_URL");
36-
37+
3738
@Test(dataProvider = "browsersDetails")
3839
public void test(String param, Method method) throws Exception {
3940

4041
try {
41-
42-
String[] envDeatails = param.split(",");
43-
String os = envDeatails[1];
44-
String version = envDeatails[2];
45-
String browser = envDeatails[0];
46-
String resValue = envDeatails[3];
4742

48-
this.setUp(browser, version, os, resValue, method.getName());
43+
String[] envDeatails = param.split(",");
44+
String os = envDeatails[1];
45+
String version = envDeatails[2];
46+
String browser = envDeatails[0];
47+
String resValue = envDeatails[3];
48+
49+
this.setUp(browser, version, os, resValue, method.getName());
4950

50-
// Launch the app
51-
getWebDriver().get("https://lambdatest.github.io/sample-todo-app/");
51+
// Launch the app
52+
getWebDriver().get("https://lambdatest.github.io/sample-todo-app/");
5253

53-
// Click on First Item
54-
getWebDriver().findElement(By.name("li1")).click();
54+
// Click on First Item
55+
getWebDriver().findElement(By.name("li1")).click();
5556

56-
// Click on Second Item
57-
getWebDriver().findElement(By.name("li2")).click();
57+
// Click on Second Item
58+
getWebDriver().findElement(By.name("li2")).click();
5859

59-
// Add new item is list
60-
getWebDriver().findElement(By.id("sampletodotext")).clear();
61-
getWebDriver().findElement(By.id("sampletodotext")).sendKeys("Yey, Let's add it to list");
62-
getWebDriver().findElement(By.id("addbutton")).click();
60+
// Add new item is list
61+
getWebDriver().findElement(By.id("sampletodotext")).clear();
62+
getWebDriver().findElement(By.id("sampletodotext")).sendKeys("Yey, Let's add it to list");
63+
getWebDriver().findElement(By.id("addbutton")).click();
6364

64-
// Verify Added item
65-
String item = getWebDriver().findElement(By.xpath("/html/body/div/div/div/ul/li[6]/span")).getText();
66-
AssertJUnit.assertTrue(item.contains("Yey, Let's add it to list"));
67-
status = "passed";
65+
// Verify Added item
66+
String item = getWebDriver().findElement(By.xpath("/html/body/div/div/div/ul/li[6]/span")).getText();
67+
AssertJUnit.assertTrue(item.contains("Yey, Let's add it to list"));
68+
status = "passed";
6869
}
69-
70-
catch(Exception e) {
71-
e.printStackTrace();
72-
}
7370

71+
catch (Exception e) {
72+
e.printStackTrace();
73+
}
7474

7575
}
7676

7777
@AfterMethod
7878
public void afterTest(ITestResult result) throws InterruptedException {
79-
((JavascriptExecutor) webDriver.get()).executeScript("lambda-status="
80-
+ (result.isSuccess() ? "passed" : "failed"));
81-
webDriver.get().quit();
82-
Thread.sleep(10000);
79+
((JavascriptExecutor) webDriver.get())
80+
.executeScript("lambda-status=" + (result.isSuccess() ? "passed" : "failed"));
81+
webDriver.get().quit();
82+
Thread.sleep(10000);
8383
}
8484

8585
private ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();
@@ -138,6 +138,7 @@ public WebDriver getWebDriver() {
138138
return webDriver.get();
139139
}
140140

141+
@BeforeMethod(alwaysRun=true)
141142
protected void setUp(String browser, String version, String os, String resolution, String methodName)
142143
throws Exception {
143144
DesiredCapabilities capabilities = new DesiredCapabilities();
@@ -153,8 +154,8 @@ protected void setUp(String browser, String version, String os, String resolutio
153154
capabilities.setCapability("video", true);
154155
capabilities.setCapability("console", true);
155156
capabilities.setCapability("visual", true);
156-
//capabilities.setCapability("fixedIP", "10.33.13.34");
157-
System.out.println("capabilities"+capabilities);
157+
capabilities.setCapability("tunnel", true);
158+
System.out.println("capabilities" + capabilities);
158159
// Launch remote browser and set it as the current thread
159160
webDriver.set(new RemoteWebDriver(new URL(gridURL), capabilities));
160161

src/test/java/com/lambdatest/Tests/ParallelTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
public class ParallelTest {
2525

2626
public static String status = "failed";
27+
private ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();
2728

2829
@Test(dataProvider = "browsersDetails")
2930
public void test(String browser, String version, String os, Method method) throws Exception {
@@ -55,17 +56,14 @@ public void test(String browser, String version, String os, Method method) throw
5556
}
5657
}
5758

58-
@AfterMethod(alwaysRun = true)
59+
@AfterTest(alwaysRun = true)
5960
public void tearDown(ITestResult result) throws Exception {
6061
((JavascriptExecutor) webDriver.get()).executeScript("lambda-status="
6162
+ (result.isSuccess() ? "passed" : "failed"));
6263
webDriver.get().quit();
6364
Thread.sleep(10000);
6465
}
6566

66-
67-
68-
private ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();
6967

7068
@DataProvider(name = "browsersDetails", parallel = true)
7169
public static Object[][] ltBrowserDataProvider(Method testMethod) {
@@ -84,7 +82,7 @@ public WebDriver getWebDriver() {
8482
return webDriver.get();
8583
}
8684

87-
85+
@BeforeTest(alwaysRun=true)
8886
protected void setUp(String browser, String version, String os, String methodName)
8987
throws Exception {
9088
DesiredCapabilities capabilities = new DesiredCapabilities();
@@ -101,11 +99,12 @@ protected void setUp(String browser, String version, String os, String methodNam
10199
capabilities.setCapability("video", true);
102100
capabilities.setCapability("console", false);
103101
capabilities.setCapability("visual", true);
104-
//capabilities.setCapability("fixedIP", "10.33.13.34");
102+
capabilities.setCapability("tunnel", true);
103+
105104
System.out.println("capabilities"+capabilities);
106105

107-
String username = Configuration.readConfig("LambdaTest_UserName");
108-
String accesskey = Configuration.readConfig("LambdaTest_AppKey");
106+
String username = System.getenv("LT_USERNAME") != null ?System.getenv("LT_USERNAME"): Configuration.readConfig("LambdaTest_UserName");
107+
String accesskey = System.getenv("LT_ACCESS_KEY") != null ?System.getenv("LT_ACCESS_KEY"):Configuration.readConfig("LambdaTest_AppKey");
109108

110109

111110
// Launch remote browser and set it as the current thread

src/test/java/com/lambdatest/Tests/SingleJenkinsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class SingleJenkinsTest {
2525
public static String status = "failed";
2626

2727
public static String username = System.getenv("LT_USERNAME");
28-
public static String accesskey = System.getenv("LT_APPKEY");
28+
public static String accesskey = System.getenv("LT_ACCESS_KEY");
2929
public static String gridURL = System.getenv("LT_GRID_URL");
3030
public static String os = System.getenv("LT_OPERATING_SYSTEM");
3131
public static String browser = System.getenv("LT_BROWSER_NAME");
@@ -45,6 +45,7 @@ public void setUp() throws Exception {
4545
capability.setCapability("video", true);
4646
capability.setCapability("console", true);
4747
capability.setCapability("visual", true);
48+
capability.setCapability("tunnel", true);
4849

4950
driver = new RemoteWebDriver(new URL(gridURL), capability);
5051

src/test/java/com/lambdatest/Tests/SingleTest.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,18 @@ public class SingleTest {
2121
public static WebDriver driver;
2222
public static String status = "failed";
2323

24-
//@SuppressWarnings("deprecation")
25-
///@BeforeTest
26-
//public void setUp() throws Exception {
27-
28-
public static void main(String args[]) throws Exception {
29-
30-
31-
String browser =Configuration.readConfig("browser");
24+
@BeforeTest(alwaysRun=true)
25+
public void setUp() throws Exception {
26+
27+
String browser = Configuration.readConfig("browser");
3228
String version = Configuration.readConfig("version");
3329
String os = Configuration.readConfig("os");
3430
String res = Configuration.readConfig("resolution");
3531

36-
String username = Configuration.readConfig("LambdaTest_UserName");
37-
String accesskey = Configuration.readConfig("LambdaTest_AppKey");
32+
String username = System.getenv("LT_USERNAME") != null ? System.getenv("LT_USERNAME")
33+
: Configuration.readConfig("LambdaTest_UserName");
34+
String accesskey = System.getenv("LT_ACCESS_KEY") != null ? System.getenv("LT_ACCESS_KEY")
35+
: Configuration.readConfig("LambdaTest_AppKey");
3836

3937
DesiredCapabilities capability = new DesiredCapabilities();
4038
capability.setCapability(CapabilityType.BROWSER_NAME, browser);
@@ -55,12 +53,9 @@ public static void main(String args[]) throws Exception {
5553
System.out.println("driver error");
5654
System.out.println(e.getMessage());
5755
}
58-
test();
59-
afterTest();
60-
6156
}
6257

63-
58+
@Test
6459
public static void test() {
6560
try {
6661

@@ -87,11 +82,12 @@ public static void test() {
8782
} catch (Exception e) {
8883
System.out.println(e.getMessage());
8984
} catch (Error e) {
90-
System.out.println("i am here assert failed");
85+
System.out.println("Assert failed");
9186
}
9287

9388
}
9489

90+
@AfterTest
9591
public static void afterTest() {
9692
((JavascriptExecutor) driver).executeScript("lambda-status=" + status + "");
9793
driver.quit();

0 commit comments

Comments
 (0)