-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Added PrintOptions to Documentation #1987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5bbe661
Added PrintOptions to Documentation
shbenzer 1b9cde3
Merge branch 'trunk' into PrintOptionsSection
harsha509 6fa4054
Made intro more technical
shbenzer dca0c1d
Update print_page.ja.md
shbenzer 23126b2
Update print_page.pt-br.md
shbenzer 1d2df70
Update print_page.zh-cn.md
shbenzer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package dev.selenium.interactions; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.print.PageMargin; | ||
import org.openqa.selenium.print.PrintOptions; | ||
|
||
import dev.selenium.BaseChromeTest; | ||
|
||
public class PrintOptionsTest extends BaseChromeTest { | ||
|
||
@Test | ||
public void TestOrientation() | ||
{ | ||
driver.get("https://www.selenium.dev/"); | ||
PrintOptions printOptions = new PrintOptions(); | ||
printOptions.setOrientation(PrintOptions.Orientation.LANDSCAPE); | ||
PrintOptions.Orientation current_orientation = printOptions.getOrientation(); | ||
} | ||
|
||
@Test | ||
public void TestRange() | ||
{ | ||
driver.get("https://www.selenium.dev/"); | ||
PrintOptions printOptions = new PrintOptions(); | ||
printOptions.setPageRanges("1-2"); | ||
String[] current_range = printOptions.getPageRanges(); | ||
} | ||
|
||
@Test | ||
public void TestSize() | ||
{ | ||
driver.get("https://www.selenium.dev/"); | ||
PrintOptions printOptions = new PrintOptions(); | ||
printOptions.setScale(.50); | ||
double current_scale = printOptions.getScale(); | ||
} | ||
|
||
@Test | ||
public void TestMargins() | ||
{ | ||
driver.get("https://www.selenium.dev/"); | ||
PrintOptions printOptions = new PrintOptions(); | ||
PageMargin margins = new PageMargin(1.0,1.0,1.0,1.0); | ||
printOptions.setPageMargin(margins); | ||
double topMargin = margins.getTop(); | ||
double bottomMargin = margins.getBottom(); | ||
double leftMargin = margins.getLeft(); | ||
double rightMargin = margins.getRight(); | ||
} | ||
|
||
@Test | ||
public void TestScale() | ||
{ | ||
driver.get("https://www.selenium.dev/"); | ||
PrintOptions printOptions = new PrintOptions(); | ||
printOptions.setScale(.50); | ||
double current_scale = printOptions.getScale(); | ||
} | ||
|
||
@Test | ||
public void TestBackground() | ||
{ | ||
driver.get("https://www.selenium.dev/"); | ||
PrintOptions printOptions = new PrintOptions(); | ||
printOptions.setBackground(true); | ||
boolean current_background = printOptions.getBackground(); | ||
} | ||
|
||
@Test | ||
public void TestShrinkToFit() | ||
{ | ||
driver.get("https://www.selenium.dev/"); | ||
PrintOptions printOptions = new PrintOptions(); | ||
printOptions.setShrinkToFit(true); | ||
boolean current_shrink_to_fit = printOptions.getShrinkToFit(); | ||
} | ||
} |
190 changes: 190 additions & 0 deletions
190
website_and_docs/content/documentation/webdriver/interactions/print_page.en.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
--- | ||
title: "Print Page" | ||
linkTitle: "Print Page" | ||
weight: 7 | ||
aliases: [ | ||
"/documentation/en/support_packages/print_page/", | ||
] | ||
--- | ||
|
||
Sometimes you need to print the website you are using - whether that be your | ||
grandmother printing mapquest directions, or a judge needing to print court | ||
records. Luckily, Selenium provides an easy way to automate that! | ||
|
||
The `PrintOptions()` class provides an intuitive and multifaceted way of printing | ||
webpages to pdf so that you may enhance your tests, scripts, and software further. | ||
|
||
## Orientation | ||
Using the `getOrientation()` and `setOrientation()` methods, you can get/set the page orientation --- either `PORTRAIT` or `LANDSCAPE`. | ||
|
||
{{< tabpane text=true >}} | ||
{{< tab header="Java" >}} | ||
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L14-L20" >}} | ||
{{< /tab >}} | ||
{{< tab header="CSharp" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Ruby" >}} | ||
{{< badge-code >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="JavaScript" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Kotlin" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< /tabpane >}} | ||
|
||
## Range | ||
Using the `getPageRanges()` and `setPageRanges()` methods, you can get/set the range of pages to print --- e.g. "2-4". | ||
|
||
{{< tabpane text=true >}} | ||
{{< tab header="Java" >}} | ||
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L23-L29" >}} | ||
{{< /tab >}} | ||
{{< tab header="CSharp" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Ruby" >}} | ||
{{< badge-code >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="JavaScript" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Kotlin" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< /tabpane >}} | ||
|
||
## Size | ||
Using the `getPaperSize()` and `setPaperSize()` methods, you can get/set the paper size to print --- e.g. "A0", "A6", "Legal", "Tabloid", etc. | ||
|
||
{{< tabpane text=true >}} | ||
{{< tab header="Java" >}} | ||
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L32-L38" >}} | ||
{{< /tab >}} | ||
{{< tab header="CSharp" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Ruby" >}} | ||
{{< badge-code >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="JavaScript" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Kotlin" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< /tabpane >}} | ||
|
||
## Margins | ||
Using the `getPageMargin()` and `setPageMargin()` methods, you can set the margin sizes of the page you wish to print --- i.e. top, bottom, left, and right margins. | ||
|
||
{{< tabpane text=true >}} | ||
{{< tab header="Java" >}} | ||
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L41-L51" >}} | ||
{{< /tab >}} | ||
{{< tab header="CSharp" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Ruby" >}} | ||
{{< badge-code >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="JavaScript" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Kotlin" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< /tabpane >}} | ||
|
||
## Scale | ||
Using `getScale()` and `setScale()` methods, you can get/set the scale of the page you wish to print --- e.g. 1.0 is 100% or default, 0.25 is 25%, etc. | ||
|
||
{{< tabpane text=true >}} | ||
{{< tab header="Java" >}} | ||
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L54-L60" >}} | ||
{{< /tab >}} | ||
{{< tab header="CSharp" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Ruby" >}} | ||
{{< badge-code >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="JavaScript" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Kotlin" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< /tabpane >}} | ||
|
||
## Background | ||
Using `getBackground()` and `setBackground()` methods, you can get/set whether background colors and images appear --- boolean `true` or `false`. | ||
|
||
{{< tabpane text=true >}} | ||
{{< tab header="Java" >}} | ||
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L63-L69" >}} | ||
{{< /tab >}} | ||
{{< tab header="CSharp" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Ruby" >}} | ||
{{< badge-code >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="JavaScript" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Kotlin" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< /tabpane >}} | ||
|
||
## ShrinkToFit | ||
Using `getBackground()` and `setBackground()` methods, you can get/set whether the page will shrink-to-fit content on the page --- boolean `true` or `false`. | ||
|
||
{{< tabpane text=true >}} | ||
{{< tab header="Java" >}} | ||
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L72-L78" >}} | ||
{{< /tab >}} | ||
{{< tab header="CSharp" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Ruby" >}} | ||
{{< badge-code >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Python" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="JavaScript" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< tab header="Kotlin" >}} | ||
{{< badge-code >}} | ||
{{< /tab >}} | ||
{{< /tabpane >}} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.