@@ -69,8 +69,8 @@ static private void rafraf(Page page) {
69
69
// Do a double raf since single raf does not
70
70
// actually guarantee a new animation frame.
71
71
page .evaluate ("() => new Promise(x => {\n " +
72
- " requestAnimationFrame(() => requestAnimationFrame(x));\n " +
73
- " })" );
72
+ " requestAnimationFrame(() => requestAnimationFrame(x));\n " +
73
+ " })" );
74
74
}
75
75
76
76
@ Test
@@ -136,7 +136,7 @@ void shouldNotCaptureInfiniteWebAnimations() {
136
136
}
137
137
138
138
@ Test
139
- void maskShouldWork () {
139
+ void maskShouldWorkForPage () {
140
140
page .setViewportSize (500 , 500 );
141
141
page .navigate (server .PREFIX + "/grid.html" );
142
142
byte [] screenshot = page .screenshot (new Page .ScreenshotOptions ()
@@ -146,6 +146,17 @@ void maskShouldWork() {
146
146
assertThrows (AssertionFailedError .class , () -> assertArrayEquals (screenshot , originalScreenshot ));
147
147
}
148
148
149
+ @ Test
150
+ void maskShouldWorkForLocator () {
151
+ page .navigate (server .PREFIX + "/grid.html" );
152
+ Locator locatorToScreenshot = page .locator ("div" ).first ();
153
+ byte [] screenshot = locatorToScreenshot .screenshot (new Locator .ScreenshotOptions ()
154
+ .setMask (asList (page .locator ("img" ))));
155
+ // TODO: toMatchSnapshot is not present in java, so we only checks that masked screenshot is different.
156
+ byte [] originalScreenshot = locatorToScreenshot .screenshot ();
157
+ assertThrows (AssertionFailedError .class , () -> assertArrayEquals (screenshot , originalScreenshot ));
158
+ }
159
+
149
160
@ Test
150
161
void shouldWorkWithDeviceScaleFactorAndClip () {
151
162
try (BrowserContext context = browser .newContext (new Browser .NewContextOptions ()
@@ -186,16 +197,16 @@ void shouldWorkWithDeviceScaleFactorAndScaleDevice() {
186
197
@ Test
187
198
void shouldNotCaptureBlinkingCaretByDefault () {
188
199
page .setContent ("<!-- Refer to stylesheet from other origin. Accessing this\n " +
189
- " stylesheet rules will throw.\n " +
190
- " -->\n " +
191
- " <link rel=stylesheet href=\" " + server .CROSS_PROCESS_PREFIX + "/injectedstyle.css\" >\n " +
192
- " <!-- make life harder: define caret color in stylesheet -->\n " +
193
- " <style>\n " +
194
- " div {\n " +
195
- " caret-color: #000 !important;\n " +
196
- " }\n " +
197
- " </style>\n " +
198
- " <div contenteditable=\" true\" ></div>\n " );
200
+ " stylesheet rules will throw.\n " +
201
+ " -->\n " +
202
+ " <link rel=stylesheet href=\" " + server .CROSS_PROCESS_PREFIX + "/injectedstyle.css\" >\n " +
203
+ " <!-- make life harder: define caret color in stylesheet -->\n " +
204
+ " <style>\n " +
205
+ " div {\n " +
206
+ " caret-color: #000 !important;\n " +
207
+ " }\n " +
208
+ " </style>\n " +
209
+ " <div contenteditable=\" true\" ></div>\n " );
199
210
Locator div = page .locator ("div" );
200
211
div .type ("foo bar" );
201
212
byte [] screenshot = div .screenshot ();
@@ -210,19 +221,19 @@ void shouldNotCaptureBlinkingCaretByDefault() {
210
221
}
211
222
212
223
@ Test
213
- @ DisabledIf (value = "com.microsoft.playwright.TestBase#isFirefox" , disabledReason = "fixme" )
224
+ @ DisabledIf (value = "com.microsoft.playwright.TestBase#isFirefox" , disabledReason = "fixme" )
214
225
void shouldCaptureBlinkingCaretIfExplicitlyAskedFor () {
215
226
page .setContent (" <!-- Refer to stylesheet from other origin. Accessing this\n " +
216
- " stylesheet rules will throw.\n " +
217
- " -->\n " +
218
- " <link rel=stylesheet href=\" " + server .CROSS_PROCESS_PREFIX + "/injectedstyle.css'}\" >\n " +
219
- " <!-- make life harder: define caret color in stylesheet -->\n " +
220
- " <style>\n " +
221
- " div {\n " +
222
- " caret-color: #000 !important;\n " +
223
- " }\n " +
224
- " </style>\n " +
225
- " <div contenteditable=\" true\" ></div>\n " );
227
+ " stylesheet rules will throw.\n " +
228
+ " -->\n " +
229
+ " <link rel=stylesheet href=\" " + server .CROSS_PROCESS_PREFIX + "/injectedstyle.css'}\" >\n " +
230
+ " <!-- make life harder: define caret color in stylesheet -->\n " +
231
+ " <style>\n " +
232
+ " div {\n " +
233
+ " caret-color: #000 !important;\n " +
234
+ " }\n " +
235
+ " </style>\n " +
236
+ " <div contenteditable=\" true\" ></div>\n " );
226
237
Locator div = page .locator ("div" );
227
238
div .type ("foo bar" );
228
239
byte [] screenshot = div .screenshot ();
@@ -265,32 +276,32 @@ static boolean isScreenshotTestDisabled() {
265
276
}
266
277
267
278
@ Test
268
- @ DisabledIf (value = "com.microsoft.playwright.TestPageScreenshot#isScreenshotTestDisabled" , disabledReason = "array lengths differ" )
279
+ @ DisabledIf (value = "com.microsoft.playwright.TestPageScreenshot#isScreenshotTestDisabled" , disabledReason = "array lengths differ" )
269
280
void shouldHideElementsBasedOnAttr () throws IOException {
270
281
page .setViewportSize (500 , 500 );
271
282
page .navigate (server .PREFIX + "/grid.html" );
272
283
page .locator ("div" ).nth (5 ).evaluate ("element => {\n " +
273
- " element.setAttribute('data-test-screenshot', 'hide');\n " +
274
- "}" );
284
+ " element.setAttribute('data-test-screenshot', 'hide');\n " +
285
+ "}" );
275
286
byte [] actual = page .screenshot (new Page .ScreenshotOptions ().setStyle ("[data-test-screenshot=\" hide\" ] {\n " +
276
- " visibility: hidden;\n " +
277
- " }" ));
287
+ " visibility: hidden;\n " +
288
+ " }" ));
278
289
assertArrayEquals (expectedScreenshot ("hide-should-work" ), actual , "Screenshots should match" );
279
290
Object visibility = page .locator ("div" ).nth (5 ).evaluate ("element => element.style.visibility" );
280
291
assertEquals ("" , visibility );
281
292
}
282
293
283
294
@ Test
284
- @ DisabledIf (value = "com.microsoft.playwright.TestPageScreenshot#isScreenshotTestDisabled" , disabledReason = "array lengths differ" )
295
+ @ DisabledIf (value = "com.microsoft.playwright.TestPageScreenshot#isScreenshotTestDisabled" , disabledReason = "array lengths differ" )
285
296
void shouldRemoveElementsBasedOnAttr () throws IOException {
286
297
page .setViewportSize (500 , 500 );
287
298
page .navigate (server .PREFIX + "/grid.html" );
288
299
page .locator ("div" ).nth (5 ).evaluate ("element => {\n " +
289
- " element.setAttribute('data-test-screenshot', 'remove');\n " +
290
- " }" );
300
+ " element.setAttribute('data-test-screenshot', 'remove');\n " +
301
+ " }" );
291
302
byte [] actual = page .screenshot (new Page .ScreenshotOptions ().setStyle ("[data-test-screenshot=\" remove\" ] {\n " +
292
- " display: none;\n " +
293
- " }" ));
303
+ " display: none;\n " +
304
+ " }" ));
294
305
assertArrayEquals (expectedScreenshot ("remove-should-work" ), actual , "Screenshots should match" );
295
306
Object display = page .locator ("div" ).nth (5 ).evaluate ("element => element.style.display" );
296
307
assertEquals ("" , display );
0 commit comments