使用 webdriver-manager 指定用于 Dash 应用程序测试的本地 Chromedriver 路径

问题描述 投票:0回答:2

我正在尝试利用测试 Dash 应用程序,如下所述:https://dash.plotly.com/testing

但是,我发现无法在 dash 测试的背后指定 webdriver-manager 的 Chromedriver 路径。

我在下面尝试了这个,在到达测试代码之前调用 webdriver-manager:

def test_bsly001_falsy_child(dash_duo):
    
    app = import_app("my_app_path")
    dash_duo.start_server(app)
然后

webdriver-manager 将开始下载最新的 Chrome 版本。但由于公司政策,我们不能只从互联网上下载东西,它被防火墙阻止了。我们应该使用已经在内网为我们下载的 Chromedriver。

我尝试在测试开始之前实现 pytest 固定装置来设置 Chrome 驱动程序:

driver = webdriver.Chrome(executable_path="...")

但是 webdriver-manager 不接受这一点。

您知道解决这个问题的方法吗?有什么提示吗? 有没有办法在没有 webdriver-manager 的情况下进行 Dash 测试?

谢谢。

python selenium testing pytest plotly-dash
2个回答
0
投票

我遇到了类似的问题,最终得到了另一个 pytest 固定装置

dash_duo_bis
,它在
class DashComposite(Browser)
内使用另一个
conftest.py
,其中
_get_chrome
方法被重写,如下所示:

class DashComposite(Browser):

    def __init__(self, server, **kwargs):
        super().__init__(**kwargs)
        self.server = server

    def get_webdriver(self):
        return self._get_chrome()

    def _get_chrome(self):
        return webdriver.Chrome(executable_path = r"MY_CHROME_EXECUTABLE_PATH")

    def start_server(self, app, **kwargs):
        """Start the local server with app."""

        # start server with app and pass Dash arguments
        self.server(app, **kwargs)

        # set the default server_url, it implicitly call wait_for_page
        self.server_url = self.server.url

0
投票

我也有同样的问题。最后,我只是将 Chromedriver 包含在 PATH 中,然后运行测试。如果您按照以下步骤操作,它应该可以工作:

export PATH=$PATH:<path to your chromedriver>
pytest <path to your folder containing your test scripts>
© www.soinside.com 2019 - 2024. All rights reserved.