From 3edc14fc3edab78f8dc16053a7c7d9cf6d90247d Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 1 May 2024 20:23:26 +0000 Subject: [PATCH] fix(locators): Style attribute in ScreenshotAsync (#2926) --- .../ElementHandleScreenshotTests.cs | 15 +++++++++++++++ src/Playwright/Core/ElementHandle.cs | 1 + 2 files changed, 16 insertions(+) diff --git a/src/Playwright.Tests/ElementHandleScreenshotTests.cs b/src/Playwright.Tests/ElementHandleScreenshotTests.cs index 390ffd409..1573de91c 100644 --- a/src/Playwright.Tests/ElementHandleScreenshotTests.cs +++ b/src/Playwright.Tests/ElementHandleScreenshotTests.cs @@ -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); + } } diff --git a/src/Playwright/Core/ElementHandle.cs b/src/Playwright/Core/ElementHandle.cs index 37ea99e44..e71a76806 100644 --- a/src/Playwright/Core/ElementHandle.cs +++ b/src/Playwright/Core/ElementHandle.cs @@ -105,6 +105,7 @@ public async Task ScreenshotAsync(ElementHandleScreenshotOptions options ["scale"] = options.Scale, ["quality"] = options.Quality, ["maskColor"] = options.MaskColor, + ["style"] = options.Style, }; if (options.Mask != null) {