Python Forum
Fixture not returning webdriver element
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fixture not returning webdriver element
#1
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'
Reply
#2
@snippsat: Would you be able to please help on this one?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium Webdriver Python — ERR_NO_SUPPORTED_PROXIES TimofeyKolpakov 0 1,843 May-06-2023, 02:13 PM
Last Post: TimofeyKolpakov
  WebDriver' object has no attribute 'find_element_by_css_selector rickadams 3 5,986 Sep-19-2022, 06:11 PM
Last Post: Larz60+
  webdriver does not work wiki11 2 1,783 Dec-06-2021, 10:52 AM
Last Post: wiki11
  Multiple for loops selenium webdriver KRS 4 2,623 Mar-10-2020, 03:31 PM
Last Post: KRS
  Unable to locate element no such element gahhon 6 4,536 Feb-18-2019, 02:09 PM
Last Post: gahhon
  pytest fixture in conftest.py thrown error while in the test file runs OzzieOzzum 1 3,993 Jul-31-2018, 12:12 PM
Last Post: OzzieOzzum
  Change single element in 2D list changes every 1D element AceScottie 9 12,117 Nov-13-2017, 07:05 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020