-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddRemoveElements.java
More file actions
84 lines (69 loc) · 1.95 KB
/
AddRemoveElements.java
File metadata and controls
84 lines (69 loc) · 1.95 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
package Tests;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;
public class AddRemoveElements {
private static WebDriver driver = null;
public static String browserName = null;
//Setting up the Chrome browser
@BeforeTest
public void setUp() {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
}
@Test
public void testingAB() {
// Go to the page of dummy Website
driver.get("http://the-internet.herokuapp.com");
// Click the Add remove elements link
driver.findElement(By.xpath("//*[@id=\"content\"]/ul/li[2]/a")).click();
int j = 0;
int i = 0;
for (i = 1; i <= 5; i++) {
//Adding an element by clicking on Add element
driver.findElement(By.xpath("//*[@id=\"content\"]/div/button")).click();
//Adding an element after 1 second.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (j = 1; j <= 5; j++) {
// Deleting an element by clicking on delete Button.
driver.findElement(By.xpath("//*[@id=\"elements\"]/button")).click();
//Deleting an item after one second
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@AfterTest
public void tearDown() {
//Quitting and Closing the browser after test
driver.close();
driver.quit();
System.out.println("Tested successfully");
}
}