Skip to content

Commit

Permalink
Fix WaitFor Timeout defaults (#1300)
Browse files Browse the repository at this point in the history
* Fix WaitForOptions.Timeout type and default

* Fix on WaitForSelectorOptions
  • Loading branch information
kblok committed Oct 8, 2019
1 parent b901c22 commit 666f07c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 deletions lib/PuppeteerSharp/DOMWorld.cs
Expand Up @@ -145,12 +145,14 @@ internal async Task SetContentAsync(string html, NavigationOptions options = nul
document.close();
}", html).ConfigureAwait(false);

var watcher = new LifecycleWatcher(_frameManager, Frame, waitUntil, timeout);
var watcherTask = await Task.WhenAny(
watcher.TimeoutOrTerminationTask,
watcher.LifecycleTask).ConfigureAwait(false);
using (var watcher = new LifecycleWatcher(_frameManager, Frame, waitUntil, timeout))
{
var watcherTask = await Task.WhenAny(
watcher.TimeoutOrTerminationTask,
watcher.LifecycleTask).ConfigureAwait(false);

await watcherTask.ConfigureAwait(false);
await watcherTask.ConfigureAwait(false);
}
}

internal async Task<ElementHandle> AddScriptTagAsync(AddTagOptions options)
Expand Down Expand Up @@ -384,6 +386,8 @@ private async Task<ElementHandle> GetDocument()
private async Task<ElementHandle> WaitForSelectorOrXPathAsync(string selectorOrXPath, bool isXPath, WaitForSelectorOptions options = null)
{
options = options ?? new WaitForSelectorOptions();
var timeout = options.Timeout ?? _timeoutSettings.Timeout;

const string predicate = @"
function predicate(selectorOrXPath, isXPath, waitForVisible, waitForHidden) {
const node = isXPath
Expand Down Expand Up @@ -413,7 +417,7 @@ private async Task<ElementHandle> WaitForSelectorOrXPathAsync(string selectorOrX
$"{(isXPath ? "XPath" : "selector")} '{selectorOrXPath}'{(options.Hidden ? " to be hidden" : "")}",
polling,
null,
options.Timeout,
timeout,
new object[]
{
selectorOrXPath,
Expand Down
4 changes: 2 additions & 2 deletions lib/PuppeteerSharp/WaitForOptions.cs
Expand Up @@ -12,9 +12,9 @@ namespace PuppeteerSharp
public class WaitForOptions
{
/// <summary>
/// Maximum time to wait for in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.
/// Maximum time to wait for in milliseconds. Pass 0 to disable timeout.
/// The default value can be changed by setting the <see cref="Page.DefaultTimeout"/> property.
/// </summary>
public int Timeout { get; set; } = Puppeteer.DefaultTimeout;
public int? Timeout { get; set; }
}
}
4 changes: 2 additions & 2 deletions lib/PuppeteerSharp/WaitForSelectorOptions.cs
Expand Up @@ -8,9 +8,9 @@
public class WaitForSelectorOptions
{
/// <summary>
/// Maximum time to wait for in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.
/// Maximum time to wait for in milliseconds. Pass 0 to disable timeout.
/// </summary>
public int Timeout { get; set; } = Puppeteer.DefaultTimeout;
public int? Timeout { get; set; }

/// <summary>
/// Wait for selector to become visible.
Expand Down

0 comments on commit 666f07c

Please sign in to comment.