19
19
20
20
import static org .assertj .core .api .AssertionsForClassTypes .assertThat ;
21
21
import static org .assertj .core .api .AssertionsForClassTypes .assertThatExceptionOfType ;
22
+ import static org .junit .jupiter .api .Assertions .fail ;
22
23
import static org .openqa .selenium .support .ui .ExpectedConditions .alertIsPresent ;
23
24
import static org .openqa .selenium .testing .Safely .safelyCall ;
24
25
import static org .openqa .selenium .testing .drivers .Browser .CHROME ;
28
29
import static org .openqa .selenium .testing .drivers .Browser .SAFARI ;
29
30
30
31
import java .util .List ;
32
+
31
33
import org .junit .jupiter .api .AfterEach ;
32
34
import org .junit .jupiter .api .BeforeEach ;
33
35
import org .junit .jupiter .api .Test ;
34
36
import org .openqa .selenium .By ;
37
+ import org .openqa .selenium .Rectangle ;
38
+ import org .openqa .selenium .WebElement ;
35
39
import org .openqa .selenium .WindowType ;
36
40
import org .openqa .selenium .bidi .BiDiException ;
37
41
import org .openqa .selenium .environment .webserver .AppServer ;
@@ -74,7 +78,7 @@ void canCreateAWindow() {
74
78
@ NotYetImplemented (EDGE )
75
79
void canCreateAWindowWithAReferenceContext () {
76
80
BrowsingContext browsingContext =
77
- new BrowsingContext (driver , WindowType .WINDOW , driver .getWindowHandle ());
81
+ new BrowsingContext (driver , WindowType .WINDOW , driver .getWindowHandle ());
78
82
assertThat (browsingContext .getId ()).isNotEmpty ();
79
83
}
80
84
@@ -93,7 +97,7 @@ void canCreateATab() {
93
97
@ NotYetImplemented (EDGE )
94
98
void canCreateATabWithAReferenceContext () {
95
99
BrowsingContext browsingContext =
96
- new BrowsingContext (driver , WindowType .TAB , driver .getWindowHandle ());
100
+ new BrowsingContext (driver , WindowType .TAB , driver .getWindowHandle ());
97
101
assertThat (browsingContext .getId ()).isNotEmpty ();
98
102
}
99
103
@@ -358,6 +362,32 @@ void canCaptureScreenshot() {
358
362
assertThat (screenshot .length ()).isPositive ();
359
363
}
360
364
365
+ @ Test
366
+ @ NotYetImplemented (SAFARI )
367
+ @ NotYetImplemented (IE )
368
+ @ NotYetImplemented (CHROME )
369
+ void canCaptureScreenshotOfViewport () {
370
+ String expectedBase64EncodedImage =
371
+ "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAVklEQVQYV2P8z8AARIQB41BQOAvomScE/MIElGdcCFS4B"
372
+ + "8hYTEAx3NdLgApjkRRbA9mrgRgUdrdBJsKC5x6Qo4yksBbIbkLiwxW+BwoKIUnUAdmNSHwAe44dOkRcP14AAAAASUVORK5CYII=" ;
373
+
374
+ BrowsingContext browsingContext = new BrowsingContext (driver , driver .getWindowHandle ());
375
+
376
+ driver .get (appServer .whereIs ("coordinates_tests/simple_page.html" ));
377
+ WebElement element = driver .findElement (By .id ("box" ));
378
+
379
+ Rectangle elementRectangle = element .getRect ();
380
+
381
+ String screenshot = browsingContext .captureBoxScreenshot (
382
+ elementRectangle .getX (),
383
+ elementRectangle .getY (),
384
+ 5 ,
385
+ 5 );
386
+
387
+ assertThat (screenshot .length ()).isPositive ();
388
+ assertThat (screenshot ).isEqualTo (expectedBase64EncodedImage );
389
+ }
390
+
361
391
private String alertPage () {
362
392
return appServer .create (
363
393
new Page ()
0 commit comments