【问题标题】:Not able to Extend RobotFramework SeleniumLibrary无法扩展 RobotFramework SeleniumLibrary
【发布时间】:2018-05-27 16:13:55
【问题描述】:

我正在尝试扩展 RobotFramework SeleniumLibrary:

class ReusableModule(SeleniumLibrary):

    ROBOT_LIBRARY_SCOPE = 'GLOBAL'

    def __init__(self, timeout=0.5, implicit_wait=15.0, **kwargs):
        logger.info("Reusable __init__")
        SeleniumLibrary.__init__(self, timeout=timeout, implicit_wait=implicit_wait, **kwargs)

    @keyword
    def open_browser(self, url, browser=env.capabilities.get("browserName"), alias=None, remote_url=env.host,
                     desired_capabilities=env.capabilities, ff_profile_dir=None):
        logger.info("Reusable open browser")
        return super(ReusableModule, self).open_browser(url=url, browser=browser, alias=alias, remote_url=remote_url,
                                                        desired_capabilities=desired_capabilities,
                                                        ff_profile_dir=ff_profile_dir)

当我在 RobotFramework Test 中调用此关键字时出现以下错误:

AttributeError: 'super' object has no attribute 'open_browser'

注意:这在过去适用于 Selenium2Library。

【问题讨论】:

  • 是的,新的 SeleniumLibrary 完全用某种动态 api 重新实现,使其更难(或至少没有记录)扩展。

标签: python python-2.7 selenium robotframework


【解决方案1】:

这已添加到 RFW SeleniumLibrary 文档 16.01.2018: Extending SeleniumLibrary

from SeleniumLibrary import SeleniumLibrary
from SeleniumLibrary.base import keyword

class ExtendedSeleniumLibrary(SeleniumLibrary):
    @keyword
    def test(self):
        return "Extended SeleniumLibrary keyword"

【讨论】:

    猜你喜欢
    • 2019-11-29
    • 2017-04-16
    • 2019-01-18
    • 2021-07-15
    • 2013-02-24
    • 2019-06-04
    • 2020-08-18
    • 2012-04-10
    • 1970-01-01
    相关资源
    最近更新 更多