Skip to main content

A plugin to run pyppeteer in pytest.

Project description

pytest-pyppeteer

A plugin to run pyppeteer in pytest.

PyPI - Python Version GitHub issues PyPI PyPI - Downloads Code style: black Documentation Status

Documents

Github Pages: https://luizyao.github.io/pytest-pyppeteer/

Gitee Pages: https://luizyao.gitee.io/pytest-pyppeteer/

Installation

You can install pytest-pyppeteer via pip:

$ pip install pytest-pyppeteer

or install the latest one on Github:

pip install git+https://github.com/luizyao/pytest-pyppeteer.git

Quickstart

For example, query the rating of the movie The Shawshank Redemption on douban.com.

from dataclasses import dataclass


@dataclass
class Elements:
    url = "https://movie.douban.com/"

    query = "#inp-query"
    apply = ".inp-btn > input:nth-child(1)"

    result = (
        "#root > div > div > div > div > div:nth-child(1) > div.item-root a.cover-link"
    )
    rating = (
        "#interest_sectl > div.rating_wrap.clearbox > div.rating_self.clearfix > strong"
    )


async def test_pyppeteer(pyppeteer):
    page = await pyppeteer.new_page()
    await page.goto(Elements.url)

    await page.type(Elements.query, "The Shawshank Redemption")
    await page.click(Elements.apply)

    await page.waitfor(Elements.result)
    await page.click(Elements.result)

    await page.waitfor(Elements.rating)
    rating = await page.get_value(Elements.rating)
    assert rating == 0

License

Distributed under the terms of the MIT license, pytest-pyppeteer is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Changelog

0.2.1 (2020-10-16)

Fixed

  • 🐛 fix issue #18 [b1b2246]

0.2.0 (2020-10-02)

Added

  • ✨ support to start the browser maximized [f632ea5]
  • ✨ add new hook [bd04729]
  • ✨ add options marker [989150e]
  • ✨ add errors module [37dece5]
  • ✨ add "--executable-path" command line option [664dd7c]

Fixed

  • 🐛 fix unprintable error class [d57af5a]
  • 🐛 fix different "--window-size 0 0" behaviors between mac and windows [ff30cdd]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-pyppeteer-0.2.1.tar.gz (13.8 kB view hashes)

Uploaded Source

Built Distribution

pytest_pyppeteer-0.2.1-py3-none-any.whl (13.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page