(
this: WebdriverIO.Browser,
filepath: string,
options?: PDFPrintOptions
)
| 21 | * Command implementation of the `savePDF` command. |
| 22 | */ |
| 23 | export async function savePDF ( |
| 24 | this: WebdriverIO.Browser, |
| 25 | filepath: string, |
| 26 | options?: PDFPrintOptions |
| 27 | ) { |
| 28 | /** |
| 29 | * type check |
| 30 | */ |
| 31 | if (typeof filepath !== 'string' || !filepath.endsWith('.pdf')) { |
| 32 | throw new Error('savePDF expects a filepath of type string and ".pdf" file ending') |
| 33 | } |
| 34 | |
| 35 | const absoluteFilepath = path.resolve(filepath) |
| 36 | await assertDirectoryExists(absoluteFilepath) |
| 37 | |
| 38 | const pdf = await this.printPage(options?.orientation, options?.scale, options?.background, |
| 39 | options?.width, options?.height, options?.top, options?.bottom, options?.left, options?.right, |
| 40 | options?.shrinkToFit, options?.pageRanges) |
| 41 | const page = Buffer.from(pdf, 'base64') |
| 42 | fs.writeFileSync(absoluteFilepath, page) |
| 43 | |
| 44 | return page |
| 45 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…