Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/print_pdf_test.js
2884 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
'use strict'
19
20
const test = require('../lib/test')
21
const { Pages } = require('../lib/test')
22
const { Browser } = require('selenium-webdriver')
23
const assert = require('node:assert')
24
25
let startIndex = 0
26
let endIndex = 5
27
let pdfMagicNumber = 'JVBER'
28
let base64Code
29
30
test.suite(
31
function (env) {
32
let driver
33
34
afterEach(function () {
35
return driver.quit()
36
})
37
38
it('Should Print pdf with 2 pages', async function () {
39
driver = env.builder().build()
40
await driver.get(Pages.printPage)
41
base64Code = await driver.printPage({ pageRanges: ['1-2'] })
42
base64Code = base64Code.slice(startIndex, endIndex)
43
assert.strictEqual(base64Code, pdfMagicNumber)
44
})
45
46
it('Should Print pdf with total pages', async function () {
47
driver = env.builder().build()
48
await driver.get(Pages.printPage)
49
base64Code = await driver.printPage()
50
base64Code = base64Code.slice(startIndex, endIndex)
51
assert.strictEqual(base64Code, pdfMagicNumber)
52
})
53
54
it('Check with all valid params', async function () {
55
driver = env.builder().build()
56
await driver.get(Pages.printPage)
57
base64Code = await driver.printPage({
58
orientation: 'landscape',
59
scale: 1,
60
background: true,
61
width: 30,
62
height: 30,
63
top: 1,
64
bottom: 1,
65
left: 1,
66
right: 1,
67
shrinkToFit: true,
68
pageRanges: ['1-2'],
69
})
70
base64Code = base64Code.slice(startIndex, endIndex)
71
assert.strictEqual(base64Code, pdfMagicNumber)
72
})
73
74
it('Check with page params', async function () {
75
driver = env.builder().build()
76
await driver.get(Pages.printPage)
77
base64Code = await driver.printPage({ width: 30, height: 30 })
78
base64Code = base64Code.slice(startIndex, endIndex)
79
assert.strictEqual(base64Code, pdfMagicNumber)
80
})
81
82
it('Check with margin params', async function () {
83
driver = env.builder().build()
84
await driver.get(Pages.printPage)
85
base64Code = await driver.printPage({
86
top: 1,
87
bottom: 1,
88
left: 1,
89
right: 1,
90
})
91
base64Code = base64Code.slice(startIndex, endIndex)
92
assert.strictEqual(base64Code, pdfMagicNumber)
93
})
94
},
95
{ browsers: [Browser.FIREFOX, Browser.CHROME] },
96
)
97
98