【问题标题】:Robot Framework - return a value from custom keywordRobot Framework - 从自定义关键字返回一个值
【发布时间】:2018-10-11 00:00:57
【问题描述】:

我有这个问题,我需要返回由我创建的自定义关键字生成的值。

我有两个关键字 Get DataVerify Signal R 我在 Verify Signal R 关键字中生成一个调用 Get data 函数的值,我需要验证我收到的某种消息是代码

def get_data(notificaition):
    print("Notification Recived: ", notificaition)
    return notificaition

def verify_signal_r():

    print(connection)
    presenceservice1.client.on('StaffPresenceNotified', get_data)
    connection.wait(15)
    return presenceservice1

然后是我的关键字

*** Variables ***

${Notification}

*** Keywords ***

Verify Notification Was Displayed
    get connection
    Doctor Has Entered The Room
    verify signal r
    get data  ${Notification}

然后是我的日志

如您所见,我在 Verify Singal R 关键字中打印消息,但获取数据为空,如何从 python 方法/关键字返回值?

EDIT 我在 Verify Signal R 中打印消息,但是当我尝试调用 get data 时,它会打印出消息,我得到一个空字段您可以在我的日志中看到那是因为get data 使用来自Verify Signal R 的生成值,如果我只是按预期调用get data 方法,它是空的,我正在尝试验证get data 不为空并且我收到一条消息从服务器返回。

希望它更清楚

【问题讨论】:

  • 您好,您能重新表述一下您的问题吗?我不确定你有什么问题。
  • @JaPyR 我已经编辑了问题

标签: python return-value robotframework


【解决方案1】:

您需要使用Log 关键字来打印日志中的值。 http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Log

【讨论】:

    【解决方案2】:

    我可能很难理解您的问题,因为我没有看到任何奇怪的行为。我会从头开始。

    1. 关键字get data 不打印任何内容,因为${Notification} 变量从一开始就是空的,并且从未被修改过。
    2. 我假设在关键字verify signal r 的情况下,您有Notification received: {....},因为presenceservice1.client.on('StaffPresenceNotified', get_data) 调用get_data 带有一些参数

    【讨论】:

      【解决方案3】:

      我已通过创建另一种方法并使用global 传递数据来解决此问题

      def get_data(self, notification):
          global var2
          var2 = notification
          print("Message Received From Client!")
      
      
      def print_data(self):
      
          print(var2)
      

      【讨论】:

        【解决方案4】:

        我不确定你是否想要这个。 只需在您的关键字前面添加 ${data}= (有/无 '=' 都可以)

        *** Keywords ***
        
        Verify Notification Was Displayed
            get connection
            Doctor Has Entered The Room
            verify signal r
            ${data}=  get data  ${Notification}
            Log  ${data}
        

        【讨论】:

          猜你喜欢
          • 2018-06-24
          • 2019-01-13
          • 2011-11-26
          • 2015-10-09
          • 2017-06-05
          • 1970-01-01
          • 2019-11-02
          • 2015-09-09
          • 2016-11-21
          相关资源
          最近更新 更多