File tree Expand file tree Collapse file tree 4 files changed +70
-2
lines changed Expand file tree Collapse file tree 4 files changed +70
-2
lines changed Original file line number Diff line number Diff line change 20
20
<version >3.141.59</version >
21
21
</dependency >
22
22
23
+ <dependency >
24
+ <groupId >org.seleniumhq.selenium</groupId >
25
+ <artifactId >selenium-support</artifactId >
26
+ <version >3.141.59</version >
27
+ </dependency >
28
+
29
+
23
30
<dependency >
24
31
<groupId >org.testng</groupId >
25
32
<artifactId >testng</artifactId >
Original file line number Diff line number Diff line change
1
+ package pages ;
2
+
3
+ import org .openqa .selenium .By ;
4
+ import org .openqa .selenium .WebDriver ;
5
+ import org .openqa .selenium .WebElement ;
6
+ import org .openqa .selenium .support .ui .Select ;
7
+
8
+ import java .util .List ;
9
+ import java .util .stream .Collectors ;
10
+
11
+ public class DropdownPage {
12
+
13
+ private WebDriver driver ;
14
+ private By dropdown = By .id ("dropdown" );
15
+
16
+ public DropdownPage (WebDriver driver ){
17
+ this .driver = driver ;
18
+ }
19
+
20
+ public void selectFromDropDown (String option ){
21
+ findDropDownElement ().selectByVisibleText (option );
22
+ }
23
+
24
+ public List <String > getSelectedOptions (){
25
+ List <WebElement > selectedElements = findDropDownElement ().getAllSelectedOptions ();
26
+ return selectedElements .stream ().map (e ->e .getText ()).collect (Collectors .toList ());
27
+ }
28
+
29
+ private Select findDropDownElement (){
30
+ return new Select (driver .findElement (dropdown ));
31
+ }
32
+ }
Original file line number Diff line number Diff line change 6
6
public class HomePage {
7
7
8
8
private WebDriver driver ;
9
- private By formAuthenticationLink = By .linkText ("Form Authentication" );
10
9
11
10
public HomePage (WebDriver driver ){
12
11
this .driver = driver ;
13
12
}
14
13
15
14
public LoginPage clickFormAuthentication (){
16
- driver . findElement ( formAuthenticationLink ). click ( );
15
+ clickLink ( "Form Authentication" );
17
16
return new LoginPage (driver );
18
17
}
18
+
19
+ public DropdownPage clickDropDown (){
20
+ clickLink ("Dropdown" );
21
+ return new DropdownPage (driver );
22
+ }
23
+
24
+ private void clickLink (String linkText ){
25
+ driver .findElement (By .linkText (linkText )).click ();
26
+ }
19
27
}
Original file line number Diff line number Diff line change
1
+ package dropdown ;
2
+
3
+ import base .BaseTests ;
4
+ import org .testng .annotations .Test ;
5
+
6
+ import static org .testng .Assert .assertEquals ;
7
+ import static org .testng .Assert .assertTrue ;
8
+
9
+ public class DropdownTests extends BaseTests {
10
+
11
+ @ Test
12
+ public void testSelectOption (){
13
+ var dropDownPage = homePage .clickDropDown ();
14
+
15
+ String option = "Option 1" ;
16
+ dropDownPage .selectFromDropDown (option );
17
+ var selectedOptions = dropDownPage .getSelectedOptions ();
18
+ assertEquals (selectedOptions .size (), 1 , "Incorrect number of selections" );
19
+ assertTrue (selectedOptions .contains (option ), "Option not selected" );
20
+ }
21
+ }
You can’t perform that action at this time.
0 commit comments