[Python] TypeError: HomePage.click_signin() missing 1 required positional argument: 'self'...

Discussão em 'Python' iniciado por Stack, Abril 11, 2025.

  1. Stack

    Stack Membro Participativo

    My test launches the home page url with no issues but it cannot click the button, an error appears, TypeError: missing 1 required positional argument: 'self'. The error pertains to the test_pytestbddsteps.py file in the 6th image below, but I have included all the files in the project if they will help. Thanks

    [​IMG]

    orderTransaction.feature

    Feature: Transfer functionality

    Scenario: login
    Given I launch the application using the url
    And I click the Sign In button


    home.py

    from playwright.sync_api import expect, Page

    class HomePage:

    def __init__(self, page:page):
    self.page = page

    def navigate(self):
    self.page.goto("https://rahulshettyacademy.com/loginpagePractise/")

    def click_signin(self):
    self.page.locator("#SignIn").click()


    conftest.py

    import pytest

    def pytest_addoption(parser):
    parser.addoption(
    "--browser_name", action="store", default="chrome", help="browser selection"
    )
    parser.addoption(
    "--url_name", action="store", default="https://rahulshettyacademy.com/loginpagePractise/", help="server selection"
    )

    @pytest.fixture(scope="session")
    def user_credentials(request):
    return request.param

    @pytest.fixture
    def browserInstance(playwright, request):
    browser_name = request.config.getoption("browser_name")
    url_name = request.config.getoption("url_name")
    if browser_name == "chrome":
    browser = playwright.chromium.launch(headless=False)
    elif browser_name == "firefox":
    browser = playwright.firefox.launch(headless=False)

    context = browser.new_context()
    page = context.new_page()
    #page.goto(url_name)
    yield page
    context.close()
    browser.close()
    #2 times, 1st run opened browser and completed, homepage


    test_pytestbddsteps.py

    import pytest
    import time
    from pytest_bdd import given, when, then, scenarios, parsers

    from pageobjects.home import HomePage

    scenarios('features/coreFunctions.feature')

    @pytest.fixture
    def shared_data():
    return {}

    @given('I launch the application using the url')
    def launch_application(browserInstance):
    homePage = HomePage(browserInstance)
    homePage.navigate()
    time.sleep(2)

    @given(parsers.parse('I click the Sign In button'))
    def sign_in_button():

    #--does not work--
    #HomePage.click_signin()

    # --does not work--
    drive = HomePage()
    drive.click_signin()


    [​IMG]

    Continue reading...

Compartilhe esta Página