【问题标题】:edge driver is not getting installed using robotframework没有使用机器人框架安装边缘驱动程序
【发布时间】:2022-01-08 05:29:10
【问题描述】:

我们正在使用 Python 机器人框架自动化。是否可以在脚本运行时根据作为参数传递的版本自动下载和安装边缘驱动程序?我们使用的是 selenium 3.14、机器人框架 selenium 库 4.5.0 和 python 3.7

【问题讨论】:

    标签: python selenium robotframework


    【解决方案1】:

    不,这是不可能的。任何 webdriver 的安装都必须在运行测试之前完成,因为它需要为 webdriver 准备好环境变量 PATH 和适当的执行权限。

    【讨论】:

      【解决方案2】:

      是否可以在脚本运行时根据作为参数传递的版本自动下载和安装边缘驱动程序?

      回答-是的

      为此,您需要使用 - pip install webdriver-manager 安装驱动程序管理器

      然后使用以下导入 -

      from selenium import webdriver
      from webdriver_manager.microsoft import EdgeChromiumDriverManager
      

      您可以在机器人框架中使用 python 函数作为关键字,如下所示。其中96.0.1054.43 参数是边缘驱动程序的版本。这个函数是写在让我们说 - drivermanager.py 文件中的。

      def get_chromedriver_path():
          driver_path = EdgeChromiumDriverManager("96.0.1054.43").install()
          print(driver_path)
          return  driver_path
      

      您可以使用命令 - Library drivermanager.py 在您的测试套件中导入这个 (drivermanager.py) 库。该函数在执行时将被视为关键字。

      Testsuite 将有测试用例

      Open Chrome Browser
          [Documentation]      To create chrome browser instance with specific profile
      
          ${chromedriver_path}=   drivermanager.Get Chromedriver Path
      

      这里${chromedriver_path} 变量保存驱动程序路径。以及存储在缓存中的驱动程序。

      执行截图 -

      参考资料 - 1. https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ 2.https://github.com/SergeyPirogov/webdriver_manager

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-10-09
        • 2013-01-26
        • 1970-01-01
        • 1970-01-01
        • 2022-10-18
        • 2019-05-24
        • 1970-01-01
        相关资源
        最近更新 更多