Skip to content

Commit e4c0a4d

Browse files
committed
Updating .NET bindings specification compliance for windows and timeouts
This commit properly implements the local end of the W3C WebDriver specification for getting and setting window size and position, and for getting and setting timeouts. It also marks as obsolete the methods for the ITimeouts interface in favor of properties, since the specification supports getting as well as setting timeouts.
1 parent 94db948 commit e4c0a4d

File tree

7 files changed

+216
-53
lines changed

7 files changed

+216
-53
lines changed

dotnet/src/webdriver/ITimeouts.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,40 @@ namespace OpenQA.Selenium
2525
/// </summary>
2626
public interface ITimeouts
2727
{
28+
/// <summary>
29+
/// Gets or sets the implicit wait timeout, which is the amount of time the
30+
/// driver should wait when searching for an element if it is not immediately
31+
/// present.
32+
/// </summary>
33+
/// <remarks>
34+
/// When searching for a single element, the driver should poll the page
35+
/// until the element has been found, or this timeout expires before throwing
36+
/// a <see cref="NoSuchElementException"/>. When searching for multiple elements,
37+
/// the driver should poll the page until at least one element has been found
38+
/// or this timeout has expired.
39+
/// <para>
40+
/// Increasing the implicit wait timeout should be used judiciously as it
41+
/// will have an adverse effect on test run time, especially when used with
42+
/// slower location strategies like XPath.
43+
/// </para>
44+
/// </remarks>
45+
TimeSpan ImplicitWait { get; set; }
46+
47+
/// <summary>
48+
/// Gets or sets the asynchronous script timeout, which is the amount
49+
/// of time the driver should wait when executing JavaScript asynchronously.
50+
/// This timeout only affects the <see cref="IJavaScriptExecutor.ExecuteAsyncScript(string, object[])"/>
51+
/// method.
52+
/// </summary>
53+
TimeSpan AsynchronousJavaScript { get; set; }
54+
55+
/// <summary>
56+
/// Gets or sets the page load timeout, which is the amount of time the driver
57+
/// should wait for a page to load when setting the <see cref="IWebDriver.Url"/>
58+
/// property.
59+
/// </summary>
60+
TimeSpan PageLoad { get; set; }
61+
2862
/// <summary>
2963
/// Specifies the amount of time the driver should wait when searching for an
3064
/// element if it is not immediately present.
@@ -43,6 +77,7 @@ public interface ITimeouts
4377
/// slower location strategies like XPath.
4478
/// </para>
4579
/// </remarks>
80+
[Obsolete("This method will be removed in a future version. Please set the ImplicitWait property instead.")]
4681
ITimeouts ImplicitlyWait(TimeSpan timeToWait);
4782

4883
/// <summary>
@@ -51,6 +86,7 @@ public interface ITimeouts
5186
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.
5287
/// Setting this parameter to <see cref="TimeSpan.MinValue"/> will allow the script to run indefinitely.</param>
5388
/// <returns>A self reference</returns>
89+
[Obsolete("This method will be removed in a future version. Please set the AsynchronousJavaScript property instead.")]
5490
ITimeouts SetScriptTimeout(TimeSpan timeToWait);
5591

5692
/// <summary>
@@ -59,6 +95,7 @@ public interface ITimeouts
5995
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.
6096
/// Setting this parameter to <see cref="TimeSpan.MinValue"/> will allow the page to load indefinitely.</param>
6197
/// <returns>A self reference</returns>
98+
[Obsolete("This method will be removed in a future version. Please set the PageLoad property instead.")]
6299
ITimeouts SetPageLoadTimeout(TimeSpan timeToWait);
63100
}
64101
}

dotnet/src/webdriver/Remote/DriverCommand.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,26 @@ public static class DriverCommand
313313
/// </summary>
314314
public static readonly string SetWindowPosition = "setWindowPosition";
315315

