Path: blob/trunk/javascript/selenium-webdriver/test/print_pdf_test.js
2884 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.1617'use strict'1819const test = require('../lib/test')20const { Pages } = require('../lib/test')21const { Browser } = require('selenium-webdriver')22const assert = require('node:assert')2324let startIndex = 025let endIndex = 526let pdfMagicNumber = 'JVBER'27let base64Code2829test.suite(30function (env) {31let driver3233afterEach(function () {34return driver.quit()35})3637it('Should Print pdf with 2 pages', async function () {38driver = env.builder().build()39await driver.get(Pages.printPage)40base64Code = await driver.printPage({ pageRanges: ['1-2'] })41base64Code = base64Code.slice(startIndex, endIndex)42assert.strictEqual(base64Code, pdfMagicNumber)43})4445it('Should Print pdf with total pages', async function () {46driver = env.builder().build()47await driver.get(Pages.printPage)48base64Code = await driver.printPage()49base64Code = base64Code.slice(startIndex, endIndex)50assert.strictEqual(base64Code, pdfMagicNumber)51})5253it('Check with all valid params', async function () {54driver = env.builder().build()55await driver.get(Pages.printPage)56base64Code = await driver.printPage({57orientation: 'landscape',58scale: 1,59background: true,60width: 30,61height: 30,62top: 1,63bottom: 1,64left: 1,65right: 1,66shrinkToFit: true,67pageRanges: ['1-2'],68})69base64Code = base64Code.slice(startIndex, endIndex)70assert.strictEqual(base64Code, pdfMagicNumber)71})7273it('Check with page params', async function () {74driver = env.builder().build()75await driver.get(Pages.printPage)76base64Code = await driver.printPage({ width: 30, height: 30 })77base64Code = base64Code.slice(startIndex, endIndex)78assert.strictEqual(base64Code, pdfMagicNumber)79})8081it('Check with margin params', async function () {82driver = env.builder().build()83await driver.get(Pages.printPage)84base64Code = await driver.printPage({85top: 1,86bottom: 1,87left: 1,88right: 1,89})90base64Code = base64Code.slice(startIndex, endIndex)91assert.strictEqual(base64Code, pdfMagicNumber)92})93},94{ browsers: [Browser.FIREFOX, Browser.CHROME] },95)969798