File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
src/org/openqa/selenium/bidi/browsingcontext
test/org/openqa/selenium/bidi/browsingcontext Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 3232import org .openqa .selenium .json .Json ;
3333import org .openqa .selenium .json .JsonInput ;
3434import org .openqa .selenium .json .TypeToken ;
35+ import org .openqa .selenium .print .PageMargin ;
36+ import org .openqa .selenium .print .PageSize ;
37+ import org .openqa .selenium .print .PrintOptions ;
3538
3639public class BrowsingContext {
3740
@@ -310,6 +313,20 @@ public void activate() {
310313 this .bidi .send (new Command <>("browsingContext.activate" , Map .of (CONTEXT , id )));
311314 }
312315
316+ public String print (PrintOptions printOptions ) {
317+ Map <String , Object > printOptionsParams = printOptions .toMap ();
318+ printOptionsParams .put (CONTEXT , id );
319+
320+ return this .bidi .send (
321+ new Command <>(
322+ "browsingContext.print" ,
323+ printOptionsParams ,
324+ jsonInput -> {
325+ Map <String , Object > result = jsonInput .read (Map .class );
326+ return (String ) result .get ("data" );
327+ }));
328+ }
329+
313330 public void close () {
314331 // This might need more clean up actions once the behavior is defined.
315332 // Specially when last tab or window is closed.
Original file line number Diff line number Diff line change 4141import org .openqa .selenium .environment .webserver .AppServer ;
4242import org .openqa .selenium .environment .webserver .NettyAppServer ;
4343import org .openqa .selenium .environment .webserver .Page ;
44+ import org .openqa .selenium .print .PrintOptions ;
4445import org .openqa .selenium .remote .RemoteWebElement ;
4546import org .openqa .selenium .testing .JupiterTestBase ;
4647import org .openqa .selenium .testing .NotYetImplemented ;
@@ -478,6 +479,25 @@ void canSetViewportWithDevicePixelRatio() {
478479 assertThat (newDevicePixelRatio ).isEqualTo (5 );
479480 }
480481
482+ @ Test
483+ @ NotYetImplemented (SAFARI )
484+ @ NotYetImplemented (IE )
485+ void canPrintPage () {
486+ BrowsingContext browsingContext = new BrowsingContext (driver , driver .getWindowHandle ());
487+
488+ driver .get (appServer .whereIs ("formPage.html" ));
489+ PrintOptions printOptions = new PrintOptions ();
490+
491+ String printPage = browsingContext .print (printOptions );
492+
493+ assertThat (printPage .length ()).isPositive ();
494+ // Comparing expected PDF is a hard problem.
495+ // As long as we are sending the parameters correctly it should be fine.
496+ // Trusting the browsers to do the right thing.
497+ // Hence, just checking if the response is base64 encoded string.
498+ assertThat (printPage ).contains ("JVBER" );
499+ }
500+
481501 private String alertPage () {
482502 return appServer .create (
483503 new Page ()
You can’t perform that action at this time.
0 commit comments