Python Forum
Fixture not returning webdriver element - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Fixture not returning webdriver element (/thread-41943.html)



Fixture not returning webdriver element - Nik1811 - Apr-12-2024

Hi,
I've added a new fixture to return webdriver and access it within my 'Login' method. I'm receiving the below error as webdriver is not returned, instead a funtion object is returned.
Can someone please help with the best practices to add fixtures?

My end goal is : To add fixtures to conftest.py and access chrome/firefox driver for every login method in each case

test.py
import pytest
from selenium import webdriver
from utilities.settings import url
from pageObjects.Login import Login

@pytest.fixture
def driverChrome():
    driver = webdriver.Chrome()
    return driver


Login(driverChrome).loginToApp()
Login(driverChrome).setLoginValues()
Login.py
from utilities.settings import url, username, password, company_code
import pytest


class Login:
    textbox_username_id = "usercode"
    textbox_password_id = "mirror_password"
    textbox_companyCode_id = "companyCode"
    btn_login_xpath = "//input[@value='Login']"

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

    def loginToApp(self):
        self.driver1.get(url)
        self.driver1.maximize_window()

    def setLoginValues(self):
        self.driver1.find_element("id", self.textbox_username_id).send_keys(username)
        self.driver1.find_element("id", self.textbox_password_id).send_keys(password)
        self.driver1.find_element("id", self.textbox_companyCode_id).send_keys(company_code)
        self.driver1.find_element("xpath", self.btn_login_xpath).click()
        self.driver1.save_screenshot(".\\screenshots\\"+"setLoginValues.png")
Error:
Error:
Traceback (most recent call last): File "C:\Users\Nikita\PycharmProjects\thymeit_auto_base\testCases\test.py", line 15, in <module> Login(driverChrome).loginToApp() File "C:\Users\Nikita\PycharmProjects\thymeit_auto_base\pageObjects\Login.py", line 15, in loginToApp self.driver1.get(url) ^^^^^^^^^^^^^^^^ AttributeError: 'function' object has no attribute 'get'



RE: Fixture not returning webdriver element - Nik1811 - Apr-15-2024

@snippsat: Would you be able to please help on this one?