0

I am trying to run some script in headed mode from command line but its always running in headless mode. The thing is when I am directly running the class from the pycharm IDE, its successfully running in headed mode but unable to do the same when running from command line using any of the following settings.

I have my pytest.ini file like below

[pytest]
addopts = --html=report/report.html --self-contained-html --reruns 0 --reruns-delay 0 -v --browser chromium --headed --slowmo 2000

I have the conftest file as below

def pytest_addoption(parser):
    parser.addoption("--headed", action="store_true", default=True, help="Run browser in headed mode")


    @pytest.fixture(scope="session")
    def playwright():
        with sync_playwright() as playwright_instance:
            yield playwright_instance
    
    
    @pytest.fixture(scope="session")
    def browser(playwright):
        browser = playwright.firefox.launch(headless=False)  # Set headless=True for headless mode
        yield browser
        browser.close()
    
    
    @pytest.fixture(scope="function")
    def browser_context(browser):
        context = browser.new_context()
        yield context
        context.close()
    
    
    @pytest.fixture(scope="function")
    def set_up_tear_down(browser_context):
        page = browser_context.new_page()
        page.set_viewport_size({"width": 1536, "height": 800})
        page.goto("https://www.saucedemo.com/")
        yield page
        page.close()

Command:

py -m pytest -v -s test_place_order.py --headed

Is there any hidden configurations which I need to modify to achieve running the tests in headed mode using command line?

1
  • Are you using pytest-playwright plugin? Commented Jul 31, 2024 at 11:37

1 Answer 1

0
    @pytest.fixture(scope="session")
    def browser(playwright):
        headless_mode = request.config.getoption("--headed")
        browser = playwright.firefox.launch(headless=headless_mode)  # Set headless=True for headless mode
        yield browser
        browser.close()

[pytest]
addopts = 
    --html=report/report.html 
    --self-contained-html 
    --reruns 0 
    --reruns-delay 0 
    -v 
    --browser chromium 
    --headed=1
    --slowmo 2000
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.