Skip to content

Commit bd84f28

Browse files
committed
Fixes the timeout on driver.Get
1 parent dcb6ad4 commit bd84f28

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

Selenium/Common/SearchContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void WaitNotElement(By by, int timeout = -1) {
4141
/// </summary>
4242
/// <param name="strategy">The mechanism by which to find the elements.</param>
4343
/// <param name="value">The value to use to search for the elements.</param>
44-
/// <param name="timeout"></param>
44+
/// <param name="timeout">Optional timeout in milliseconds</param>
4545
/// <param name="raise"></param>
4646
/// <returns>WebElement</returns>
4747
public WebElement FindElementBy(Strategy strategy, string value, int timeout = -1, bool raise = true) {

Selenium/Common/Timeouts.cs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Selenium {
99
/// </summary>
1010
/// <example>
1111
/// Sets the implicit timout to 1 second
12-
/// <code lang="vbs">
12+
/// <code lang="vb">
1313
/// driver.Timeouts.ImplicitWait = 1000
1414
/// </code>
1515
/// </example>
@@ -19,10 +19,25 @@ namespace Selenium {
1919
[ComVisible(true), ClassInterface(ClassInterfaceType.None)]
2020
public class Timeouts : ComInterfaces._Timeouts {
2121

22-
internal int timeout_implicitwait = 3000;
23-
internal int timeout_pageload = -1;
24-
internal int timeout_script = -1;
25-
internal int timeout_server = 60000;
22+
private static void SendTimeoutScript(RemoteSession session, int timeout) {
23+
session.Send(RequestMethod.POST, "/timeouts", "type", "script", "ms", timeout);
24+
}
25+
26+
private static void SendTimeoutPageLoad(RemoteSession session, int timeout) {
27+
session.Send(RequestMethod.POST, "/timeouts", "type", "page load", "ms", timeout);
28+
}
29+
30+
private static void SendTimeoutImplicit(RemoteSession session, int timeout) {
31+
session.Send(RequestMethod.POST, "/timeouts", "type", "implicit", "ms", timeout);
32+
}
33+
34+
35+
private RemoteSession _session;
36+
37+
internal int timeout_server = 90000; // 90 seconds
38+
internal int timeout_pageload = 60000; // 60 seconds
39+
internal int timeout_implicitwait = 3000; // 3 seconds
40+
internal int timeout_script = 15000; // 15 seconds
2641

2742
/// <summary>
2843
/// Amount of time that Selenium will wait for waiting commands to complete
@@ -32,6 +47,7 @@ public int ImplicitWait {
3247
return timeout_implicitwait;
3348
}
3449
set {
50+
if (value == timeout_implicitwait) return;
3551
timeout_implicitwait = value;
3652
}
3753
}
@@ -44,18 +60,24 @@ public int PageLoad {
4460
return timeout_pageload;
4561
}
4662
set {
63+
if (value == timeout_pageload) return;
64+
if (_session != null)
65+
SendTimeoutPageLoad(_session, value);
4766
timeout_pageload = value;
4867
}
4968
}
5069

5170
/// <summary>
52-
/// Amount of time the driver should wait while executing a script before throwing an exception.
71+
/// Amount of time the driver should wait while executing an asynchronous script before throwing an error.
5372
/// </summary>
5473
public int Script {
5574
get {
5675
return timeout_script;
5776
}
5877
set {
78+
if (value == timeout_script) return;
79+
if (_session != null)
80+
SendTimeoutScript(_session, value);
5981
timeout_script = value;
6082
}
6183
}
@@ -68,10 +90,17 @@ public int Server {
6890
return timeout_server;
6991
}
7092
set {
93+
if (value == timeout_server) return;
7194
timeout_server = value;
7295
}
7396
}
7497

98+
internal void SetSession(RemoteSession session) {
99+
_session = session;
100+
SendTimeoutPageLoad(_session, timeout_pageload);
101+
SendTimeoutScript(_session, timeout_pageload);
102+
}
103+
75104
}
76105

77106
}

Selenium/Core/RemoteSession.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ public void Start(Dictionary desired_capabilities, Dictionary requiredCapabiliti
5959
throw new DeserializeException(typeof(RemoteSession), ex);
6060
}
6161

62-
if (this.timeouts.PageLoad != -1)
63-
Send(RequestMethod.POST, "/timeouts", "type", "page load", "ms", this.timeouts.PageLoad);
64-
65-
if (this.timeouts.Script != -1)
66-
Send(RequestMethod.POST, "/timeouts", "type", "script", "ms", this.timeouts.Script);
62+
this.timeouts.SetSession(this);
6763
}
6864

6965
/// <summary>

0 commit comments

Comments
 (0)