1
- // <copyright file="RemoteTimeouts.cs" company="WebDriver Committers">
1
+ // <copyright file="RemoteTimeouts.cs" company="WebDriver Committers">
2
2
// Licensed to the Software Freedom Conservancy (SFC) under one
3
3
// or more contributor license agreements. See the NOTICE file
4
4
// distributed with this work for additional information
@@ -27,6 +27,15 @@ namespace OpenQA.Selenium.Remote
27
27
/// </summary>
28
28
internal class RemoteTimeouts : ITimeouts
29
29
{
30
+ private const string ImplicitTimeoutName = "implicit" ;
31
+ private const string AsyncScriptTimeoutName = "script" ;
32
+ private const string PageLoadTimeoutName = "pageLoad" ;
33
+ private const string LegacyPageLoadTimeoutName = "page load" ;
34
+
35
+ private readonly TimeSpan DefaultImplicitWaitTimeout = TimeSpan . FromSeconds ( 0 ) ;
36
+ private readonly TimeSpan DefaultAsyncScriptTimeout = TimeSpan . FromSeconds ( 30 ) ;
37
+ private readonly TimeSpan DefaultPageLoadTimeout = TimeSpan . FromSeconds ( 300 ) ;
38
+
30
39
private RemoteWebDriver driver ;
31
40
32
41
/// <summary>
@@ -57,8 +66,8 @@ public RemoteTimeouts(RemoteWebDriver driver)
57
66
/// </remarks>
58
67
public TimeSpan ImplicitWait
59
68
{
60
- get { return this . ExecuteGetTimeout ( "implicit" ) ; }
61
- set { this . ExecuteSetTimeout ( "implicit" , value ) ; }
69
+ get { return this . ExecuteGetTimeout ( ImplicitTimeoutName ) ; }
70
+ set { this . ExecuteSetTimeout ( ImplicitTimeoutName , value ) ; }
62
71
}
63
72
64
73
/// <summary>
@@ -69,8 +78,8 @@ public TimeSpan ImplicitWait
69
78
/// </summary>
70
79
public TimeSpan AsynchronousJavaScript
71
80
{
72
- get { return this . ExecuteGetTimeout ( "script" ) ; }
73
- set { this . ExecuteSetTimeout ( "script" , value ) ; }
81
+ get { return this . ExecuteGetTimeout ( AsyncScriptTimeoutName ) ; }
82
+ set { this . ExecuteSetTimeout ( AsyncScriptTimeoutName , value ) ; }
74
83
}
75
84
76
85
/// <summary>
@@ -82,84 +91,27 @@ public TimeSpan PageLoad
82
91
{
83
92
get
84
93
{
85
- string timeoutName = "page load" ;
94
+ string timeoutName = LegacyPageLoadTimeoutName ;
86
95
if ( this . driver . IsSpecificationCompliant )
87
96
{
88
- timeoutName = "pageLoad" ;
97
+ timeoutName = PageLoadTimeoutName ;
89
98
}
90
99
91
100
return this . ExecuteGetTimeout ( timeoutName ) ;
92
101
}
93
102
94
103
set
95
104
{
96
- string timeoutName = "page load" ;
105
+ string timeoutName = LegacyPageLoadTimeoutName ;
97
106
if ( this . driver . IsSpecificationCompliant )
98
107
{
99
- timeoutName = "pageLoad" ;
108
+ timeoutName = PageLoadTimeoutName ;
100
109
}
101
110
102
111
this . ExecuteSetTimeout ( timeoutName , value ) ;
103
112
}
104
113
}
105
114
106
- /// <summary>
107
- /// Specifies the amount of time the driver should wait when searching for an
108
- /// element if it is not immediately present.
109
- /// </summary>
110
- /// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.</param>
111
- /// <returns>A self reference</returns>
112
- /// <remarks>
113
- /// When searching for a single element, the driver should poll the page
114
- /// until the element has been found, or this timeout expires before throwing
115
- /// a <see cref="NoSuchElementException"/>. When searching for multiple elements,
116
- /// the driver should poll the page until at least one element has been found
117
- /// or this timeout has expired.
118
- /// <para>
119
- /// Increasing the implicit wait timeout should be used judiciously as it
120
- /// will have an adverse effect on test run time, especially when used with
121
- /// slower location strategies like XPath.
122
- /// </para>
123
- /// </remarks>
124
- [ Obsolete ( "This method will be removed in a future version. Please set the ImplicitWait property instead." ) ]
125
- public ITimeouts ImplicitlyWait ( TimeSpan timeToWait )
126
- {
127
- this . ExecuteSetTimeout ( "implicit" , timeToWait ) ;
128
- return this ;
129
- }
130
-
131
- /// <summary>
132
- /// Specifies the amount of time the driver should wait when executing JavaScript asynchronously.
133
- /// </summary>
134
- /// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.
135
- /// Setting this parameter to <see cref="TimeSpan.MinValue"/> will allow the script to run indefinitely.</param>
136
- /// <returns>A self reference</returns>
137
- [ Obsolete ( "This method will be removed in a future version. Please set the AsynchronousJavaScript property instead." ) ]
138
- public ITimeouts SetScriptTimeout ( TimeSpan timeToWait )
139
- {
140
- this . ExecuteSetTimeout ( "script" , timeToWait ) ;
141
- return this ;
142
- }
143
-
144
- /// <summary>
145
- /// Specifies the amount of time the driver should wait for a page to load when setting the <see cref="IWebDriver.Url"/> property.
146
- /// </summary>
147
- /// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.
148
- /// Setting this parameter to <see cref="TimeSpan.MinValue"/> will allow the page to load indefinitely.</param>
149
- /// <returns>A self reference</returns>
150
- [ Obsolete ( "This method will be removed in a future version. Please set the PageLoad property instead." ) ]
151
- public ITimeouts SetPageLoadTimeout ( TimeSpan timeToWait )
152
- {
153
- string timeoutName = "page load" ;
154
- if ( this . driver . IsSpecificationCompliant )
155
- {
156
- timeoutName = "pageLoad" ;
157
- }
158
-
159
- this . ExecuteSetTimeout ( timeoutName , timeToWait ) ;
160
- return this ;
161
- }
162
-
163
115
private TimeSpan ExecuteGetTimeout ( string timeoutType )
164
116
{
165
117
if ( this . driver . IsSpecificationCompliant )
@@ -184,7 +136,25 @@ private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait)
184
136
double milliseconds = timeToWait . TotalMilliseconds ;
185
137
if ( timeToWait == TimeSpan . MinValue )
186
138
{
187
- milliseconds = - 1 ;
139
+ if ( this . driver . IsSpecificationCompliant )
140
+ {
141
+ if ( timeoutType == ImplicitTimeoutName )
142
+ {
143
+ milliseconds = DefaultImplicitWaitTimeout . TotalMilliseconds ;
144
+ }
145
+ else if ( timeoutType == AsyncScriptTimeoutName )
146
+ {
147
+ milliseconds = DefaultAsyncScriptTimeout . TotalMilliseconds ;
148
+ }
149
+ else
150
+ {
151
+ milliseconds = DefaultPageLoadTimeout . TotalMilliseconds ;
152
+ }
153
+ }
154
+ else
155
+ {
156
+ milliseconds = - 1 ;
157
+ }
188
158
}
189
159
190
160
Dictionary < string , object > parameters = new Dictionary < string , object > ( ) ;
0 commit comments