Skip to content

Add Python Examples for PrintOptions #1994

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

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions examples/python/tests/interactions/test_print_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import pytest
from selenium import webdriver
from selenium.webdriver.common import PrintOptions, PageMargin

@pytest.fixture()
def driver():
driver = webdriver.Chrome()
yield driver
driver.quit()

def test_orientation(driver):
driver.get("https://www.selenium.dev/")
print_options = PrintOptions()
print_options.set_orientation(PrintOptions.Orientation.LANDSCAPE) ## LANDSCAPE or PORTRAIT
current_orientation = print_options.get_orientation()
assert current_orientation == PrintOptions.Orientation.LANDSCAPE

def test_range(driver):
driver.get("https://www.selenium.dev/")
print_options = PrintOptions()
print_options.set_page_ranges("1-3")
# print_options.set_page_ranges(["1", "2", "3"])
current_range = print_options.get_page_ranges()
assert current_range == ["1", "2", "3"]

def test_size(driver):
driver.get("https://www.selenium.dev/")
print_options = PrintOptions()
print_options.set_page_size("A4") ## A4, A3, A2, A1, A0, Letter, Legal, Tabloid
current_size = print_options.get_size()
assert current_size == "A4"

def test_margin(driver):
driver.get("https://www.selenium.dev/")
margins = PageMargin(10, 10, 10, 10) # margins are in millimeters (mm)
print_options = PrintOptions()
print_options.set_page_margin(margins)
current_margin = print_options.get_page_margin()
assert current_margin.get_top() == 10
assert current_margin.get_bottom() == 10
assert current_margin.get_left() == 10
assert current_margin.get_right() == 10

def test_scale(driver):
driver.get("https://www.selenium.dev/")
print_options = PrintOptions()
print_options.set_scale(0.5) ## 0.1 to 2.0
current_scale = print_options.get_scale()
assert current_scale == 0.5

def test_background(driver):
driver.get("https://www.selenium.dev/")
print_options = PrintOptions()
print_options.set_background(True) ## True or False
current_background = print_options.get_background()
assert current_background is True

def test_shrink_to_fit(driver):
driver.get("https://www.selenium.dev/")
print_options = PrintOptions()
print_options.set_shrink_to_fit(True) ## True or False
current_shrink_to_fit = print_options.get_shrink_to_fit()
assert current_shrink_to_fit is True
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
title: "Print Page"
linkTitle: "Print Page"
weight: 7
aliases: [
"/documentation/en/support_packages/print_page/",
]
aliases: ["/documentation/en/support_packages/print_page/"]
---

Printing a website is a common requirement, whether for sharing information or archiving records.
Expand All @@ -22,17 +20,16 @@ Using the `getOrientation()` and `setOrientation()` methods, you can get/set the
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L11-L16" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}

Expand All @@ -47,17 +44,16 @@ Using the `getPageRanges()` and `setPageRanges()` methods, you can get/set the r
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L18-L24" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}

Expand All @@ -72,17 +68,16 @@ Using the `getPaperSize()` and `setPaperSize()` methods, you can get/set the pap
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L26-L31" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}

Expand All @@ -97,17 +92,16 @@ Using the `getPageMargin()` and `setPageMargin()` methods, you can set the margi
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L33-L424" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}

Expand All @@ -122,17 +116,16 @@ Using `getScale()` and `setScale()` methods, you can get/set the scale of the pa
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L44-L49" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}

Expand All @@ -147,17 +140,16 @@ Using `getBackground()` and `setBackground()` methods, you can get/set whether b
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L51-L56" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}

Expand All @@ -172,16 +164,15 @@ Using `getBackground()` and `setBackground()` methods, you can get/set whether t
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L58-L63" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
title: "Print Page"
linkTitle: "Print Page"
weight: 7
aliases: [
"/documentation/ja/support_packages/print_page/",
]
aliases: ["/documentation/ja/support_packages/print_page/"]
---

Printing a website is a common requirement, whether for sharing information or archiving records.
Expand All @@ -22,17 +20,16 @@ Using the `getOrientation()` and `setOrientation()` methods, you can get/set the
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L11-L16" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}

Expand All @@ -47,17 +44,16 @@ Using the `getPageRanges()` and `setPageRanges()` methods, you can get/set the r
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L18-L24" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}

Expand All @@ -72,17 +68,16 @@ Using the `getPaperSize()` and `setPaperSize()` methods, you can get/set the pap
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L26-L31" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}

Expand All @@ -97,17 +92,16 @@ Using the `getPageMargin()` and `setPageMargin()` methods, you can set the margi
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L33-L424" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}

Expand All @@ -122,17 +116,16 @@ Using `getScale()` and `setScale()` methods, you can get/set the scale of the pa
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L44-L49" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}

Expand All @@ -147,17 +140,16 @@ Using `getBackground()` and `setBackground()` methods, you can get/set whether b
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L51-L56" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}

Expand All @@ -172,16 +164,15 @@ Using `getBackground()` and `setBackground()` methods, you can get/set whether t
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_print_options.py#L58-L63" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< badge-implementation >}}
{{< /tab >}}
{{< /tabpane >}}
Loading
Loading