Path: blob/trunk/java/test/org/openqa/selenium/PrintPageTest.java
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.1617package org.openqa.selenium;1819import static org.assertj.core.api.Assertions.assertThat;20import static org.junit.jupiter.api.Assumptions.assumeTrue;21import static org.openqa.selenium.testing.drivers.Browser.CHROME;2223import org.junit.jupiter.api.BeforeEach;24import org.junit.jupiter.api.Test;25import org.openqa.selenium.print.PageSize;26import org.openqa.selenium.print.PrintOptions;27import org.openqa.selenium.testing.Ignore;28import org.openqa.selenium.testing.JupiterTestBase;2930class PrintPageTest extends JupiterTestBase {31private static final String MAGIC_STRING = "JVBER";32private PrintsPage printer;3334@BeforeEach35public void setUp() {36assumeTrue(driver instanceof PrintsPage);37printer = (PrintsPage) driver;38driver.get(pages.printPage);39}4041// TODO: Skipped for Chrome because it needs to run headless, a workaround for this is needed.42@Test43@Ignore(value = CHROME)44public void canPrintPage() {45PrintOptions printOptions = new PrintOptions();4647Pdf pdf = printer.print(printOptions);48assertThat(pdf.getContent().contains(MAGIC_STRING)).isTrue();49}5051// TODO: Skipped for Chrome because it needs to run headless, a workaround for this is needed.52@Test53@Ignore(value = CHROME)54public void canPrintTwoPages() {55PrintOptions printOptions = new PrintOptions();56printOptions.setPageRanges("1-2");5758Pdf pdf = printer.print(printOptions);59assertThat(pdf.getContent().contains(MAGIC_STRING)).isTrue();60}6162// TODO: Skipped for Chrome because it needs to run headless, a workaround for this is needed.63@Test64@Ignore(value = CHROME)65public void canPrintWithValidParams() {66PrintOptions printOptions = new PrintOptions();67PageSize pageSize = new PageSize();6869printOptions.setPageRanges("1-2");70printOptions.setOrientation(PrintOptions.Orientation.LANDSCAPE);71printOptions.setPageSize(pageSize);7273Pdf pdf = printer.print(printOptions);74assertThat(pdf.getContent().contains(MAGIC_STRING)).isTrue();75}76}777879