Skip to content

Commit

Permalink
fix(locators): Style attribute in ScreenshotAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed May 1, 2024
1 parent c14ebe5 commit b786d35
Show file tree
Hide file tree
Showing 5 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 });
Assert.True(ScreenshotHelper.PixelMatch("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;
}",
});
Assert.True(ScreenshotHelper.PixelMatch("grid-cell-5-red.png", screenshot));
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 b786d35

Please sign in to comment.