【问题标题】:Using ScreenshotKeywords from SeleniumLibrary使用 SeleniumLibrary 中的 ScreenshotKeywords
【发布时间】:2018-04-23 06:04:56
【问题描述】:

我正在尝试创建一个自定义 python 库,我可以将它与RobotFramework 一起使用来运行我的测试。到目前为止,我只在我的代码中使用capture_page_screenshot() 方法时遇到了问题。我似乎无法找出调用该函数的正确方法。

我该如何解决这个问题?

from SeleniumLibrary import ScreenshotKeywords

def screenshot():
    ScreenshotKeywords.capture_page_screenshot()

【问题讨论】:

    标签: python selenium robotframework


    【解决方案1】:

    最简单的方法是获取对已由您的套件导入的 selenium 库的引用,然后在该实例上调用关键字。您可以使用内置关键字 get library instance 获取对该库的引用

    from robot.libraries.BuiltIn import BuiltIn
    
    def screenshot():
        se2lib = BuiltIn().get_library_instance("SeleniumLibrary")
        se2lib.capture_page_screenshot()
    

    【讨论】:

      猜你喜欢
      • 2021-04-22
      • 2022-01-27
      • 2019-01-18
      • 2020-08-18
      • 2020-01-20
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      • 2019-11-29
      相关资源
      最近更新 更多