316+
/// <summary>
317+
/// Represents GetWindowRect command
318+
/// </summary>
319+
public static readonly string GetWindowRect = "getWindowRect";
320+
321+
/// <summary>
322+
/// Represents SetWindowRect command
323+
/// </summary>
324+
public static readonly string SetWindowRect = "setWindowRect";
325+
316326
/// <summary>
317327
/// Represents MaximizeWindow command
318328
/// </summary>
319329
public static readonly string MaximizeWindow = "maximizeWindow";
320330

331+
/// <summary>
332+
/// Represents MinimizeWindow command
333+
/// </summary>
334+
public static readonly string MinimizeWindow = "minimizeWindow";
335+
321336
/// <summary>
322337
/// Represents FullScreenWindow command
323338
/// </summary>
@@ -361,7 +376,12 @@ public static class DriverCommand
361376
/// <summary>
362377
/// Represents the SetTimeout command
363378
/// </summary>
364-
public static readonly string SetTimeout = "setTimeout";
379+
public static readonly string SetTimeouts = "setTimeouts";
380+
381+
/// <summary>
382+
/// Represents the SetTimeout command
383+
/// </summary>
384+
public static readonly string GetTimeouts = "getTimeouts";
365385

366386
/// <summary>
367387
/// Represents the Actions command.

dotnet/src/webdriver/Remote/RemoteTimeouts.cs

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,52 @@ public RemoteTimeouts(RemoteWebDriver driver)
3737
this.driver = driver;
3838
}
3939

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+
4086
/// <summary>
4187
/// Specifies the amount of time the driver should wait when searching for an
4288
/// element if it is not immediately present.
@@ -55,6 +101,7 @@ public RemoteTimeouts(RemoteWebDriver driver)
55101
/// slower location strategies like XPath.
56102
/// </para>
57103
/// </remarks>
104+
[Obsolete("This method will be removed in a future version. Please set the ImplicitWait property instead.")]
58105
public ITimeouts ImplicitlyWait(TimeSpan timeToWait)
59106
{
60107
this.ExecuteSetTimeout("implicit", timeToWait);
@@ -67,6 +114,7 @@ public ITimeouts ImplicitlyWait(TimeSpan timeToWait)
67114
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.
68115
/// Setting this parameter to <see cref="TimeSpan.MinValue"/> will allow the script to run indefinitely.</param>
69116
/// <returns>A self reference</returns>
117+
[Obsolete("This method will be removed in a future version. Please set the AsynchronousJavaScript property instead.")]
70118
public ITimeouts SetScriptTimeout(TimeSpan timeToWait)
71119
{
72120
this.ExecuteSetTimeout("script", timeToWait);
@@ -79,12 +127,32 @@ public ITimeouts SetScriptTimeout(TimeSpan timeToWait)
79127
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.
80128
/// Setting this parameter to <see cref="TimeSpan.MinValue"/> will allow the page to load indefinitely.</param>
81129
/// <returns>A self reference</returns>
130+
[Obsolete("This method will be removed in a future version. Please set the PageLoad property instead.")]
82131
public ITimeouts SetPageLoadTimeout(TimeSpan timeToWait)
83132
{
84133
this.ExecuteSetTimeout("page load", timeToWait);
85134
return this;
86135
}
87136

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+
88156
private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait)
89157
{
90158
double milliseconds = timeToWait.TotalMilliseconds;
@@ -94,9 +162,17 @@ private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait)
94162
}
95163

96164
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);
100176
}
101177
}
102178
}

