Skip to content

Commit fa68af7

Browse files
committed
Updating .NET tests to no longer use obsolete Timeout methods
1 parent e4c0a4d commit fa68af7

File tree

7 files changed

+76
-28
lines changed

7 files changed

+76
-28
lines changed

dotnet/src/support/Events/EventFiringWebDriver.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,52 @@ public EventFiringTimeouts(IOptions options)
10941094
this.wrappedTimeouts = options.Timeouts();
10951095
}
10961096

1097+
/// <summary>
1098+
/// Gets or sets the implicit wait timeout, which is the amount of time the
1099+
/// driver should wait when searching for an element if it is not immediately
1100+
/// present.
1101+
/// </summary>
1102+
/// <remarks>
1103+
/// When searching for a single element, the driver should poll the page
1104+
/// until the element has been found, or this timeout expires before throwing
1105+
/// a <see cref="NoSuchElementException"/>. When searching for multiple elements,
1106+
/// the driver should poll the page until at least one element has been found
1107+
/// or this timeout has expired.
1108+
/// <para>
1109+
/// Increasing the implicit wait timeout should be used judiciously as it
1110+
/// will have an adverse effect on test run time, especially when used with
1111+
/// slower location strategies like XPath.
1112+
/// </para>
1113+
/// </remarks>
1114+
public TimeSpan ImplicitWait
1115+
{
1116+
get { return this.wrappedTimeouts.ImplicitWait; }
1117+
set { this.wrappedTimeouts.ImplicitWait = value; }
1118+
}
1119+
1120+
/// <summary>
1121+
/// Gets or sets the asynchronous script timeout, which is the amount
1122+
/// of time the driver should wait when executing JavaScript asynchronously.
1123+
/// This timeout only affects the <see cref="IJavaScriptExecutor.ExecuteAsyncScript(string, object[])"/>
1124+
/// method.
1125+
/// </summary>
1126+
public TimeSpan AsynchronousJavaScript
1127+
{
1128+
get { return this.wrappedTimeouts.AsynchronousJavaScript; }
1129+
set { this.wrappedTimeouts.AsynchronousJavaScript = value; }
1130+
}
1131+
1132+
/// <summary>
1133+
/// Gets or sets the page load timeout, which is the amount of time the driver
1134+
/// should wait for a page to load when setting the <see cref="IWebDriver.Url"/>
1135+
/// property.
1136+
/// </summary>
1137+
public TimeSpan PageLoad
1138+
{
1139+
get { return this.wrappedTimeouts.PageLoad; }
1140+
set { this.wrappedTimeouts.PageLoad = value; }
1141+
}
1142+
10971143
/// <summary>
10981144
/// Specifies the amount of time the driver should wait when searching for an
10991145
/// element if it is not immediately present.
@@ -1112,6 +1158,7 @@ public EventFiringTimeouts(IOptions options)
11121158
/// slower location strategies like XPath.
11131159
/// </para>
11141160
/// </remarks>
1161+
[Obsolete("This method will be removed in a future version. Please set the ImplicitWait property instead.")]
11151162
public ITimeouts ImplicitlyWait(TimeSpan timeToWait)
11161163
{
11171164
return this.wrappedTimeouts.ImplicitlyWait(timeToWait);
@@ -1122,6 +1169,7 @@ public ITimeouts ImplicitlyWait(TimeSpan timeToWait)
11221169
/// </summary>
11231170
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.</param>
11241171
/// <returns>A self reference</returns>
1172+
[Obsolete("This method will be removed in a future version. Please set the AsynchronousJavaScript property instead.")]
11251173
public ITimeouts SetScriptTimeout(TimeSpan timeToWait)
11261174
{
11271175
return this.wrappedTimeouts.SetScriptTimeout(timeToWait);
@@ -1132,6 +1180,7 @@ public ITimeouts SetScriptTimeout(TimeSpan timeToWait)
11321180
/// </summary>
11331181
/// <param name="timeToWait">A <see cref="TimeSpan"/> structure defining the amount of time to wait.</param>
11341182
/// <returns>A self reference</returns>
1183+
[Obsolete("This method will be removed in a future version. Please set the PageLoad property instead.")]
11351184
public ITimeouts SetPageLoadTimeout(TimeSpan timeToWait)
11361185
{
11371186
this.wrappedTimeouts.SetPageLoadTimeout(timeToWait);

dotnet/test/common/CorrectEventFiringTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,10 @@ public void ShouldReportTheXAndYCoordinatesWhenClicking()
361361
IWebElement element = driver.FindElement(By.Id("eventish"));
362362
element.Click();
363363

364-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));
364+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2);
365365
string clientX = driver.FindElement(By.Id("clientX")).Text;
366366
string clientY = driver.FindElement(By.Id("clientY")).Text;
367-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(0));
367+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0);
368368

