Path: blob/trunk/py/test/selenium/webdriver/common/print_pdf_tests.py
1865 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.16import pytest1718from selenium.webdriver.common.print_page_options import PrintOptions1920START_INDEX = 021END_INDEX = 522PDF_MAGIC_NUMBER = "JVBER"232425@pytest.mark.xfail_safari(reason="no endpoint for print in safari")26def test_pdf_with_2_pages(driver, pages):27print_options = PrintOptions()28print_options.page_ranges = ["1-2"]2930pages.load("printPage.html")3132base64code = driver.print_page(print_options)3334assert base64code[START_INDEX:END_INDEX] == PDF_MAGIC_NUMBER353637@pytest.mark.xfail_safari(reason="no endpoint for print in safari")38def test_pdf_with_all_pages(driver, pages):39pages.load("printPage.html")40base64code = driver.print_page()4142assert base64code[START_INDEX:END_INDEX] == PDF_MAGIC_NUMBER434445@pytest.mark.xfail_safari(reason="no endpoint for print in safari")46def test_valid_params(driver, pages):47print_options = PrintOptions()4849print_options.page_ranges = ["1-2"]50print_options.orientation = "landscape"51print_options.width = 305253pages.load("printPage.html")54base64code = driver.print_page(print_options)5556assert base64code[START_INDEX:END_INDEX] == PDF_MAGIC_NUMBER575859@pytest.mark.xfail_safari(reason="no endpoint for print in safari")60def test_session_id_is_not_preserved_after_page_is_printed(driver, pages):61print_options = PrintOptions()62print_options.margin_bottom = print_options.margin_top = print_options.margin_left = print_options.margin_right = 063assert "sessionId" not in print_options.to_dict()64pages.load("printPage.html")65driver.print_page(print_options=print_options)66assert "sessionId" not in print_options.to_dict()676869