17
17
18
18
package org .openqa .selenium .support .ui ;
19
19
20
+ import static org .hamcrest .CoreMatchers .containsString ;
21
+ import static org .hamcrest .CoreMatchers .instanceOf ;
22
+ import static org .junit .Assert .assertNotNull ;
20
23
import static org .junit .Assert .assertSame ;
24
+ import static org .junit .Assert .assertThat ;
21
25
import static org .junit .Assert .fail ;
26
+ import static org .mockito .Matchers .any ;
22
27
import static org .mockito .Mockito .mock ;
23
28
import static org .mockito .Mockito .when ;
29
+ import static org .mockito .Mockito .withSettings ;
30
+ import static org .openqa .selenium .testing .TestUtilities .catchThrowable ;
24
31
25
32
import org .junit .Before ;
26
33
import org .junit .Test ;
27
34
import org .junit .runner .RunWith ;
28
35
import org .junit .runners .JUnit4 ;
29
36
import org .mockito .Mock ;
30
37
import org .mockito .MockitoAnnotations ;
38
+ import org .openqa .selenium .Capabilities ;
39
+ import org .openqa .selenium .MutableCapabilities ;
31
40
import org .openqa .selenium .NoSuchElementException ;
32
41
import org .openqa .selenium .NoSuchFrameException ;
33
42
import org .openqa .selenium .NoSuchWindowException ;
34
43
import org .openqa .selenium .TimeoutException ;
35
44
import org .openqa .selenium .WebDriver ;
36
45
import org .openqa .selenium .WebElement ;
46
+ import org .openqa .selenium .internal .WrapsDriver ;
47
+ import org .openqa .selenium .remote .Command ;
48
+ import org .openqa .selenium .remote .CommandExecutor ;
49
+ import org .openqa .selenium .remote .RemoteWebDriver ;
50
+ import org .openqa .selenium .remote .Response ;
51
+ import org .openqa .selenium .remote .SessionId ;
52
+
53
+ import java .io .IOException ;
37
54
38
55
@ RunWith (JUnit4 .class )
39
56
public class WebDriverWaitTest {
@@ -46,6 +63,28 @@ public void createMocks() {
46
63
MockitoAnnotations .initMocks (this );
47
64
}
48
65
66
+ @ Test
67
+ public void shouldIncludeRemoteInfoForWrappedDriverTimeout () throws IOException {
68
+ Capabilities caps = new MutableCapabilities ();
69
+ Response response = new Response (new SessionId ("foo" ));
70
+ response .setValue (caps .asMap ());
71
+ CommandExecutor executor = mock (CommandExecutor .class );
72
+ when (executor .execute (any (Command .class ))).thenReturn (response );
73
+
74
+ RemoteWebDriver driver = new RemoteWebDriver (executor , caps );
75
+ WebDriver testDriver = mock (WebDriver .class , withSettings ().extraInterfaces (WrapsDriver .class ));
76
+ when (((WrapsDriver ) testDriver ).getWrappedDriver ()).thenReturn (driver );
77
+
78
+ TickingClock clock = new TickingClock (200 );
79
+ WebDriverWait wait = new WebDriverWait (testDriver , clock , clock , 1 , 200 );
80
+
81
+ Throwable ex = catchThrowable (() -> wait .until ((d ) -> false ));
82
+ assertNotNull (ex );
83
+ assertThat (ex , instanceOf (TimeoutException .class ));
84
+ assertThat (ex .getMessage (), containsString ("Capabilities [{javascriptEnabled=true, platformName=ANY, platform=ANY}]" ));
85
+ assertThat (ex .getMessage (), containsString ("Session ID: foo" ));
86
+ }
87
+
49
88
@ Test
50
89
public void shouldThrowAnExceptionIfTheTimerRunsOut () {
51
90
TickingClock clock = new TickingClock (200 );
@@ -105,4 +144,3 @@ public Boolean apply(WebDriver driver) {
105
144
}
106
145
}
107
146
}
108
-
0 commit comments