369369
Assert.AreNotEqual("0", clientX);
370370
Assert.AreNotEqual("0", clientY);

dotnet/test/common/ExecutingAsyncJavascriptTest.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void SetUpEnvironment()
1818
executor = (IJavaScriptExecutor)driver;
1919
}
2020

21-
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromMilliseconds(0));
21+
driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromMilliseconds(0);
2222
}
2323

2424
[Test]
@@ -142,7 +142,7 @@ public void ShouldNotTimeoutIfScriptCallsbackInsideAZeroTimeout()
142142
[Test]
143143
public void ShouldTimeoutIfScriptDoesNotInvokeCallbackWithLongTimeout()
144144
{
145-
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromMilliseconds(500));
145+
driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromMilliseconds(500);
146146
driver.Url = ajaxyPage;
147147
Assert.Throws<WebDriverTimeoutException>(() => executor.ExecuteAsyncScript(
148148
"var callback = arguments[arguments.length - 1];" +
@@ -153,7 +153,7 @@ public void ShouldTimeoutIfScriptDoesNotInvokeCallbackWithLongTimeout()
153153
public void ShouldDetectPageLoadsWhileWaitingOnAnAsyncScriptAndReturnAnError()
154154
{
155155
driver.Url = ajaxyPage;
156-
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromMilliseconds(100));
156+
driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromMilliseconds(100);
157157
Assert.Throws<InvalidOperationException>(() => executor.ExecuteAsyncScript("window.location = '" + dynamicPage + "';"));
158158
}
159159

@@ -178,7 +178,7 @@ public void ShouldBeAbleToExecuteAsynchronousScripts()
178178

179179
Assert.AreEqual(1, GetNumberOfDivElements(), "There should only be 1 DIV at this point, which is used for the butter message");
180180

181-
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10));
181+
driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(10);
182182
string text = (string)executor.ExecuteAsyncScript(
183183
"var callback = arguments[arguments.length - 1];"
184184
+ "window.registerListener(arguments[arguments.length - 1]);");
@@ -223,7 +223,7 @@ public void ShouldBeAbleToMakeXMLHttpRequestsAndWaitForTheResponse()
223223
"xhr.send();";
224224

225225
driver.Url = ajaxyPage;
226-
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(3));
226+
driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(3);
227227
string response = (string)executor.ExecuteAsyncScript(script, sleepingPage + "?time=2");
228228
Assert.AreEqual("<html><head><title>Done</title></head><body>Slept for 2s</body></html>", response.Trim());
229229
}
@@ -239,7 +239,7 @@ public void ShouldBeAbleToMakeXMLHttpRequestsAndWaitForTheResponse()
239239
public void ThrowsIfScriptTriggersAlert()
240240
{
241241
driver.Url = simpleTestPage;
242-
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(5));
242+
driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(5);
243243
try
244244
{
245245
((IJavaScriptExecutor)driver).ExecuteAsyncScript(
@@ -266,7 +266,7 @@ public void ThrowsIfScriptTriggersAlert()
266266
public void ThrowsIfAlertHappensDuringScript()
267267
{
268268
driver.Url = slowLoadingAlertPage;
269-
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(5));
269+
driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(5);
270270
try
271271
{
272272
((IJavaScriptExecutor)driver).ExecuteAsyncScript("setTimeout(arguments[0], 1000);");
@@ -292,7 +292,7 @@ public void ThrowsIfAlertHappensDuringScript()
292292
public void ThrowsIfScriptTriggersAlertWhichTimesOut()
293293
{
294294
driver.Url = simpleTestPage;
295-
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(5));
295+
driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(5);
296296
try
297297
{
298298
((IJavaScriptExecutor)driver)
@@ -318,7 +318,7 @@ public void ThrowsIfScriptTriggersAlertWhichTimesOut()
318318
public void ThrowsIfAlertHappensDuringScriptWhichTimesOut()
319319
{
320320
driver.Url = slowLoadingAlertPage;
321-
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(5));
321+
driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(5);
322322
try
323323
{
324324
((IJavaScriptExecutor)driver).ExecuteAsyncScript("");
@@ -343,7 +343,7 @@ public void ThrowsIfAlertHappensDuringScriptWhichTimesOut()
343343
[IgnoreBrowser(Browser.Safari, "Does not handle async alerts")]
344344
public void IncludesAlertTextInUnhandledAlertException()
345345
{
346-
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(5));
346+
driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(5);
347347
string alertText = "Look! An alert!";
348348
try
349349
{

dotnet/test/common/FrameSwitchingTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public void ShouldAlwaysFocusOnTheTopMostFrameAfterANavigationEvent()
2525
public void ShouldNotAutomaticallySwitchFocusToAnIFrameWhenAPageContainingThemIsLoaded()
2626
{
2727
driver.Url = iframePage;
28-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1));
28+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1);
2929
IWebElement element = driver.FindElement(By.Id("iframe_page_heading"));
30-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(0));
30+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0);
3131
Assert.IsNotNull(element);
3232
}
3333

dotnet/test/common/HTML5/AppCacheTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ public class AppCacheTest : DriverTestFixture
88
{
99
[Test]
1010
[IgnoreBrowser(Browser.Android, "Untested feature")]
11-
// [IgnoreBrowser(Browser.Chrome, "Not implemented")]
1211
public void TestAppCacheStatus()
1312
{
1413
driver.Url = html5Page;
15-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(2000));
14+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(2000);
1615
IHasApplicationCache hasAppCacheDriver = driver as IHasApplicationCache;
1716
if (hasAppCacheDriver == null || !hasAppCacheDriver.HasApplicationCache)
1817
{

dotnet/test/common/ImplicitWaitTest.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class ImplicitWaitTest : DriverTestFixture
1010
[TearDown]
1111
public void ResetImplicitWaitTimeout()
1212
{
13-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(0));
13+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(0);
1414
}
1515

1616
[Test]
@@ -20,7 +20,7 @@ public void ShouldImplicitlyWaitForASingleElement()
2020
driver.Url = dynamicPage;
2121
IWebElement add = driver.FindElement(By.Id("adder"));
2222

23-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(3000));
23+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(3000);
2424

2525
add.Click();
2626
driver.FindElement(By.Id("box0")); // All is well if this doesn't throw.
@@ -31,7 +31,7 @@ public void ShouldImplicitlyWaitForASingleElement()
3131
public void ShouldStillFailToFindAnElementWhenImplicitWaitsAreEnabled()
3232
{
3333
driver.Url = dynamicPage;
34-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(500));
34+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500);
3535
Assert.Throws<NoSuchElementException>(() => driver.FindElement(By.Id("box0")));
3636
}
3737

