3333import org .openqa .selenium .WebElement ;
3434import org .openqa .selenium .htmlunit .WebDriverTestCase ;
3535import org .openqa .selenium .htmlunit .junit .BrowserRunner ;
36+ import org .openqa .selenium .htmlunit .junit .BrowserRunner .Alerts ;
37+ import org .openqa .selenium .htmlunit .junit .BrowserRunner .HtmlUnitNYI ;
3638
3739/**
3840 * Tests for RelativeLocator.
4345public class RelativeLocatorTest extends WebDriverTestCase {
4446
4547 @ Test
48+ @ Alerts ({"2" , "mid" , "above" })
49+ @ HtmlUnitNYI (CHROME = {"1" , "above" , "above" },
50+ EDGE = {"1" , "above" , "above" },
51+ FF = {"1" , "above" , "above" },
52+ FF_ESR = {"1" , "above" , "above" })
4653 public void shouldBeAbleToFindElementsAboveAnotherWithTagName () throws Exception {
4754 final String html = getFileContent ("relative_locators.html" );
4855 final WebDriver driver = loadPage2 (html );
@@ -52,12 +59,17 @@ public void shouldBeAbleToFindElementsAboveAnotherWithTagName() throws Exception
5259 final List <WebElement > seen = driver .findElements (with (tagName ("p" )).above (lowest ));
5360 final List <String > ids = seen .stream ().map (e -> e .getAttribute ("id" )).collect (Collectors .toList ());
5461
55- assertEquals (2 , ids .size ());
56- assertTrue (ids .contains ("mid" ));
57- assertTrue (ids .contains ("above" ));
62+ assertEquals (Integer . parseInt ( getExpectedAlerts ()[ 0 ]) , ids .size ());
63+ assertTrue (ids .contains (getExpectedAlerts ()[ 1 ] ));
64+ assertTrue (ids .contains (getExpectedAlerts ()[ 2 ] ));
5865 }
5966
6067 @ Test
68+ @ Alerts ({"2" , "fourth" , "first" })
69+ @ HtmlUnitNYI (CHROME = {"1" , "first" , "first" },
70+ EDGE = {"1" , "first" , "first" },
71+ FF = {"1" , "first" , "first" },
72+ FF_ESR = {"1" , "first" , "first" })
6173 public void shouldBeAbleToFindElementsAboveAnotherWithXpath () throws Exception {
6274 final String html = getFileContent ("relative_locators.html" );
6375 final WebDriver driver = loadPage2 (html );
@@ -67,12 +79,17 @@ public void shouldBeAbleToFindElementsAboveAnotherWithXpath() throws Exception {
6779 final List <WebElement > seen = driver .findElements (with (xpath ("//td[1]" )).above (lowest ));
6880 final List <String > ids = seen .stream ().map (e -> e .getAttribute ("id" )).collect (Collectors .toList ());
6981
70- assertEquals (2 , ids .size ());
71- assertTrue (ids .contains ("fourth" ));
72- assertTrue (ids .contains ("first" ));
82+ assertEquals (Integer . parseInt ( getExpectedAlerts ()[ 0 ]) , ids .size ());
83+ assertTrue (ids .contains (getExpectedAlerts ()[ 1 ] ));
84+ assertTrue (ids .contains (getExpectedAlerts ()[ 2 ] ));
7385 }
7486
7587 @ Test
88+ @ Alerts ({"2" , "mid" , "above" })
89+ @ HtmlUnitNYI (CHROME = {"1" , "above" , "above" },
90+ EDGE = {"1" , "above" , "above" },
91+ FF = {"1" , "above" , "above" },
92+ FF_ESR = {"1" , "above" , "above" })
7693 public void shouldBeAbleToFindElementsAboveAnotherWithCssSelector () throws Exception {
7794 final String html = getFileContent ("relative_locators.html" );
7895 final WebDriver driver = loadPage2 (html );
@@ -82,12 +99,13 @@ public void shouldBeAbleToFindElementsAboveAnotherWithCssSelector() throws Excep
8299 final List <WebElement > seen = driver .findElements (with (cssSelector ("p" )).above (lowest ));
83100 final List <String > ids = seen .stream ().map (e -> e .getAttribute ("id" )).collect (Collectors .toList ());
84101
85- assertEquals (2 , ids .size ());
86- assertTrue (ids .contains ("mid" ));
87- assertTrue (ids .contains ("above" ));
102+ assertEquals (Integer . parseInt ( getExpectedAlerts ()[ 0 ]) , ids .size ());
103+ assertTrue (ids .contains (getExpectedAlerts ()[ 1 ] ));
104+ assertTrue (ids .contains (getExpectedAlerts ()[ 2 ] ));
88105 }
89106
90107 @ Test
108+ @ Alerts ({"1" , "third" })
91109 public void shouldBeAbleToCombineFilters () throws Exception {
92110 final String html = getFileContent ("relative_locators.html" );
93111 final WebDriver driver = loadPage2 (html );
@@ -96,11 +114,12 @@ public void shouldBeAbleToCombineFilters() throws Exception {
96114 with (tagName ("td" )).above (By .id ("center" )).toRightOf (By .id ("second" )));
97115 final List <String > ids = seen .stream ().map (e -> e .getAttribute ("id" )).collect (Collectors .toList ());
98116
99- assertEquals (1 , ids .size ());
100- assertTrue (ids .contains ("third" ));
117+ assertEquals (Integer . parseInt ( getExpectedAlerts ()[ 0 ]) , ids .size ());
118+ assertTrue (ids .contains (getExpectedAlerts ()[ 1 ] ));
101119 }
102120
103121 @ Test
122+ @ Alerts ({"1" , "fourth" })
104123 public void shouldBeAbleToCombineFiltersWithXpath () throws Exception {
105124 final String html = getFileContent ("relative_locators.html" );
106125 final WebDriver driver = loadPage2 (html );
@@ -109,11 +128,12 @@ public void shouldBeAbleToCombineFiltersWithXpath() throws Exception {
109128 with (xpath ("//td[1]" )).below (By .id ("second" )).above (By .id ("seventh" )));
110129 final List <String > ids = seen .stream ().map (e -> e .getAttribute ("id" )).collect (Collectors .toList ());
111130
112- assertEquals (1 , ids .size ());
113- assertTrue (ids .contains ("fourth" ));
131+ assertEquals (Integer . parseInt ( getExpectedAlerts ()[ 0 ]) , ids .size ());
132+ assertTrue (ids .contains (getExpectedAlerts ()[ 1 ] ));
114133 }
115134
116135 @ Test
136+ @ Alerts ({"1" , "third" })
117137 public void shouldBeAbleToCombineFiltersWithCssSelector () throws Exception {
118138 final String html = getFileContent ("relative_locators.html" );
119139 final WebDriver driver = loadPage2 (html );
@@ -122,8 +142,8 @@ public void shouldBeAbleToCombineFiltersWithCssSelector() throws Exception {
122142 with (cssSelector ("td" )).above (By .id ("center" )).toRightOf (By .id ("second" )));
123143 final List <String > ids = seen .stream ().map (e -> e .getAttribute ("id" )).collect (Collectors .toList ());
124144
125- assertEquals (1 , ids .size ());
126- assertTrue (ids .contains ("third" ));
145+ assertEquals (Integer . parseInt ( getExpectedAlerts ()[ 0 ]) , ids .size ());
146+ assertTrue (ids .contains (getExpectedAlerts ()[ 1 ] ));
127147 }
128148
129149 @ Test
0 commit comments