@@ -37,6 +37,52 @@ public RemoteTimeouts(RemoteWebDriver driver)
37
37
this . driver = driver ;
38
38
}
39
39
40
+ /// <summary>
41
+ /// Gets or sets the implicit wait timeout, which is the amount of time the
42
+ /// driver should wait when searching for an element if it is not immediately
43
+ /// present.
44
+ /// </summary>
45
+ /// <remarks>
46
+ /// When searching for a single element, the driver should poll the page
47
+ /// until the element has been found, or this timeout expires before throwing
48
+ /// a <see cref="NoSuchElementException"/>. When searching for multiple elements,
49
+ /// the driver should poll the page until at least one element has been found
50
+ /// or this timeout has expired.
51
+ /// <para>
52
+ /// Increasing the implicit wait timeout should be used judiciously as it
53
+ /// will have an adverse effect on test run time, especially when used with
54
+ /// slower location strategies like XPath.
55
+ /// </para>
56
+ /// </remarks>
57
+ public TimeSpan ImplicitWait
58
+ {
59
+ get { return this . ExecuteGetTimeout ( "implicit" ) ; }
60
+ set { this . ExecuteSetTimeout ( "implicit" , value ) ; }
61
+ }
62
+
63
+ /// <summary>
64
+ /// Gets or sets the asynchronous script timeout, which is the amount
65
+ /// of time the driver should wait when executing JavaScript asynchronously.
66
+ /// This timeout only affects the <see cref="IJavaScriptExecutor.ExecuteAsyncScript(string, object[])"/>
67
+ /// method.
68
+ /// </summary>
69
+ public TimeSpan AsynchronousJavaScript
70
+ {
71
+ get { return this . ExecuteGetTimeout ( "script" ) ; }
72
+ set { this . ExecuteSetTimeout ( "script" , value ) ; }
73
+ }
74
+
75
+ /// <summary>
76
+ /// Gets or sets the page load timeout, which is the amount of time the driver
77
+ /// should wait for a page to load when setting the <see cref="IWebDriver.Url"/>
78
+ /// property.
79
+ /// </summary>
80
+ public TimeSpan PageLoad
81
+ {
82
+ get { return this . ExecuteGetTimeout ( "page load" ) ; }
83
+ set { this . ExecuteSetTimeout ( "page load" , value ) ; }
84
+ }
85
+
40
86
/// <summary>
41
87
/// Specifies the amount of time the driver should wait when searching for an
42
88
/// element if it is not immediately present.
@@ -55,6 +101,7 @@ public RemoteTimeouts(RemoteWebDriver driver)
55
101
/// slower location strategies like XPath.
56
102
/// </para>
57
103
/// </remarks>
104
+ [ Obsolete ( "This method will be removed in a future version. Please set the ImplicitWait property instead." ) ]
58
105
public ITimeouts ImplicitlyWait ( TimeSpan timeToWait )
59
106
{
60
107
this . ExecuteSetTimeout ( "implicit" , timeToWait ) ;
@@ -67,6 +114,7 @@ public ITimeouts ImplicitlyWait(TimeSpan timeToWait)
67
114
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.
68
115
/// Setting this parameter to <see cref="TimeSpan.MinValue"/> will allow the script to run indefinitely.</param>
69
116
/// <returns>A self reference</returns>
117
+ [ Obsolete ( "This method will be removed in a future version. Please set the AsynchronousJavaScript property instead." ) ]
70
118
public ITimeouts SetScriptTimeout ( TimeSpan timeToWait )
71
119
{
72
120
this . ExecuteSetTimeout ( "script" , timeToWait ) ;
@@ -79,12 +127,32 @@ public ITimeouts SetScriptTimeout(TimeSpan timeToWait)
79
127
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.
80
128
/// Setting this parameter to <see cref="TimeSpan.MinValue"/> will allow the page to load indefinitely.</param>
81
129
/// <returns>A self reference</returns>
130
+ [ Obsolete ( "This method will be removed in a future version. Please set the PageLoad property instead." ) ]
82
131
public ITimeouts SetPageLoadTimeout ( TimeSpan timeToWait )
83
132
{
84
133
this . ExecuteSetTimeout ( "page load" , timeToWait ) ;
85
134
return this ;
86
135
}
87
136
137
+ private TimeSpan ExecuteGetTimeout ( string timeoutType )
138
+ {
139
+ if ( this . driver . IsSpecificationCompliant )
140
+ {
141
+ Response commandResponse = this . driver . InternalExecute ( DriverCommand . GetTimeouts , null ) ;
142
+ Dictionary < string , object > responseValue = ( Dictionary < string , object > ) commandResponse . Value ;
143
+ if ( ! responseValue . ContainsKey ( timeoutType ) )
144
+ {
145
+ throw new WebDriverException ( "Specified timeout type not defined" ) ;
146
+ }
147
+
148
+ return TimeSpan . FromMilliseconds ( Convert . ToDouble ( responseValue [ timeoutType ] ) ) ;
149
+ }
150
+ else
151
+ {
152
+ throw new NotImplementedException ( "Driver instance must comply with the W3C specification to support getting timeout values." ) ;
153
+ }
154
+ }
155
+
88
156
private void ExecuteSetTimeout ( string timeoutType , TimeSpan timeToWait )
89
157
{
90
158
double milliseconds = timeToWait . TotalMilliseconds ;
@@ -94,9 +162,17 @@ private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait)
94
162
}
95
163
96
164
Dictionary < string , object > parameters = new Dictionary < string , object > ( ) ;
97
- parameters . Add ( "type" , timeoutType ) ;
98
- parameters . Add ( "ms" , milliseconds ) ;
99
- this . driver . InternalExecute ( DriverCommand . SetTimeout , parameters ) ;
165
+ if ( this . driver . IsSpecificationCompliant )
166
+ {
167
+ parameters . Add ( timeoutType , Convert . ToInt64 ( milliseconds ) ) ;
168
+ }
169
+ else
170
+ {
171
+ parameters . Add ( "type" , timeoutType ) ;
172
+ parameters . Add ( "ms" , milliseconds ) ;
173
+ }
174
+
175
+ this . driver . InternalExecute ( DriverCommand . SetTimeouts , parameters ) ;
100
176
}
101
177
}
102
178
}
0 commit comments