@@ -41,8 +41,8 @@ public void ShouldStillFailToFindAnElementWhenImplicitWaitsAreEnabled()
4141
public void ShouldReturnAfterFirstAttemptToFindOneAfterDisablingImplicitWaits()
4242
{
4343
driver.Url = dynamicPage;
44-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(3000));
45-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(0));
44+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(3000);
45+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(0);
4646
Assert.Throws<NoSuchElementException>(() => driver.FindElement(By.Id("box0")));
4747
}
4848

@@ -54,7 +54,7 @@ public void ShouldImplicitlyWaitUntilAtLeastOneElementIsFoundWhenSearchingForMan
5454
driver.Url = dynamicPage;
5555
IWebElement add = driver.FindElement(By.Id("adder"));
5656

57-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(2000));
57+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(2000);
5858
add.Click();
5959
add.Click();
6060

@@ -69,7 +69,7 @@ public void ShouldStillFailToFindAnElemenstWhenImplicitWaitsAreEnabled()
6969
{
7070
driver.Url = dynamicPage;
7171

72-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(500));
72+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500);
7373
ReadOnlyCollection<IWebElement> elements = driver.FindElements(By.ClassName("redbox"));
7474
Assert.AreEqual(0, elements.Count);
7575
}
@@ -81,8 +81,8 @@ public void ShouldReturnAfterFirstAttemptToFindManyAfterDisablingImplicitWaits()
8181
{
8282
driver.Url = dynamicPage;
8383
IWebElement add = driver.FindElement(By.Id("adder"));
84-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(1100));
85-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(0));
84+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(1100);
85+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(0);
8686
add.Click();
8787
ReadOnlyCollection<IWebElement> elements = driver.FindElements(By.ClassName("redbox"));
8888
Assert.AreEqual(0, elements.Count);
@@ -100,7 +100,7 @@ public void ShouldImplicitlyWaitForAnElementToBeVisibleBeforeInteracting()
100100

101101
IWebElement reveal = driver.FindElement(By.Id("reveal"));
102102
IWebElement revealed = driver.FindElement(By.Id("revealed"));
103-
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(5000));
103+
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(5000);
104104

105105
Assert.IsFalse(revealed.Displayed, "revealed should not be visible");
106106
reveal.Click();

dotnet/test/common/PageLoadingTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public void ShouldTimeoutIfAPageTakesTooLongToLoad()
240240
Assert.Ignore("Driver does not return control from timeout wait when executed via Marionette");
241241
}
242242

243-
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(2));
243+
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(2);
244244

245245
try
246246
{
@@ -256,7 +256,7 @@ public void ShouldTimeoutIfAPageTakesTooLongToLoad()
256256
}
257257
finally
258258
{
259-
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.MinValue);
259+
driver.Manage().Timeouts().PageLoad = TimeSpan.MinValue;
260260
}
261261
}
262262

0 commit comments

Comments
 (0)