GithubHelp home page GithubHelp logo

mxschmitt / pytest-playwright Goto Github PK

View Code? Open in Web Editor NEW
14.0 14.0 1.0 37 KB

Pytest plugin to write Playwright tests with ease. Provides fixtures to have a page instance for each individual test and helpful CLI options for headless browsers.

Home Page: https://pypi.org/project/pytest-playwright/

License: MIT License

Python 100.00%
playwright pytest python

pytest-playwright's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

abhimanyuaryan

pytest-playwright's Issues

[feature] base-url advanced integration

I thought about:

await page.goto() -> will navigate to the base url
await page.goto("/kek.html") -> will navigate to the base url + "kek.html"
await page.goto("https://google.com/kek.html") -> will navigate to "https://google.com/kek.html" (as normal)

Maybe even go before every test to the base URL, but not sure.
cc @suzil

[docs] add examples

Add some examples how to use the fixtures. Maybe in the readme or an examples directory.

Note: Its also possible to load the examples and load them into the tests.

[feature] add ability to manage test runs using conftest.py and config.json files

For my selenium project I do use solution to manage shared fixtures to control browser versions and options.

In conftest.py file

@pytest.fixture
def config(scope='session'):
    # Read the file
    with open('config.json') as config_file:
        config = json.load(config_file)

    assert config['browser'] in ['Firefox', 'Chrome', 'Headless Chrome']
    assert isinstance(config['implicit_wait'], int)
    assert config['implicit_wait'] > 0
    return config


@pytest.fixture
def browser(config):
    if config['browser'] == 'Firefox':
        b = selenium.webdriver.Firefox()
    elif config['browser'] == 'Chrome':
        b = selenium.webdriver.Chrome()
    elif config['browser'] == 'Headless Chrome':
        opts = selenium.webdriver.ChromeOptions()
        opts.add_argument('headless')
        b = selenium.webdriver.Chrome(options=opts)
    else:
        raise Exception(f'Browser "{config["browser"]}" is not supported')

    b.implicitly_wait(config['implicit_wait'])
    yield b
    b.quit()

And config.json will look like

{
  "browser": "Headless Chrome",
  "implicit_wait": 10
}

I do see fixtures in pytest_playwright.py - so I assume that those configurable through CLI could be moved into conftest.py file

[Feature] launch/context arguments

Thought about an fixture which is called something like new_context and new_page.

Usage:

@pytest.mark.asyncio
async def test_hello_default(new_page):
    page = await new_page(foo=True)
    await page.setContent('<span id="foo">bar</span>')
    assert await page.querySelector("#foo")
@pytest.mark.asyncio
async def test_hello_default(new_context):
    context = await new_context(foo=True)
    ...

[tests] enhance unit tests

Testing the following cases:

  • Using launch arguments
  • is_XXX fixtures
  • browser_name fixture
  • custom goto
  • Using context arguments
  • Using CLI argument: --browser
  • Using CLI argument: --headless
  • skip / only browser fixture

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.