How to use pyppeteer - 10 common examples

To help you get started, we’ve selected a few pyppeteer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github miyakogi / pyppeteer / tests / test_page.py View on Github external
async def test_nice_error_after_navigation(self):
        executionContext = await self.page.mainFrame.executionContext()

        await asyncio.wait([
            self.page.waitForNavigation(),
            executionContext.evaluate('window.location.reload()'),
        ])

        with self.assertRaises(NetworkError) as cm:
            await executionContext.evaluate('() => null')
        self.assertIn('navigation', cm.exception.args[0])
github miyakogi / pyppeteer / tests / test_abnormal_crash.py View on Github external
async def test_browser_crash_send(self):
        browser = await launch(args=['--no-sandbox'])
        page = await browser.newPage()
        await page.goto('about:blank')
        await page.querySelector("title")
        browser.process.terminate()
        browser.process.wait()

        if current_platform().startswith('win'):
            # wait for terminating browser process
            await asyncio.sleep(1)

        with self.assertRaises(NetworkError):
            await page.querySelector("title")
        with self.assertRaises(NetworkError):
            with self.assertLogs('pyppeteer', logging.ERROR):
                await page.querySelector("title")
        with self.assertRaises(ConnectionError):
            await browser.newPage()
github web-platform-tests / wpt / tools / pyppeteer / pyppeteer / connection.py View on Github external
def open(self):
        if self.is_open():
            raise ConnectionError('Connection is already open')

        self.logger.info('opening')
        self._reading_thread = threading.Thread(target=lambda: self._read_forever())
        self._reading_thread.start()
        self._open_event.wait()
        self.logger.info('opened')

        if self.prefer_experimental:
            self.send(
                'Security.setIgnoreCertificateErrors',  # API status: experimental
                {'ignore': True}
            )
        else:
            self.send('Security.enable', {})  # API status: stable
            self.send(
                'Security.setOverrideCertificateErrors',  # API status: deprecated
github miyakogi / pyppeteer / tests / test_launcher.py View on Github external
async def test_ignore_https_errors(self):
        browser = await launch(DEFAULT_OPTIONS, ignoreHTTPSErrors=True)
        page = await browser.newPage()
        port = get_free_port()
        time.sleep(0.1)
        app = get_application()
        server = app.listen(port)
        response = await page.goto('https://localhost:{}'.format(port))
        self.assertTrue(response.ok)
        await browser.close()
        server.stop()
github miyakogi / pyppeteer / tests / test_launcher.py View on Github external
async def test_user_data_dir_restore_cookie_in_browser(self):
        browser = await launch(
            DEFAULT_OPTIONS, userDataDir=self.datadir, headless=False)
        page = await browser.newPage()
        await page.goto(self.url + 'empty')
        await page.evaluate('() => document.cookie = "foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT"')  # noqa: E501
        await browser.close()

        browser2 = await launch(DEFAULT_OPTIONS, userDataDir=self.datadir)
        page2 = await browser2.newPage()
        await page2.goto(self.url + 'empty')
        result = await page2.evaluate('() => document.cookie')
        await browser2.close()
        self.assertEqual(result, 'foo=true')
github miyakogi / pyppeteer / tests / test_launcher.py View on Github external
async def test_launch(self):
        browser = await launch(DEFAULT_OPTIONS)
        await browser.newPage()
        await browser.close()
github miyakogi / pyppeteer / tests / test_execution_context.py View on Github external
async def test_json_circular_object_error(self):
        windowHandle = await self.page.evaluateHandle('window')
        with self.assertRaises(NetworkError) as cm:
            await windowHandle.jsonValue()
        self.assertIn('Object reference chain is too long',
                      cm.exception.args[0])
github miyakogi / pyppeteer / tests / test_frame.py View on Github external
async def test_fail_page_closed(self):
        page = await self.context.newPage()
        await page.goto(self.url + 'empty')
        task = page.waitForSelector('.box')
        await page.close()
        with self.assertRaises(NetworkError):
            await task
github miyakogi / pyppeteer / tests / test_execution_context.py View on Github external
async def test_query_objects_disposed(self):
        await self.page.goto(self.url + 'empty')
        prototypeHandle = await self.page.evaluateHandle(
            '() => HTMLBodyElement.prototype'
        )
        await prototypeHandle.dispose()
        with self.assertRaises(ElementHandleError):
            await self.page.queryObjects(prototypeHandle)
github miyakogi / pyppeteer / tests / test_element_handle.py View on Github external
async def test_Jeval_with_missing_selector(self):
        htmlContent = '<div class="a">not-a-child-div</div><div id="myId"></div>'  # noqa: E501
        await self.page.setContent(htmlContent)
        elementHandle = await self.page.J('#myId')
        with self.assertRaises(ElementHandleError) as cm:
            await elementHandle.Jeval('.a', 'node =&gt; node.innerText')
        self.assertIn('Error: failed to find element matching selector ".a"',
                      cm.exception.args[0])