dotnet/src/webdriver/Remote/RemoteWebDriver.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,8 @@ protected void StartSession(ICapabilities desiredCapabilities)
10741074
{
10751075
DesiredCapabilities capabilitiesObject = desiredCapabilities as DesiredCapabilities;
10761076
Dictionary<string, object> parameters = new Dictionary<string, object>();
1077+
Dictionary<string, object> capabilitiesParameter = new Dictionary<string, object>();
1078+
capabilitiesParameter["desiredCapabilities"] = capabilitiesObject.CapabilitiesDictionary;
10771079
parameters.Add("desiredCapabilities", capabilitiesObject.CapabilitiesDictionary);
10781080
Response response = this.Execute(DriverCommand.NewSession, parameters);
10791081

dotnet/src/webdriver/Remote/RemoteWindow.cs

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,18 @@ public Point Position
4747
{
4848
get
4949
{
50-
Dictionary<string, object> parameters = new Dictionary<string, object>();
51-
parameters.Add("windowHandle", "current");
52-
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowPosition, parameters);
50+
Response commandResponse;
51+
if (this.driver.IsSpecificationCompliant)
52+
{
53+
commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null);
54+
}
55+
else
56+
{
57+
Dictionary<string, object> parameters = new Dictionary<string, object>();
58+
parameters.Add("windowHandle", "current");
59+
commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowPosition, parameters);
60+
}
61+
5362
Dictionary<string, object> rawPosition = (Dictionary<string, object>)commandResponse.Value;
5463
int x = Convert.ToInt32(rawPosition["x"], CultureInfo.InvariantCulture);
5564
int y = Convert.ToInt32(rawPosition["y"], CultureInfo.InvariantCulture);
@@ -59,10 +68,17 @@ public Point Position
5968
set
6069
{
6170
Dictionary<string, object> parameters = new Dictionary<string, object>();
62-
parameters.Add("windowHandle", "current");
6371
parameters.Add("x", value.X);
6472
parameters.Add("y", value.Y);
65-
this.driver.InternalExecute(DriverCommand.SetWindowPosition, parameters);
73+
if (this.driver.IsSpecificationCompliant)
74+
{
75+
this.driver.InternalExecute(DriverCommand.SetWindowRect, parameters);
76+
}
77+
else
78+
{
79+
parameters.Add("windowHandle", "current");
80+
this.driver.InternalExecute(DriverCommand.SetWindowPosition, parameters);
81+
}
6682
}
6783
}
6884

@@ -74,9 +90,18 @@ public Size Size
7490
{
7591
get
7692
{
77-
Dictionary<string, object> parameters = new Dictionary<string, object>();
78-
parameters.Add("windowHandle", "current");
79-
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowSize, parameters);
93+
Response commandResponse;
94+
if (this.driver.IsSpecificationCompliant)
95+
{
96+
commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null);
97+
}
98+
else
99+
{
100+
Dictionary<string, object> parameters = new Dictionary<string, object>();
101+
parameters.Add("windowHandle", "current");
102+
commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowSize, parameters);
103+
}
104+
80105
Dictionary<string, object> rawPosition = (Dictionary<string, object>)commandResponse.Value;
81106
int height = Convert.ToInt32(rawPosition["height"], CultureInfo.InvariantCulture);
82107
int width = Convert.ToInt32(rawPosition["width"], CultureInfo.InvariantCulture);
@@ -86,10 +111,17 @@ public Size Size
86111
set
87112
{
88113
Dictionary<string, object> parameters = new Dictionary<string, object>();
89-
parameters.Add("windowHandle", "current");
90114
parameters.Add("width", value.Width);
91115
parameters.Add("height", value.Height);
92-
this.driver.InternalExecute(DriverCommand.SetWindowSize, parameters);
116+
if (this.driver.IsSpecificationCompliant)
117+
{
118+
this.driver.InternalExecute(DriverCommand.SetWindowRect, parameters);
119+
}
120+
else
121+
{
122+
parameters.Add("windowHandle", "current");
123+
this.driver.InternalExecute(DriverCommand.SetWindowSize, parameters);
124+
}
93125
}
94126
}
95127

@@ -98,8 +130,13 @@ public Size Size
98130
/// </summary>
99131
public void Maximize()
100132
{
101-
Dictionary<string, object> parameters = new Dictionary<string, object>();
102-
parameters.Add("windowHandle", "current");
133+
Dictionary<string, object> parameters = null;
134+
if (!this.driver.IsSpecificationCompliant)
135+
{
136+
parameters = new Dictionary<string, object>();
137+
parameters.Add("windowHandle", "current");
138+
}
139+
103140
this.driver.InternalExecute(DriverCommand.MaximizeWindow, parameters);
104141
}
105142
}

0 commit comments

Comments
 (0)