21
21
import static org .mockito .Mockito .inOrder ;
22
22
import static org .mockito .Mockito .mock ;
23
23
import static org .mockito .Mockito .times ;
24
+ import static org .mockito .Mockito .when ;
25
+ import static org .mockito .Mockito .withSettings ;
24
26
25
27
import org .junit .Before ;
26
28
import org .junit .Test ;
30
32
import org .mockito .Mock ;
31
33
import org .mockito .MockitoAnnotations ;
32
34
import org .openqa .selenium .Keys ;
33
- import org .openqa .selenium .StubRenderedWebElement ;
34
35
import org .openqa .selenium .WebDriver ;
35
36
import org .openqa .selenium .WebElement ;
36
37
import org .openqa .selenium .interactions .internal .Coordinates ;
38
+ import org .openqa .selenium .internal .Locatable ;
37
39
38
40
/**
39
41
* Tests the builder for advanced user interaction, the Actions class.
@@ -51,25 +53,11 @@ public class ActionsTest {
51
53
public void setUp () {
52
54
MockitoAnnotations .initMocks (this );
53
55
54
- dummyLocatableElement = new StubRenderedWebElement () {
55
- @ Override
56
- public Coordinates getCoordinates () {
57
- return mockCoordinates ;
58
- }
59
- };
60
-
61
- driver = new StubInputDeviceDriver () {
62
- @ Override
63
- public Keyboard getKeyboard () {
64
- return mockKeyboard ;
65
- }
66
-
67
- @ Override
68
- public Mouse getMouse () {
69
- return mockMouse ;
70
- }
71
-
72
- };
56
+ dummyLocatableElement = mockLocatableElementWithCoordinates (mockCoordinates );
57
+
58
+ driver = mock (WebDriver .class , withSettings ().extraInterfaces (HasInputDevices .class ));
59
+ when (((HasInputDevices ) driver ).getKeyboard ()).thenReturn (mockKeyboard );
60
+ when (((HasInputDevices ) driver ).getMouse ()).thenReturn (mockMouse );
73
61
}
74
62
75
63
@ Test
@@ -112,19 +100,8 @@ public void supplyingIndividualElementsToKeyboardActions() {
112
100
final Coordinates dummyCoordinates2 = mock (Coordinates .class , "dummy2" );
113
101
final Coordinates dummyCoordinates3 = mock (Coordinates .class , "dummy3" );
114
102
115
- final WebElement dummyElement2 = new StubRenderedWebElement () {
116
- @ Override
117
- public Coordinates getCoordinates () {
118
- return dummyCoordinates2 ;
119
- }
120
- };
121
-
122
- final WebElement dummyElement3 = new StubRenderedWebElement () {
123
- @ Override
124
- public Coordinates getCoordinates () {
125
- return dummyCoordinates3 ;
126
- }
127
- };
103
+ final WebElement dummyElement2 = mockLocatableElementWithCoordinates (dummyCoordinates2 );
104
+ final WebElement dummyElement3 = mockLocatableElementWithCoordinates (dummyCoordinates3 );
128
105
129
106
Actions builder = new Actions (driver );
130
107
@@ -177,4 +154,10 @@ public void creatingAllMouseActions() {
177
154
order .verifyNoMoreInteractions ();
178
155
}
179
156
157
+ private WebElement mockLocatableElementWithCoordinates (Coordinates coord ) {
158
+ WebElement element = mock (WebElement .class ,
159
+ withSettings ().extraInterfaces (Locatable .class ));
160
+ when (((Locatable ) element ).getCoordinates ()).thenReturn (coord );
161
+ return element ;
162
+ }
180
163
}
0 commit comments