Skip to content

Commit

Permalink
chore: roll to ToT (#1798)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Oct 21, 2021
1 parent ec7c1eb commit f993712
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 17 deletions.
2 changes: 1 addition & 1 deletion playwright
Submodule playwright updated 693 files
2 changes: 1 addition & 1 deletion src/Common/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<AssemblyVersion>1.16.0</AssemblyVersion>
<PackageVersion>$(AssemblyVersion)-next-1</PackageVersion>
<DriverVersion>1.15.2-1633455481000</DriverVersion>
<DriverVersion>1.16.0-next-1634779886000</DriverVersion>
<ReleaseVersion>$(AssemblyVersion)</ReleaseVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<NoDefaultExcludes>true</NoDefaultExcludes>
Expand Down
4 changes: 2 additions & 2 deletions src/Playwright.Tests/ElementHandleConvenienceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public async Task InnerTextShouldThrow()
{
await Page.SetContentAsync("<svg>text</svg>");
var exception1 = Assert.ThrowsAsync<PlaywrightException>(async () => await Page.InnerTextAsync("svg"));
StringAssert.Contains("Not an HTMLElement", exception1.Message);
StringAssert.Contains("Node is not an HTMLElement", exception1.Message);

var handle = await Page.QuerySelectorAsync("svg");
var exception2 = Assert.ThrowsAsync<PlaywrightException>(async () => await handle.InnerTextAsync());
StringAssert.Contains("Not an HTMLElement", exception2.Message);
StringAssert.Contains("Node is not an HTMLElement", exception2.Message);
}

[PlaywrightTest("elementhandle-convenience.spec.ts", "textContent should work")]
Expand Down
8 changes: 4 additions & 4 deletions src/Playwright.Tests/Locator/LocatorConvenienceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public async Task InputValueShouldWork()
Assert.AreEqual("input value", await locator.InputValueAsync());

var e = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(async () => await Page.InputValueAsync("#inner"));
StringAssert.Contains("Node is not an HTMLInputElement or HTMLTextAreaElement or HTMLSelectElement", e.Message);
StringAssert.Contains("Node is not an <input>, <textarea> or <select> element", e.Message);

var locator2 = Page.Locator("#inner");
e = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(async () => await locator2.InputValueAsync());

StringAssert.Contains("Node is not an HTMLInputElement or HTMLTextAreaElement or HTMLSelectElement", e.Message);
StringAssert.Contains("Node is not an <input>, <textarea> or <select> element", e.Message);
}

[PlaywrightTest("locator-convenience.spec.ts", "innerHTML should work")]
Expand All @@ -108,11 +108,11 @@ public async Task InnerTextShouldThrow()
{
await Page.SetContentAsync("<svg>text</svg>");
var e = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(async () => await Page.InnerTextAsync("svg"));
StringAssert.Contains("Not an HTMLElement", e.Message);
StringAssert.Contains("Node is not an HTMLElement", e.Message);

var locator = Page.Locator("svg");
e = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(async () => await locator.InnerTextAsync());
StringAssert.Contains("Not an HTMLElement", e.Message);
StringAssert.Contains("Node is not an HTMLElement", e.Message);
}


Expand Down
21 changes: 21 additions & 0 deletions src/Playwright.Tests/Locator/LocatorMiscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,26 @@ public async Task ShouldReturnBoundingBox()
Assert.AreEqual(50, box.Width);
Assert.AreEqual(50, box.Height);
}

[PlaywrightTest("locator-misc-2.spec.ts", "should waitFor")]
public async Task ShouldWaitFor()
{
await Page.SetContentAsync("<div></div>");
var locator = Page.Locator("span");
var task = locator.WaitForAsync();
await Page.EvalOnSelectorAsync("div", "div => div.innerHTML = '<span>target</span>'");
await task;
Assert.AreEqual("target", await locator.TextContentAsync());
}

[PlaywrightTest("locator-misc-2.spec.ts", "should waitFor hidden")]
public async Task ShouldWaitForHidden()
{
await Page.SetContentAsync("<div><span></span></div>");
var locator = Page.Locator("span");
var task = locator.WaitForAsync(new() { State = WaitForSelectorState.Hidden });
await Page.EvalOnSelectorAsync("div", "div => div.innerHTML = ''");
await task;
}
}
}
2 changes: 1 addition & 1 deletion src/Playwright.Tests/PageSelectOptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public async Task ShouldThrowWhenElementIsNotASelect()
{
await Page.GotoAsync(Server.Prefix + "/input/select.html");
var exception = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(() => Page.SelectOptionAsync("body", string.Empty));
StringAssert.Contains("Element is not a <select> element.", exception.Message);
StringAssert.Contains("Element is not a <select> element", exception.Message);
}

