Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Playwright.Tests/PageAriaSnapshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,39 @@ namespace Microsoft.Playwright.Tests;

public class PageAriaSnapshotTests : PageTestEx
{
[PlaywrightTest]
[TestCase(AriaSnapshotMode.Default)]
[TestCase(AriaSnapshotMode.Ai)]
public async Task ShouldIncludeBoundingBoxesInPageSnapshot(AriaSnapshotMode mode)
{
await Page.SetContentAsync("<button style='position: absolute; left: 20px; top: 30px; width: 100px; height: 40px'>Submit</button>");

var snapshot = await Page.AriaSnapshotAsync(new() { Mode = mode });
StringAssert.DoesNotContain("[box=", snapshot);
Assert.AreEqual(snapshot, await Page.AriaSnapshotAsync(new() { Mode = mode, Boxes = false }));

var snapshotWithBoxes = await Page.AriaSnapshotAsync(new() { Mode = mode, Boxes = true });
StringAssert.Contains("[box=20,30,100,40]", snapshotWithBoxes);
Assert.AreEqual(snapshot, await Page.AriaSnapshotAsync(new() { Mode = mode }));
}

[PlaywrightTest]
[TestCase(AriaSnapshotMode.Default)]
[TestCase(AriaSnapshotMode.Ai)]
public async Task ShouldIncludeBoundingBoxesInLocatorSnapshot(AriaSnapshotMode mode)
{
await Page.SetContentAsync("<button style='position: absolute; left: 20px; top: 30px; width: 100px; height: 40px'>Submit</button>");
var locator = Page.GetByRole(AriaRole.Button);

var snapshot = await locator.AriaSnapshotAsync(new() { Mode = mode });
StringAssert.DoesNotContain("[box=", snapshot);
Assert.AreEqual(snapshot, await locator.AriaSnapshotAsync(new() { Mode = mode, Boxes = false }));

var snapshotWithBoxes = await locator.AriaSnapshotAsync(new() { Mode = mode, Boxes = true });
StringAssert.Contains("[box=20,30,100,40]", snapshotWithBoxes);
Assert.AreEqual(snapshot, await locator.AriaSnapshotAsync(new() { Mode = mode }));
}

private string _unshift(string snapshot)
{
var lines = snapshot.Split('\n');
Expand Down
1 change: 1 addition & 0 deletions src/Playwright/Core/Locator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ public async Task<string> AriaSnapshotAsync(LocatorAriaSnapshotOptions? options
["selector"] = _selector,
["mode"] = options?.Mode,
["depth"] = options?.Depth,
["boxes"] = options?.Boxes,
},
timeout: _frame.Timeout(options?.Timeout)).ConfigureAwait(false);
return result!.Value.GetProperty("snapshot").ToString();
Expand Down
1 change: 1 addition & 0 deletions src/Playwright/Core/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,7 @@ public async Task<string> AriaSnapshotAsync(PageAriaSnapshotOptions? options = d
{
["mode"] = options?.Mode,
["depth"] = options?.Depth,
["boxes"] = options?.Boxes,
},
timeout: MainFrame.Timeout(options?.Timeout)).ConfigureAwait(false);
return result!.Value.GetProperty("snapshot").ToString();
Expand Down
36 changes: 18 additions & 18 deletions src/tools/Playwright.Tooling/DriverDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ private static async Task WithRetriesAsync(string url, Func<Task> action)
}
}

private static string ResolveNpmExecutable()
{
string name = OperatingSystem.IsWindows() ? "npm.cmd" : "npm";
// On Windows npm.cmd must be started by its full path: launched by bare name,
// the script's %~dp0 expands to the working directory instead of its own
// directory and it fails to find node_modules/npm/bin/npm-cli.js.
string path = Environment.GetEnvironmentVariable("PATH") ?? string.Empty;
foreach (string directory in path.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries))
{
string candidate = Path.Combine(directory.Trim('"'), name);
if (File.Exists(candidate))
{
return candidate;
}
}
return name;
}

private async Task<bool> ExecuteAsync()
{
var driversDirectory = new DirectoryInfo(Path.Combine(BasePath, "src", "Playwright", ".drivers"));
Expand Down Expand Up @@ -186,24 +204,6 @@ private async Task<bool> ExecuteAsync()
return true;
}

private static string ResolveNpmExecutable()
{
string name = OperatingSystem.IsWindows() ? "npm.cmd" : "npm";
// On Windows npm.cmd must be started by its full path: launched by bare name,
// the script's %~dp0 expands to the working directory instead of its own
// directory and it fails to find node_modules/npm/bin/npm-cli.js.
string path = Environment.GetEnvironmentVariable("PATH") ?? string.Empty;
foreach (string directory in path.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries))
{
string candidate = Path.Combine(directory.Trim('"'), name);
if (File.Exists(candidate))
{
return candidate;
}
}
return name;
}

private async Task DownloadPlaywrightPackageAsync(string driversDirectory)
{
// Fetched with `npm pack` rather than a hard-coded registry URL so that the
Expand Down
Loading