-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathDropdownTests.java
More file actions
99 lines (70 loc) · 3.3 KB
/
Copy pathDropdownTests.java
File metadata and controls
99 lines (70 loc) · 3.3 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
package io.github.mfaisalkhatri.tests;
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
import static org.testng.Assert.assertEquals;
import java.util.regex.Pattern;
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
import com.microsoft.playwright.options.AriaRole;
import com.microsoft.playwright.options.SelectOption;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class DropdownTests {
private Playwright playwright;
private Page page;
@BeforeClass
public void setup() {
this.playwright = Playwright.create();
final Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false).setChannel("chrome"));
this.page = browser.newPage();
}
@Test
public void testSelectByOption() {
this.page.navigate("https://the-internet.herokuapp.com/dropdown");
final Locator dropdownField = this.page.locator("#dropdown");
dropdownField.selectOption("Option 2");
final String dropdownFieldSelectedValue = this.page.locator("#dropdown [selected='selected']").innerText();
assertEquals(dropdownFieldSelectedValue, "Option 2");
}
@Test
public void testSelectByLabel() {
this.page.navigate("https://the-internet.herokuapp.com/dropdown");
final Locator dropdownField = this.page.locator("#dropdown");
dropdownField.selectOption(new SelectOption().setLabel("Option 1"));
final String dropdownFieldSelectedValue = this.page.locator("#dropdown [selected='selected']").innerText();
assertEquals(dropdownFieldSelectedValue, "Option 1");
}
@Test
public void testSelectByIndex() {
this.page.navigate("https://the-internet.herokuapp.com/dropdown");
final Locator dropdownField = this.page.locator("#dropdown");
dropdownField.selectOption(new SelectOption().setIndex(2));
final String dropdownFieldSelectedValue = this.page.locator("#dropdown [selected='selected']").innerText();
assertEquals(dropdownFieldSelectedValue, "Option 2");
}
@Test
public void testSelectByValue() {
this.page.navigate ("https://the-internet.herokuapp.com/dropdown");
this.page.getByRole (AriaRole.COMBOBOX)
.selectOption ("Option 2");
assertThat (page.getByRole (AriaRole.COMBOBOX)).containsText ("Option 2");
}
@Test
public void testMultiSelectOptions() {
this.page.navigate("https://testautomationpractice.blogspot.com/");
final Locator dropdownField = this.page.getByRole (AriaRole.LISTBOX, new Page.GetByRoleOptions ().setName (
"Sorted List:"));
dropdownField.selectOption (new SelectOption [] {new SelectOption ().setLabel ("Cat"),
new SelectOption ().setLabel ("Cheetah"), new SelectOption ().setIndex (2)});
assertThat(dropdownField).hasValues (new Pattern[]{Pattern.compile ("cat"),
Pattern.compile ("cheetah"), Pattern.compile ("deer")});
}
@AfterClass
public void tearDown() {
this.page.close();
this.playwright.close();
}
}