-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindCheckedSkills.java
More file actions
81 lines (70 loc) · 2.18 KB
/
FindCheckedSkills.java
File metadata and controls
81 lines (70 loc) · 2.18 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
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class FindCheckedSkills {
private WebDriver driver;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver");
driver = new ChromeDriver();
}
@After
public void tearDown() {
driver.quit();
}
@Test
public void testCheckedSkills() {
driver.get("http://localhost:8080/workspace/xpath.html");
List<WebElement> skills = driver.findElements(By.cssSelector("#skills > li"));
String[] expected = {"Java", "C#"};
List<String> actual = new ArrayList();
for (WebElement skill: skills) {
// Is there a checked checkbox
try {
skill.findElement(By.cssSelector("input:checked"));
actual.add(skill.getText());
} catch (NoSuchElementException e) {}
}
assertArrayEquals(expected, actual.toArray());
}
@Test
public void testCheckedSkills2() {
driver.get("http://localhost:8080/workspace/xpath.html");
List<WebElement> skills = driver.findElements(By.cssSelector("#skills > li"));
String[] expected = {"Java", "C#"};
List<String> actual = new ArrayList();
for (WebElement skill: skills) {
// Is there a checked checkbox
WebElement checkbox = skill.findElement(By.tagName("input"));
if (
checkbox.getAttribute("checked") != null
&&
checkbox.getAttribute("checked").equals("true")
) {
actual.add(skill.getText());
}
}
assertArrayEquals(expected, actual.toArray());
}
@Test
public void testCheckedSkillsByXPath() {
driver.get("http://localhost:8080/workspace/xpath.html");
List<WebElement> checkedLis = driver.findElements(By.xpath(
"//*[@id='skills']//input[@checked]/.."
));
String[] expected = {"Java", "C#"};
List<String> actual = new ArrayList();
for (WebElement li: checkedLis) {
actual.add(li.getText());
}
assertArrayEquals(expected, actual.toArray());
}
}