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 32
32
import org .openqa .selenium .json .Json ;
33
33
import org .openqa .selenium .json .JsonInput ;
34
34
import 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 ;
35
38
36
39
public class BrowsingContext {
37
40
@@ -310,6 +313,20 @@ public void activate() {
310
313
this .bidi .send (new Command <>("browsingContext.activate" , Map .of (CONTEXT , id )));
311
314
}
312
315
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
+
313
330
public void close () {
314
331
// This might need more clean up actions once the behavior is defined.
315
332
// Specially when last tab or window is closed.
Original file line number Diff line number Diff line change 41
41
import org .openqa .selenium .environment .webserver .AppServer ;
42
42
import org .openqa .selenium .environment .webserver .NettyAppServer ;
43
43
import org .openqa .selenium .environment .webserver .Page ;
44
+ import org .openqa .selenium .print .PrintOptions ;
44
45
import org .openqa .selenium .remote .RemoteWebElement ;
45
46
import org .openqa .selenium .testing .JupiterTestBase ;
46
47
import org .openqa .selenium .testing .NotYetImplemented ;
@@ -478,6 +479,25 @@ void canSetViewportWithDevicePixelRatio() {
478
479
assertThat (newDevicePixelRatio ).isEqualTo (5 );
479
480
}
480
481
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
+
481
501
private String alertPage () {
482
502
return appServer .create (
483
503
new Page ()
You can’t perform that action at this time.
0 commit comments