[PlaywrightTest("page-select-option.spec.ts", "should return [] on no matched values")]
Expand Down
2 changes: 1 addition & 1 deletion src/Playwright/API/Generated/IBrowserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Microsoft.Playwright
/// belong to the parent page's browser context.
/// </para>
/// <para>
/// Playwright allows creation of "incognito" browser contexts with <c>browser.newContext()</c>
/// Playwright allows creating "incognito" browser contexts with <see cref="IBrowser.NewContextAsync"/>
/// method. "Incognito" browser contexts don't write any browsing data to disk.
/// </para>
/// <code>
Expand Down
18 changes: 18 additions & 0 deletions src/Playwright/API/Generated/ILocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,24 @@ public partial interface ILocator
/// </summary>
/// <param name="options">Call options</param>
Task UncheckAsync(LocatorUncheckOptions? options = default);

/// <summary>
/// <para>
/// Returns when element specified by locator satisfies the <paramref name="state"/>
/// option.
/// </para>
/// <para>
/// If target element already satisfies the condition, the method returns immediately.
/// Otherwise, waits for up to <paramref name="timeout"/> milliseconds until the condition
/// is met.
/// </para>
/// <code>
/// var orderSent = page.Locator("#order-sent");<br/>
/// orderSent.WaitForAsync();
/// </code>
/// </summary>
/// <param name="options">Call options</param>
Task WaitForAsync(LocatorWaitForOptions? options = default);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Playwright/API/Generated/IPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,9 @@ public partial interface IPage
/// <para>
/// <c>page.setViewportSize</c> will resize the page. A lot of websites don't expect
/// phones to change size, so you should set the viewport size before navigating to
/// the page.
/// the page. <see cref="IPage.SetViewportSizeAsync"/> will also reset <c>screen</c>
/// size, use <see cref="IBrowser.NewContextAsync"/> with <c>screen</c> and <c>viewport</c>
/// parameters if you need better control of these properties.
/// </para>
/// <code>
/// var page = await browser.NewPageAsync();<br/>
Expand Down
2 changes: 1 addition & 1 deletion src/Playwright/API/Generated/IPlaywright.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public partial interface IPlaywright
/// {<br/>
/// using var playwright = await Playwright.CreateAsync();<br/>
/// await using var browser = await playwright.Webkit.LaunchAsync();<br/>
/// await using var context = await browser.NewContextAsync(Playwright.Devices["iPhone 6"]);<br/>
/// await using var context = await browser.NewContextAsync(playwright.Devices["iPhone 6"]);<br/>
/// <br/>
/// var page = await context.NewPageAsync();<br/>
/// await page.GotoAsync("https://www.theverge.com");<br/>
Expand Down
85 changes: 85 additions & 0 deletions src/Playwright/API/Generated/Options/LocatorWaitForOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* MIT License
*
* Copyright (c) Microsoft Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

#nullable enable

namespace Microsoft.Playwright
{
public class LocatorWaitForOptions
{
public LocatorWaitForOptions() { }

public LocatorWaitForOptions(LocatorWaitForOptions clone)
{
if (clone == null) return;
State = clone.State;
Timeout = clone.Timeout;
}

/// <summary>
/// <para>Defaults to <c>'visible'</c>. Can be either:</para>
/// <list type="bullet">
/// <item><description><c>'attached'</c> - wait for element to be present in DOM.</description></item>
/// <item><description><c>'detached'</c> - wait for element to not be present in DOM.</description></item>
/// <item><description>
/// <c>'visible'</c> - wait for element to have non-empty bounding box and no <c>visibility:hidden</c>.
/// Note that element without any content or with <c>display:none</c> has an empty bounding
/// box and is not considered visible.
/// </description></item>
/// <item><description>
/// <c>'hidden'</c> - wait for element to be either detached from DOM, or have an empty
/// bounding box or <c>visibility:hidden</c>. This is opposite to the <c>'visible'</c>
/// option.
/// </description></item>
/// </list>
/// </summary>
[JsonPropertyName("state")]
public WaitForSelectorState? State { get; set; }

/// <summary>
/// <para>
/// Maximum time in milliseconds, defaults to 30 seconds, pass <c>0</c> to disable timeout.
/// The default value can be changed by using the <see cref="IBrowserContext.SetDefaultTimeout"/>
/// or <see cref="IPage.SetDefaultTimeout"/> methods.
/// </para>
/// </summary>
[JsonPropertyName("timeout")]
public float? Timeout { get; set; }
}
}

