Skip to content

Commit

Permalink
fix(locators): Style attribute in ScreenshotAsync (#2926)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed May 1, 2024
1 parent 9ef9165 commit 3edc14f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Playwright.Tests/ElementHandleScreenshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,19 @@ public async Task PathOptionShouldCreateSubdirectories()
await elementHandle.ScreenshotAsync(new() { Path = outputPath });
PlaywrightAssert.ToMatchSnapshot("screenshot-element-bounding-box.png", outputPath);
}

[PlaywrightTest("locator-screenshot.spec.ts", "should hide elements based on attr")]
public async Task ShouldHideElementsBasedOnAttr()
{
await Page.GotoAsync(Server.Prefix + "/grid.html");
var locator = Page.Locator("div").Nth(5);
await locator.EvaluateAsync("element => element.setAttribute('data-test-screenshot', 'red-background')");
var screenshot = await locator.ScreenshotAsync(new()
{
Style = @"[data-test-screenshot=""red-background""] {
background-color: red !important;
}",
});
PlaywrightAssert.ToMatchSnapshot("grid-cell-5-red.png", screenshot);
}
}
1 change: 1 addition & 0 deletions src/Playwright/Core/ElementHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public async Task<byte[]> ScreenshotAsync(ElementHandleScreenshotOptions options
["scale"] = options.Scale,
["quality"] = options.Quality,
["maskColor"] = options.MaskColor,
["style"] = options.Style,
};
if (options.Mask != null)
{
Expand Down

0 comments on commit 3edc14f

Please sign in to comment.