Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/selenium/webdriver/common/print_pdf_tests.py
1865 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
import pytest
18
19
from selenium.webdriver.common.print_page_options import PrintOptions
20
21
START_INDEX = 0
22
END_INDEX = 5
23
PDF_MAGIC_NUMBER = "JVBER"
24
25
26
@pytest.mark.xfail_safari(reason="no endpoint for print in safari")
27
def test_pdf_with_2_pages(driver, pages):
28
print_options = PrintOptions()
29
print_options.page_ranges = ["1-2"]
30
31
pages.load("printPage.html")
32
33
base64code = driver.print_page(print_options)
34
35
assert base64code[START_INDEX:END_INDEX] == PDF_MAGIC_NUMBER
36
37
38
@pytest.mark.xfail_safari(reason="no endpoint for print in safari")
39
def test_pdf_with_all_pages(driver, pages):
40
pages.load("printPage.html")
41
base64code = driver.print_page()
42
43
assert base64code[START_INDEX:END_INDEX] == PDF_MAGIC_NUMBER
44
45
46
@pytest.mark.xfail_safari(reason="no endpoint for print in safari")
47
def test_valid_params(driver, pages):
48
print_options = PrintOptions()
49
50
print_options.page_ranges = ["1-2"]
51
print_options.orientation = "landscape"
52
print_options.width = 30
53
54
pages.load("printPage.html")
55
base64code = driver.print_page(print_options)
56
57
assert base64code[START_INDEX:END_INDEX] == PDF_MAGIC_NUMBER
58
59
60
@pytest.mark.xfail_safari(reason="no endpoint for print in safari")
61
def test_session_id_is_not_preserved_after_page_is_printed(driver, pages):
62
print_options = PrintOptions()
63
print_options.margin_bottom = print_options.margin_top = print_options.margin_left = print_options.margin_right = 0
64
assert "sessionId" not in print_options.to_dict()
65
pages.load("printPage.html")
66
driver.print_page(print_options=print_options)
67
assert "sessionId" not in print_options.to_dict()
68
69