Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/java/test/org/openqa/selenium/PrintPageTest.java
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
18
package org.openqa.selenium;
19
20
import static org.assertj.core.api.Assertions.assertThat;
21
import static org.junit.jupiter.api.Assumptions.assumeTrue;
22
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
23
24
import org.junit.jupiter.api.BeforeEach;
25
import org.junit.jupiter.api.Test;
26
import org.openqa.selenium.print.PageSize;
27
import org.openqa.selenium.print.PrintOptions;
28
import org.openqa.selenium.testing.Ignore;
29
import org.openqa.selenium.testing.JupiterTestBase;
30
31
class PrintPageTest extends JupiterTestBase {
32
private static final String MAGIC_STRING = "JVBER";
33
private PrintsPage printer;
34
35
@BeforeEach
36
public void setUp() {
37
assumeTrue(driver instanceof PrintsPage);
38
printer = (PrintsPage) driver;
39
driver.get(pages.printPage);
40
}
41
42
// TODO: Skipped for Chrome because it needs to run headless, a workaround for this is needed.
43
@Test
44
@Ignore(value = CHROME)
45
public void canPrintPage() {
46
PrintOptions printOptions = new PrintOptions();
47
48
Pdf pdf = printer.print(printOptions);
49
assertThat(pdf.getContent().contains(MAGIC_STRING)).isTrue();
50
}
51
52
// TODO: Skipped for Chrome because it needs to run headless, a workaround for this is needed.
53
@Test
54
@Ignore(value = CHROME)
55
public void canPrintTwoPages() {
56
PrintOptions printOptions = new PrintOptions();
57
printOptions.setPageRanges("1-2");
58
59
Pdf pdf = printer.print(printOptions);
60
assertThat(pdf.getContent().contains(MAGIC_STRING)).isTrue();
61
}
62
63
// TODO: Skipped for Chrome because it needs to run headless, a workaround for this is needed.
64
@Test
65
@Ignore(value = CHROME)
66
public void canPrintWithValidParams() {
67
PrintOptions printOptions = new PrintOptions();
68
PageSize pageSize = new PageSize();
69
70
printOptions.setPageRanges("1-2");
71
printOptions.setOrientation(PrintOptions.Orientation.LANDSCAPE);
72
printOptions.setPageSize(pageSize);
73
74
Pdf pdf = printer.print(printOptions);
75
assertThat(pdf.getContent().contains(MAGIC_STRING)).isTrue();
76
}
77
}
78
79