#nullable disable
2 changes: 1 addition & 1 deletion src/Playwright/API/Generated/Types/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public partial class Proxy

/// <summary>
/// <para>
/// Optional coma-separated domains to bypass proxy, for example <c>".com, chromium.org,
/// Optional comma-separated domains to bypass proxy, for example <c>".com, chromium.org,
/// .domain.com"</c>.
/// </para>
/// </summary>
Expand Down
14 changes: 12 additions & 2 deletions src/Playwright/Core/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public async Task<IElementHandle> FrameElementAsync()

public Task<string> TitleAsync() => _channel.TitleAsync();

public Task WaitForTimeoutAsync(float timeout) => Task.Delay(Convert.ToInt32(timeout));
public Task WaitForTimeoutAsync(float timeout)
=> _channel.WaitForTimeoutAsync(timeout);

public Task<IReadOnlyList<string>> SelectOptionAsync(string selector, string values, FrameSelectOptionOptions options = default)
=> SelectOptionAsync(selector, new[] { values }, options);
Expand Down Expand Up @@ -443,7 +444,16 @@ public async Task<IElementHandle> WaitForSelectorAsync(string selector, FrameWai
selector: selector,
state: options?.State,
timeout: options?.Timeout,
strict: options?.Strict).ConfigureAwait(false))?.Object;
strict: options?.Strict,
omitReturnValue: false).ConfigureAwait(false))?.Object;

public async Task<IElementHandle> LocatorWaitForAsync(string selector, LocatorWaitForOptions options = default)
=> (await _channel.WaitForSelectorAsync(
selector: selector,
state: options?.State,
timeout: options?.Timeout,
strict: true,
omitReturnValue: true).ConfigureAwait(false))?.Object;

public async Task<IJSHandle> EvaluateHandleAsync(string script, object args = null)
=> (await _channel.EvaluateExpressionHandleAsync(
Expand Down
3 changes: 3 additions & 0 deletions src/Playwright/Core/Locator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ public Task UncheckAsync(LocatorUncheckOptions options = null)
ILocator ILocator.Locator(string selector)
=> new Locator(_frame, $"{_selector} >> {selector}");

public Task WaitForAsync(LocatorWaitForOptions options = null)
=> _frame.LocatorWaitForAsync(_selector, ConvertOptions<LocatorWaitForOptions>(options));

public override string ToString() => "Locator@" + _selector;

private T ConvertOptions<T>(object incoming, Action<T> configure = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Playwright/Core/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public Task<IReadOnlyList<string>> SelectOptionAsync(string selector, IEnumerabl
Strict = options?.Strict,
});

public Task WaitForTimeoutAsync(float timeout) => Task.Delay(Convert.ToInt32(timeout));
public Task WaitForTimeoutAsync(float timeout) => MainFrame.WaitForTimeoutAsync(timeout);

public Task<IElementHandle> WaitForSelectorAsync(string selector, PageWaitForSelectorOptions options = default)
=> MainFrame.WaitForSelectorAsync(selector, new()
Expand Down
15 changes: 14 additions & 1 deletion src/Playwright/Transport/Channels/FrameChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,34 @@ internal Task<JSHandleChannel> WaitForFunctionAsync(
internal async Task<string> TitleAsync()
=> (await Connection.SendMessageToServerAsync(Guid, "title", null).ConfigureAwait(false))?.GetProperty("value").ToString();

internal Task<ElementHandleChannel> WaitForSelectorAsync(string selector, WaitForSelectorState? state, float? timeout, bool? strict)
internal Task<ElementHandleChannel> WaitForSelectorAsync(string selector, WaitForSelectorState? state, float? timeout, bool? strict, bool? omitReturnValue)
{
var args = new Dictionary<string, object>
{
["selector"] = selector,
["timeout"] = timeout,
["state"] = state,
["strict"] = strict,
["omitReturnValue"] = omitReturnValue,
};
return Connection.SendMessageToServerAsync<ElementHandleChannel>(
Guid,
"waitForSelector",
args);
}

internal Task WaitForTimeoutAsync(float timeout)
{
var args = new Dictionary<string, object>
{
["timeout"] = timeout,
};
return Connection.SendMessageToServerAsync<ElementHandleChannel>(
Guid,
"waitForTimeout",
args);
}

internal Task<ElementHandleChannel> AddScriptTagAsync(string url, string path, string content, string type)
{
var args = new Dictionary<string, object>
Expand Down

0 comments on commit f993712

Please sign in to comment.