Python3行为Web驱动程序-OOP传递驱动程序

Python3行为Web驱动程序-OOP传递驱动程序,python,selenium,selenium-webdriver,python-behave,Python,Selenium,Selenium Webdriver,Python Behave,因此,我一直在努力使我的项目更加面向对象,但我很难让驱动程序在python文件之间传递 TestAutomation/ Features/ somefeature.feature Objects/ main_misc.py Steps/ actionwords.py steps.py Tools/ AutoTools.py environment.py 环境.py class

因此,我一直在努力使我的项目更加面向对象,但我很难让驱动程序在python文件之间传递

TestAutomation/
    Features/
        somefeature.feature
    Objects/
        main_misc.py
    Steps/
        actionwords.py
        steps.py
    Tools/
        AutoTools.py
    environment.py
环境.py

class DriverSetup:
    def get_driver():
        ...
        return webdriver.Firefox(executable_path=path)

def before_all(context):
        driver = DriverSetup.get_driver()
        context.actionwords = Actionwords()
        base_url = ''
        driver.get(base_url)
        AutoTools.Navigation.wait_for_page_to_load(driver)
自动工具.py

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

    @staticmethod
    def wait_for_page_to_load(self):
        old_page = self.driver.find_element_by_tag_name('html')
我只给了足够的地方,它得到的错误,它会击中的步骤。在调试中,Self有一个带有正确url的url,甚至还有一个窗口句柄
当我进入时,它返回到environment.py来运行hook exception-“WebDriver”对象没有属性“driver”

出现此错误的原因是,当调用
wait\u for\u page\u to\u load(self)
方法时,您正在访问
driver
属性。也就是说,当您将Firefox webdriver传递给该方法时,
self
指的是Firefox webdriver,因此它试图访问Firefox webdriver的
driver
属性,这是不正确的

你需要做的是实例化一个
Navigation
对象,这样
self
指的是所述对象,
self.driver
指的是你传递的Firefox驱动程序。从您的代码中,我希望看到如下内容:

def before_all(context):
    # These 4 lines are independent of the Navigation class
    driver = DriverSetup.get_driver()
    context.actionwords = Actionwords()
    base_url = ''
    driver.get(base_url)

    # These 2 lines are dependent on the Navigation class
    # On the right, the Navigation object is instantiated
    # On the left, the object is initialized to the navigation_driver variable
    navigation_driver = AutoTools.Navigation(driver)

    # After, you can call your method since the object's self.driver
    # was instantiated in the previous line and properly refers to the Firefox webdriver
    navigation_driver.wait_for_page_to_load()

什么是
测试自动化
行?这是命令吗?如果是,为什么有单破折号、双破折号和三破折号?