1

I try to create the project with page object(python 3.9) and my conftest.py file doesn't receive any driver from its pages. Any page has _init constructors,but in the conftest.py file we can see that no driver is given. I will be glad if you have any conclusions...

Functions of conftest.py

import time

import pytest as pytest
from selenium import webdriver

from src.pom import settings
from src.pom.pages.BasePage import BasePage
from src.pom.pages.LoginPage import LoginPage

# from pytest_lazyfixture import lazy_fixture

driver = None


def pytest_addoption(parser):
    # parser.addoption("--browser", action="store", default="chrome")
    parser.addoption("--browser", action="store", default=settings.browser)
    parser.addoption("--env", action="store", default=settings.env)


@pytest.fixture()
# @lazy_fixture
def getBrowser(request):
    _browser = request.config.getoption("--browser")
    return _browser


@pytest.fixture()
def getDriver(request, getBrowser):
    global driver
    print("browser from getBrowser method - " + getBrowser)
    if getBrowser == "chrome":
        driver = webdriver.Chrome("C:\\Tools\\chromedriver\\chromedriver.exe")

    driver.get(settings.url)
    driver.implicitly_wait(20)
    driver.maximize_window()
    request.cls.basePage = BasePage(driver)
    request.cls.loginPage = LoginPage(driver)
    request.cls.driver = driver
    # yield request.cls.driver
    yield driver
    time.sleep(2)
    driver.quit()

Functions from BasePage(as example):

class BasePage:
    def __int__(self,driver):
        self.driver = driver
        self.wait = WebDriverWait(self.driver, 10)

    def do_click(self, by_locator):
        # self.wait.until(EC.visibility_of_element_located(by_locator)).click()
        self.wait.until(EC.presence_of_element_located(by_locator)).click()

Functions from LoginPage(as example):

from selenium.webdriver.common.by import By

from src.pom.pages.BasePage import BasePage


class LoginPage(BasePage):

    def __int__(self, driver):
        super().__int__(driver)
        self.driver = driver

    EMAIL = (By.ID, "login-email")
    PASSWORD = (By.ID, "login-password")
    LOGIN_BUTTON = (By.CSS_SELECTOR, "div [type='submit']")
    CAMPUS_LOGO = (By.CSS_SELECTOR, ".logo")

Eventually I get the error:

  request.cls.basePage = BasePage(driver)

E TypeError: BasePage() takes no arguments

I have tried to work with this structure of page object in python but I failed. I have expected to run tests that began to write.

Romanich
  • 29
  • 4

0 Answers0