0

Below is code of my framework for testing which I am building, but I am getting the error 'TestLogin' object has no attribute 'driver'.

Confest.py code:

import pytest
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait

driver = None


def pytest_addoption(parser):
    parser.addoption(
        "--browser_name", action="store", default="chrome",
    )


@pytest.fixture(scope="class")
def setup(request):
    """
      hdhdhdh
    """
    browser_name = request.config.getoption("--browser_name")
    if browser_name == "chrome":
        driver = webdriver.Chrome(executable_path='C:/Users/Devesh/PycharmProjects/E-mandi/Drivers/chromedriver.exe')
    elif browser_name == "firefox":
        driver = webdriver.Firefox(executable_path='C:/Users/Devesh/PycharmProjects/E-mandi/Drivers/geckodriver.exe')
        driver.get('http://www.facebook.com/login') (for example not real url)
        driver.maximize_window()
        driver.delete_all_cookies()
        request.cls.driver = WebDriverWait(driver, 30)
        request.cls.driver = driver
    yield
    driver.close()

BaseClass:

import pytest


@pytest.mark.usefixtures("setup")
class BaseClass:
    pass

LoginPage:

from selenium.webdriver.common.by import By


class LoginPage:

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

    mobile = (By.CSS_SELECTOR, "input.ng-untouched.ng-pristine.ng-invalid")

    def loginclick(self):
        return self.driver.find_element(*LoginPage.mobile)

test_main:

from Pageobjects.LoginPage import LoginPage
from Utilities.BaseClass import BaseClass


class TestLogin(BaseClass):
    def test_01_login(self):
        loginpage = LoginPage(self.driver)
        loginpage.loginclick().click()
6
  • there is no global variable to access as self.driver ,
    – PDHide
    Jun 8, 2020 at 10:07
  • can specify where i missed it and in which file cuz i cant debugg this? Jun 8, 2020 at 11:17
  • in test_main: whch is the self.driver?
    – PDHide
    Jun 8, 2020 at 11:30
  • in test main self.driver is a value(driver is value) which i am passing tom constructor in class Loginpage to make coneection call method of loginclick() from the Loginpage class. Jun 8, 2020 at 14:39
  • wer r u getting that value from ? There is no variable decalred in testlogin class
    – PDHide
    Jun 8, 2020 at 14:59

0

Your Answer

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

Browse other questions tagged or ask your own question.