3434import org .junit .jupiter .api .BeforeEach ;
3535import org .junit .jupiter .api .Test ;
3636import org .openqa .selenium .By ;
37- import org .openqa .selenium .Dimension ;
3837import org .openqa .selenium .JavascriptExecutor ;
3938import org .openqa .selenium .Rectangle ;
4039import org .openqa .selenium .WebElement ;
@@ -384,18 +383,26 @@ void canCaptureScreenshot() {
384383 @ Test
385384 @ NotYetImplemented (SAFARI )
386385 @ NotYetImplemented (IE )
387- @ NotYetImplemented (CHROME )
388- void canCaptureScreenshotOfViewport () {
386+ void canCaptureScreenshotWithAllParameters () {
389387 BrowsingContext browsingContext = new BrowsingContext (driver , driver .getWindowHandle ());
390388
391389 driver .get (appServer .whereIs ("coordinates_tests/simple_page.html" ));
392390 WebElement element = driver .findElement (By .id ("box" ));
393391
394392 Rectangle elementRectangle = element .getRect ();
395393
394+ ClipRectangle clipRectangle =
395+ new BoxClipRectangle (elementRectangle .getX (), elementRectangle .getY (), 5 , 5 );
396+
397+ CaptureScreenshotParameters parameters = new CaptureScreenshotParameters ();
398+ // TODO: Add test to test the type and quality
399+ // parameters.imageFormat("image/png", 0.5);
400+
396401 String screenshot =
397- browsingContext .captureBoxScreenshot (
398- elementRectangle .getX (), elementRectangle .getY (), 5 , 5 );
402+ browsingContext .captureScreenshot (
403+ parameters
404+ .origin (CaptureScreenshotParameters .Origin .DOCUMENT )
405+ .clipRectangle (clipRectangle ));
399406
400407 assertThat (screenshot .length ()).isPositive ();
401408 }
@@ -404,15 +411,17 @@ void canCaptureScreenshotOfViewport() {
404411 @ NotYetImplemented (SAFARI )
405412 @ NotYetImplemented (IE )
406413 @ NotYetImplemented (CHROME )
407- void canCaptureElementScreenshot () {
414+ void canCaptureScreenshotOfViewport () {
408415 BrowsingContext browsingContext = new BrowsingContext (driver , driver .getWindowHandle ());
409416
410- driver .get (appServer .whereIs ("formPage.html" ));
417+ driver .get (appServer .whereIs ("coordinates_tests/simple_page.html" ));
418+ WebElement element = driver .findElement (By .id ("box" ));
411419
412- WebElement element = driver . findElement ( By . id ( "checky" ) );
420+ Rectangle elementRectangle = element . getRect ( );
413421
414422 String screenshot =
415- browsingContext .captureElementScreenshot (((RemoteWebElement ) element ).getId ());
423+ browsingContext .captureBoxScreenshot (
424+ elementRectangle .getX (), elementRectangle .getY (), 5 , 5 );
416425
417426 assertThat (screenshot .length ()).isPositive ();
418427 }
@@ -421,18 +430,15 @@ void canCaptureElementScreenshot() {
421430 @ NotYetImplemented (SAFARI )
422431 @ NotYetImplemented (IE )
423432 @ NotYetImplemented (CHROME )
424- @ NotYetImplemented (FIREFOX )
425- void canScrollAndCaptureElementScreenshot () {
426- Dimension dimension = new Dimension (300 , 300 );
427- driver .manage ().window ().setSize (dimension );
433+ void canCaptureElementScreenshot () {
428434 BrowsingContext browsingContext = new BrowsingContext (driver , driver .getWindowHandle ());
429435
430436 driver .get (appServer .whereIs ("formPage.html" ));
431437
432- WebElement element = driver .findElement (By .id ("checkbox-with-label " ));
438+ WebElement element = driver .findElement (By .id ("checky " ));
433439
434440 String screenshot =
435- browsingContext .captureElementScreenshot (((RemoteWebElement ) element ).getId (), true );
441+ browsingContext .captureElementScreenshot (((RemoteWebElement ) element ).getId ());
436442
437443 assertThat (screenshot .length ()).isPositive ();
438444 }
0 commit comments