Skip to content

Commit 85318cb

Browse files
committed
Updating .NET bindings setting of timeouts for spec-compliance
This also removes some obsolete API entry points that have been marked as deprecated for some months now. The properties of the ITimeouts object should be used.
1 parent 1ff492f commit 85318cb

File tree

3 files changed

+38
-154
lines changed

3 files changed

+38
-154
lines changed

dotnet/src/support/Events/EventFiringWebDriver.cs

-47
Original file line numberDiff line numberDiff line change
@@ -1139,53 +1139,6 @@ public TimeSpan PageLoad
11391139
get { return this.wrappedTimeouts.PageLoad; }
11401140
set { this.wrappedTimeouts.PageLoad = value; }
11411141
}
1142-
1143-
/// <summary>
1144-
/// Specifies the amount of time the driver should wait when searching for an
1145-
/// element if it is not immediately present.
1146-
/// </summary>
1147-
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.</param>
1148-
/// <returns>A self reference</returns>
1149-
/// <remarks>
1150-
/// When searching for a single element, the driver should poll the page
1151-
/// until the element has been found, or this timeout expires before throwing
1152-
/// a <see cref="NoSuchElementException"/>. When searching for multiple elements,
1153-
/// the driver should poll the page until at least one element has been found
1154-
/// or this timeout has expired.
1155-
/// <para>
1156-
/// Increasing the implicit wait timeout should be used judiciously as it
1157-
/// will have an adverse effect on test run time, especially when used with
1158-
/// slower location strategies like XPath.
1159-
/// </para>
1160-
/// </remarks>
1161-
[Obsolete("This method will be removed in a future version. Please set the ImplicitWait property instead.")]
1162-
public ITimeouts ImplicitlyWait(TimeSpan timeToWait)
1163-
{
1164-
return this.wrappedTimeouts.ImplicitlyWait(timeToWait);
1165-
}
1166-
1167-
/// <summary>
1168-
/// Specifies the amount of time the driver should wait when executing JavaScript asynchronously.
1169-
/// </summary>
1170-
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.</param>
1171-
/// <returns>A self reference</returns>
1172-
[Obsolete("This method will be removed in a future version. Please set the AsynchronousJavaScript property instead.")]
1173-
public ITimeouts SetScriptTimeout(TimeSpan timeToWait)
1174-
{
1175-
return this.wrappedTimeouts.SetScriptTimeout(timeToWait);
1176-
}
1177-
1178-
/// <summary>
1179-
/// Specifies the amount of time the driver should wait for a page to load when setting the <see cref="IWebDriver.Url"/> property.
1180-
/// </summary>
1181-
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.</param>
1182-
/// <returns>A self reference</returns>
1183-
[Obsolete("This method will be removed in a future version. Please set the PageLoad property instead.")]
1184-
public ITimeouts SetPageLoadTimeout(TimeSpan timeToWait)
1185-
{
1186-
this.wrappedTimeouts.SetPageLoadTimeout(timeToWait);
1187-
return this;
1188-
}
11891142
}
11901143

11911144
/// <summary>

dotnet/src/webdriver/ITimeouts.cs

