2019-11-20 08:29:28 +08:00
|
|
|
/**
|
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
2020-08-17 10:19:52 +08:00
|
|
|
|
2022-03-26 07:05:50 +08:00
|
|
|
import { browserTest as it, expect } from '../config/browserTest';
|
2020-08-28 19:20:29 +08:00
|
|
|
import fs from 'fs';
|
2020-08-06 23:27:00 +08:00
|
|
|
|
2024-12-06 09:53:31 +08:00
|
|
|
it('should be able to save file', async ({ contextFactory, browserName }, testInfo) => {
|
|
|
|
|
it.skip(browserName !== 'chromium', 'Printing to pdf is currently only supported in chromium.');
|
2021-04-03 12:07:45 +08:00
|
|
|
const context = await contextFactory();
|
|
|
|
|
const page = await context.newPage();
|
2020-10-06 08:03:24 +08:00
|
|
|
const outputFile = testInfo.outputPath('output.pdf');
|
2021-09-28 00:58:08 +08:00
|
|
|
await page.pdf({ path: outputFile });
|
2020-08-04 06:23:53 +08:00
|
|
|
expect(fs.readFileSync(outputFile).byteLength).toBeGreaterThan(0);
|
2020-04-09 06:19:09 +08:00
|
|
|
});
|
2024-02-16 00:28:04 +08:00
|
|
|
|
2024-12-06 09:53:31 +08:00
|
|
|
it('should be able to generate outline', async ({ contextFactory, server, browserName }, testInfo) => {
|
|
|
|
|
it.skip(browserName !== 'chromium', 'Printing to pdf is currently only supported in chromium.');
|
2024-02-16 00:28:04 +08:00
|
|
|
const context = await contextFactory({
|
|
|
|
|
baseURL: server.PREFIX,
|
|
|
|
|
});
|
|
|
|
|
const page = await context.newPage();
|
|
|
|
|
await page.goto('/headings.html');
|
|
|
|
|
const outputFileNoOutline = testInfo.outputPath('outputNoOutline.pdf');
|
|
|
|
|
const outputFileOutline = testInfo.outputPath('outputOutline.pdf');
|
|
|
|
|
await page.pdf({ path: outputFileNoOutline });
|
|
|
|
|
await page.pdf({ path: outputFileOutline, tagged: true, outline: true });
|
|
|
|
|
expect(fs.readFileSync(outputFileOutline).byteLength).toBeGreaterThan(fs.readFileSync(outputFileNoOutline).byteLength);
|
|
|
|
|
});
|