5
5
import org .openqa .selenium .By ;
6
6
import org .openqa .selenium .SearchContext ;
7
7
import org .openqa .selenium .WebElement ;
8
- import org .openqa .selenium .internal .FindsByXPath ;
9
8
10
9
import java .lang .reflect .Field ;
11
10
import java .util .List ;
12
11
13
12
import static com .google .common .collect .Lists .newArrayList ;
14
13
import static org .hamcrest .MatcherAssert .assertThat ;
15
14
import static org .hamcrest .core .Is .is ;
16
- import static org .mockito .Mockito .mock ;
17
- import static org .mockito .Mockito .when ;
15
+ import static org .mockito .Mockito .*;
18
16
19
17
public class FluentByTest {
20
18
@@ -33,7 +31,7 @@ public void attribute() throws IllegalAccessException {
33
31
34
32
FindsByXPathSearchContext context = mock (FindsByXPathSearchContext .class );
35
33
WebElement we = mock (WebElement .class );
36
- when (context .findElementByXPath ( ".//*[@foo = 'bar']" )).thenReturn (we );
34
+ when (context .findElement ( By . xpath ( ".//*[@foo = 'bar']" ) )).thenReturn (we );
37
35
WebElement bar = fooBar .findElement (context );
38
36
assertThat (bar , is (we ));
39
37
@@ -42,7 +40,7 @@ public void attribute() throws IllegalAccessException {
42
40
By lastFooBar = FluentBy .last (fooBar );
43
41
assertThat (lastFooBar .toString (), is ("FluentBy.last(FluentBy.attribute: foo = 'bar')" ));
44
42
45
- when (context .findElementByXPath ( ".//*[@foo = 'bar' and position() = last()]" )).thenReturn (we );
43
+ when (context .findElement ( By . xpath ( ".//*[@foo = 'bar' and position() = last()]" ) )).thenReturn (we );
46
44
WebElement lastBar = fooBar .findElement (context );
47
45
assertThat (lastBar , is (we ));
48
46
}
@@ -55,7 +53,7 @@ public void not_attribute() throws IllegalAccessException {
55
53
56
54
FindsByXPathSearchContext context = mock (FindsByXPathSearchContext .class );
57
55
WebElement we = mock (WebElement .class );
58
- when (context .findElementByXPath ( ".//*[not(@foo)]" )).thenReturn (we );
56
+ when (context .findElement ( By . xpath ( ".//*[not(@foo)]" ) )).thenReturn (we );
59
57
WebElement bar = notFoo .findElement (context );
60
58
61
59
assertThat (bar , is (we ));
@@ -65,7 +63,7 @@ public void not_attribute() throws IllegalAccessException {
65
63
By lastFooBar = FluentBy .last (notFoo );
66
64
assertThat (lastFooBar .toString (), is ("FluentBy.last(FluentBy.notAttribute: foo)" ));
67
65
68
- when (context .findElementByXPath ( ".//*[@foo = 'bar' and position() = last()]" )).thenReturn (we );
66
+ when (context .findElement ( By . xpath ( ".//*[@foo = 'bar' and position() = last()]" ) )).thenReturn (we );
69
67
WebElement lastBar = notFoo .findElement (context );
70
68
assertThat (lastBar , is (we ));
71
69
}
@@ -79,11 +77,11 @@ public void attribute_without_value() throws IllegalAccessException {
79
77
WebElement we = mock (WebElement .class );
80
78
WebElement we2 = mock (WebElement .class );
81
79
82
- when (context .findElementByXPath ( ".//*[@foo]" )).thenReturn (we );
80
+ when (context .findElement ( By . xpath ( ".//*[@foo]" ) )).thenReturn (we );
83
81
WebElement bar = fooBar .findElement (context );
84
82
assertThat (bar , is (we ));
85
83
86
- when (context .findElementsByXPath ( ".//*[@foo]" )).thenReturn (newArrayList (we , we2 ));
84
+ when (context .findElements ( By . xpath ( ".//*[@foo]" ) )).thenReturn (newArrayList (we , we2 ));
87
85
List <WebElement > bars = fooBar .findElements (context );
88
86
assertThat (bars .get (0 ), is (we ));
89
87
@@ -97,7 +95,7 @@ public void last() throws IllegalAccessException {
97
95
By lastFooBar = FluentBy .last ();
98
96
assertThat (lastFooBar .toString (), is ("FluentBy.last()" ));
99
97
100
- when (context .findElementByXPath ( ".//*[position() = last()]" )).thenReturn (we );
98
+ when (context .findElement ( By . xpath ( ".//*[position() = last()]" ) )).thenReturn (we );
101
99
WebElement lastBar = lastFooBar .findElement (context );
102
100
assertThat (lastBar , is (we ));
103
101
}
@@ -111,12 +109,13 @@ public void strict_class_name() throws IllegalAccessException {
111
109
By scn = FluentBy .strictClassName ("blort" );
112
110
assertThat (scn .toString (), is ("FluentBy.strictClassName: blort" ));
113
111
114
- when (context .findElementByXPath ( ".//*[@class = ' blort']" )).thenReturn (we );
112
+ when (context .findElement ( By . className ( " blort" ) )).thenReturn (we );
115
113
WebElement blort = scn .findElement (context );
116
114
assertThat (blort , is (we ));
117
115
118
- when (context .findElementsByXPath ( ".//*[@class = ' blort']" )).thenReturn (newArrayList (we , we2 ));
116
+ when (context .findElements ( By . className ( " blort" ) )).thenReturn (newArrayList (we , we2 ));
119
117
List <WebElement > blorts = scn .findElements (context );
118
+ //verifyNoMoreInteractions(we,we2, context);
120
119
assertThat (blorts .get (0 ), is (we ));
121
120
122
121
}
@@ -130,11 +129,11 @@ public void composite_classname() throws IllegalAccessException {
130
129
By aB = FluentBy .composite (new By .ByTagName ("a" ), new By .ByClassName ("b" ));
131
130
assertThat (aB .toString (), is ("FluentBy.composite([By.tagName: a, By.className: b])" ));
132
131
133
- when (context .findElementByXPath ( ".//a[contains(concat(' ',normalize-space(@class),' '),' b ')]" )).thenReturn (we );
132
+ when (context .findElement ( By . xpath ( ".//a[contains(concat(' ',normalize-space(@class),' '),' b ')]" ) )).thenReturn (we );
134
133
WebElement blort = aB .findElement (context );
135
134
assertThat (blort , is (we ));
136
135
137
- when (context .findElementsByXPath ( ".//a[contains(concat(' ',normalize-space(@class),' '),' b ')]" )).thenReturn (newArrayList (we , we2 ));
136
+ when (context .findElements ( By . xpath ( ".//a[contains(concat(' ',normalize-space(@class),' '),' b ')]" ) )).thenReturn (newArrayList (we , we2 ));
138
137
List <WebElement > blorts = aB .findElements (context );
139
138
assertThat (blorts .get (0 ), is (we ));
140
139
}
@@ -148,17 +147,17 @@ public void composite_attribute() throws IllegalAccessException {
148
147
By aB = FluentBy .composite (new By .ByTagName ("a" ), new FluentBy .ByAttribute ("b" , null ));
149
148
assertThat (aB .toString (), is ("FluentBy.composite([By.tagName: a, FluentBy.attribute: b])" ));
150
149
151
- when (context .findElementByXPath ( ".//a[@b]" )).thenReturn (we );
150
+ when (context .findElement ( By . xpath ( ".//a[@b]" ) )).thenReturn (we );
152
151
WebElement blort = aB .findElement (context );
153
152
//verifyNoMoreInteractions(context);
154
153
assertThat (blort , is (we ));
155
154
156
- when (context .findElementsByXPath ( ".//a[@b]" )).thenReturn (newArrayList (we , we2 ));
155
+ when (context .findElements ( By . xpath ( ".//a[@b]" ) )).thenReturn (newArrayList (we , we2 ));
157
156
List <WebElement > blorts = aB .findElements (context );
158
157
assertThat (blorts .get (0 ), is (we ));
159
158
160
159
}
161
160
162
- private static interface FindsByXPathSearchContext extends FindsByXPath , SearchContext {
161
+ private static interface FindsByXPathSearchContext extends SearchContext {
163
162
}
164
163
}
0 commit comments