+1-40
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="ITimeouts.cs" company="WebDriver Committers">
1+
// <copyright file="ITimeouts.cs" company="WebDriver Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -58,44 +58,5 @@ public interface ITimeouts
5858
/// property.
5959
/// </summary>
6060
TimeSpan PageLoad { get; set; }
61-
62-
/// <summary>
63-
/// Specifies the amount of time the driver should wait when searching for an
64-
/// element if it is not immediately present.
65-
/// </summary>
66-
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.</param>
67-
/// <returns>A self reference</returns>
68-
/// <remarks>
69-
/// When searching for a single element, the driver should poll the page
70-
/// until the element has been found, or this timeout expires before throwing
71-
/// a <see cref="NoSuchElementException"/>. When searching for multiple elements,
72-
/// the driver should poll the page until at least one element has been found
73-
/// or this timeout has expired.
74-
/// <para>
75-
/// Increasing the implicit wait timeout should be used judiciously as it
76-
/// will have an adverse effect on test run time, especially when used with
77-
/// slower location strategies like XPath.
78-
/// </para>
79-
/// </remarks>
80-
[Obsolete("This method will be removed in a future version. Please set the ImplicitWait property instead.")]
81-
ITimeouts ImplicitlyWait(TimeSpan timeToWait);
82-
83-
/// <summary>
84-
/// Specifies the amount of time the driver should wait when executing JavaScript asynchronously.
85-
/// </summary>
86-
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.
87-
/// Setting this parameter to <see cref="TimeSpan.MinValue"/> will allow the script to run indefinitely.</param>
88-
/// <returns>A self reference</returns>
89-
[Obsolete("This method will be removed in a future version. Please set the AsynchronousJavaScript property instead.")]
90-
ITimeouts SetScriptTimeout(TimeSpan timeToWait);
91-
92-
/// <summary>
93-
/// Specifies the amount of time the driver should wait for a page to load when setting the <see cref="IWebDriver.Url"/> property.
94-
/// </summary>
95-
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.
96-
/// Setting this parameter to <see cref="TimeSpan.MinValue"/> will allow the page to load indefinitely.</param>
97-
/// <returns>A self reference</returns>
98-
[Obsolete("This method will be removed in a future version. Please set the PageLoad property instead.")]
99-
ITimeouts SetPageLoadTimeout(TimeSpan timeToWait);
10061
}
10162
}

dotnet/src/webdriver/Remote/RemoteTimeouts.cs

+37-67
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="RemoteTimeouts.cs" company="WebDriver Committers">
1+
// <copyright file="RemoteTimeouts.cs" company="WebDriver Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -27,6 +27,15 @@ namespace OpenQA.Selenium.Remote
2727
/// </summary>
2828
internal class RemoteTimeouts : ITimeouts
2929
{
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+
3039
private RemoteWebDriver driver;
3140

3241
/// <summary>
@@ -57,8 +66,8 @@ public RemoteTimeouts(RemoteWebDriver driver)
5766
/// </remarks>
5867
public TimeSpan ImplicitWait
5968
{
60-
get { return this.ExecuteGetTimeout("implicit"); }
61-
set { this.ExecuteSetTimeout("implicit", value); }
69+
get { return this.ExecuteGetTimeout(ImplicitTimeoutName); }
70+
set { this.ExecuteSetTimeout(ImplicitTimeoutName, value); }
6271
}
6372

6473
/// <summary>
@@ -69,8 +78,8 @@ public TimeSpan ImplicitWait
6978
/// </summary>
7079
public TimeSpan AsynchronousJavaScript
7180
{
72-
get { return this.ExecuteGetTimeout("script"); }
73-
set { this.ExecuteSetTimeout("script", value); }
81+
get { return this.ExecuteGetTimeout(AsyncScriptTimeoutName); }
82+
set { this.ExecuteSetTimeout(AsyncScriptTimeoutName, value); }
7483
}
7584

7685
/// <summary>
@@ -82,84 +91,27 @@ public TimeSpan PageLoad
8291
{
8392
get
8493
{
85-
string timeoutName = "page load";
94+
string timeoutName = LegacyPageLoadTimeoutName;
8695
if (this.driver.IsSpecificationCompliant)
8796
{
88-
timeoutName = "pageLoad";
97+
timeoutName = PageLoadTimeoutName;
8998
}
9099

91100
return this.ExecuteGetTimeout(timeoutName);
92101
}
93102

94103
set
95104
{
96-
string timeoutName = "page load";
105+
string timeoutName = LegacyPageLoadTimeoutName;
97106
if (this.driver.IsSpecificationCompliant)
98107
{
99-
timeoutName = "pageLoad";
108+
timeoutName = PageLoadTimeoutName;
100109
}
101110

102111
this.ExecuteSetTimeout(timeoutName, value);
103112
}
104113
}
105114

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-
163115
private TimeSpan ExecuteGetTimeout(string timeoutType)
164116
{
165117
if (this.driver.IsSpecificationCompliant)
@@ -184,7 +136,25 @@ private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait)
184136
double milliseconds = timeToWait.TotalMilliseconds;
185137
if (timeToWait == TimeSpan.MinValue)
186138
{
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+
}
188158
}
189159

190160
Dictionary<string, object> parameters = new Dictionary<string, object>();

0 commit comments

Comments
 (0)