fix: NPE in Page.pdf for persistent context (#1292)

Fixes #1291
This commit is contained in:
Yury Semikhatsky 2023-05-26 12:00:07 -07:00 committed by GitHub
parent 5a4640fe2a
commit b8a9d888be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -946,9 +946,6 @@ public class PageImpl extends ChannelOwner implements Page {
}
private byte[] pdfImpl(PdfOptions options) {
if (!browserContext.browser().isChromium()) {
throw new PlaywrightException("Page.pdf only supported in headless Chromium");
}
if (options == null) {
options = new PdfOptions();
}

View File

@ -52,6 +52,18 @@ public class TestPdf extends TestBase {
@DisabledIf(value="com.microsoft.playwright.TestBase#isChromium", disabledReason="skip")
void shouldThrowInNonChromium() {
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.pdf());
assertTrue(e.getMessage().contains("Page.pdf only supported in headless Chromium"));
assertTrue(e.getMessage().contains("PDF generation is only supported for Headless Chromium"), e.getMessage());
}
@Test
@DisabledIf(value="com.microsoft.playwright.TestBase#isChromium", disabledReason="skip")
void correctExceptionWithPersistentContext(@TempDir Path tempDir) {
Path profile = tempDir.resolve("profile");
try (BrowserContext context = browserType.launchPersistentContext(profile)) {
Page page = context.newPage();
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.pdf());
assertTrue(e.getMessage().contains("PDF generation is only supported for Headless Chromium"), e.getMessage());
}
}
}