forked from LambdaTest/java-testng-selenium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestNGTodo2.java
121 lines (88 loc) · 4.23 KB
/
TestNGTodo2.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.lambdatest;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.ITestContext;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestNGTodo2 {
private RemoteWebDriver driver;
private String Status = "failed";
@BeforeMethod
public void setup(Method m, ITestContext ctx) throws MalformedURLException {
String username = "anubhas";
String authkey = "OmOOOshGyRoUgkriuFPDqahTb1fHdRHGXFPyStZb3BEXIQi1hg";
;
/*
Steps to run Smart UI project (https://beta-smartui.lambdatest.com/)
Step - 1 : Change the hub URL to @beta-smartui-hub.lambdatest.com/wd/hub
Step - 2 : Add "smartUI.project": "<Project Name>" as a capability above
Step - 3 : Add "((JavascriptExecutor) driver).executeScript("smartui.takeScreenshot");" code wherever you need to take a screenshot
Note: for additional capabilities navigate to https://www.lambdatest.com/support/docs/test-settings-options/
*/
String hub = "@hub.lambdatest.com/wd/hub";
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platform", "Windows 10");
caps.setCapability("browserName", "chrome");
caps.setCapability("version", "latest");
caps.setCapability("build", "TestNG With Java");
caps.setCapability("name", m.getName() + this.getClass().getName());
caps.setCapability("plugin", "git-testng");
/*
Enable Smart UI Project
caps.setCapability("smartUI.project", "<Project Name>");
*/
String[] Tags = new String[] { "Feature", "Magicleap", "Severe" };
caps.setCapability("tags", Tags);
driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps);
}
@Test
public void basicTest() throws InterruptedException {
String spanText;
System.out.println("Loading Url");
driver.get("https://lambdatest.github.io/sample-todo-app/");
System.out.println("Checking Box");
driver.findElement(By.name("li1")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li2")).click();
System.out.println("Checking Box");
driver.findElement(By.name("li3")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li4")).click();
driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 6");
driver.findElement(By.id("addbutton")).click();
driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 7");
driver.findElement(By.id("addbutton")).click();
driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 8");
driver.findElement(By.id("addbutton")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li1")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li3")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li7")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li8")).click();
System.out.println("Entering Text");
driver.findElement(By.id("sampletodotext")).sendKeys("Get Taste of Lambda and Stick to It");
driver.findElement(By.id("addbutton")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li9")).click();
// Let's also assert that the todo we added is present in the list.
spanText = driver.findElementByXPath("/html/body/div/div/div/ul/li[9]/span").getText();
Assert.assertEquals("Get Taste of Lambda and Stick to It", spanText);
Status = "passed";
Thread.sleep(150);
System.out.println("TestFinished");
}
@AfterMethod
public void tearDown() {
driver.executeScript("lambda-status=" + Status);
driver.quit();
}
}