-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathTest1.java
More file actions
165 lines (138 loc) · 6.48 KB
/
Test1.java
File metadata and controls
165 lines (138 loc) · 6.48 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
public class Test1
{
RemoteWebDriver driver = null;
public static String status = "passed";
public static String username = System.getenv("LT_USERNAME");
public static String access_key = System.getenv("LT_ACCESS_KEY");
String testURL = "https://todomvc.com/examples/react/#/";
String testURLTitle = "React • TodoMVC";
@BeforeMethod
@Parameters(value={"browser","version","platform", "resolution"})
public void testSetUp(String browser, String version, String platform, String resolution) throws Exception
{
String platformName = System.getenv("HYPEREXECUTE_PLATFORM") != null ? System.getenv("HYPEREXECUTE_PLATFORM") : platform;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("build", "testng-selenium-hyperexecute-sample");
capabilities.setCapability("name", "[HyperExecute - 1] Demonstration of the TestNG Framework");
capabilities.setCapability("platform", System.getenv("HYPEREXECUTE_PLATFORM"));
capabilities.setCapability("browserName", browser);
capabilities.setCapability("version", version);
capabilities.setCapability("tunnel",false);
capabilities.setCapability("network",true);
capabilities.setCapability("console",true);
capabilities.setCapability("visual",true);
try
{
driver = new RemoteWebDriver(new URL("https://" + username + ":" + access_key + "@hub.lambdatest.com/wd/hub"), capabilities);
}
catch (MalformedURLException e)
{
System.out.println("Invalid grid URL");
}
System.out.println("Started session");
}
@Test(description="To Do App on React App")
public void test1_element_addition_1() throws InterruptedException
{
ExtentReports extent = new ExtentReports("target/surefire-reports/html/extentReport.html");
ExtentTest test1 = extent.startTest("demo application test 1","To Do App test 1");
driver.get(testURL);
Thread.sleep(5000);
test1.log(LogStatus.PASS,"URL is opened");
// Thread.sleep(8*60*1000);
//add
/* Selenium Java 3.141.59 */
WebDriverWait wait = new WebDriverWait(driver, 5);
/* WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); */
test1.log(LogStatus.PASS, "Wait created");
/* Click on the Link */
By elem_new_item_locator = By.xpath("//input[@class='new-todo']");
WebElement elem_new_item = driver.findElement(elem_new_item_locator);
/* Add 5 items in the list */
Integer item_count = 5;
for (int count = 1; count <= item_count; count++)
{
/* Enter the text box for entering the new item */
elem_new_item.click();
elem_new_item.sendKeys("Adding a new item " + count + Keys.ENTER);
test1.log(LogStatus.PASS,"New item No. "+count+" is added");
Thread.sleep(2000);
}
extent.endTest(test1);
extent.flush();
WebElement temp_element;
/* Now that the items are added, we mark the top three items as completed */
for (int count = 1; count <= item_count; count++)
{
Integer fixed_cta_count = 1;
/* Enter the text box for entering the new item */
/* Create a varying string to create a new XPath */
String xpath_str = "//ul[@class='todo-list']/li[" + fixed_cta_count + "]" + "//input[@class='toggle']";
temp_element = driver.findElement(By.xpath(xpath_str));
temp_element.click();
Thread.sleep(2000);
/* Toggle button to destroy */
driver.findElement(By.xpath("//li[@class='completed']//button[@class='destroy']")).click();
Thread.sleep(1000);
}
/* Once you are outside this code, the list would be empty */
}
@Test(description="To Do App on React App")
public void test1_element_addition_2() throws InterruptedException
{
driver.get(testURL);
Thread.sleep(5000);
/* Selenium Java 3.141.59 */
WebDriverWait wait = new WebDriverWait(driver, 5);
/* WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); */
/* Click on the Link */
By elem_new_item_locator = By.xpath("//input[@class='new-todo']");
WebElement elem_new_item = driver.findElement(elem_new_item_locator);
/* Add 5 items in the list */
Integer item_count = 5;
for (int count = 1; count <= item_count; count++)
{
/* Enter the text box for entering the new item */
elem_new_item.click();
elem_new_item.sendKeys("Adding a new item " + count + Keys.ENTER);
Thread.sleep(2000);
}
WebElement temp_element;
/* Now that the items are added, we mark the top three items as completed */
for (int count = 1; count <= item_count; count++)
{
Integer fixed_cta_count = 1;
/* Enter the text box for entering the new item */
/* Create a varying string to create a new XPath */
String xpath_str = "//ul[@class='todo-list']/li[" + fixed_cta_count + "]" + "//input[@class='toggle']";
temp_element = driver.findElement(By.xpath(xpath_str));
temp_element.click();
Thread.sleep(2000);
/* Toggle button to destroy */
driver.findElement(By.xpath("//li[@class='completed']//button[@class='destroy']")).click();
Thread.sleep(1000);
}
/* Once you are outside this code, the list would be empty */
}
@AfterMethod
public void tearDown()
{
if (driver != null)
{
((JavascriptExecutor) driver).executeScript("lambda-status=" + status);
driver.quit();
}
}
}