代码之家  ›  专栏  ›  技术社区  ›  AutoTester213

Robot框架-从自定义关键字返回值

  •  0
  • AutoTester213  · 技术社区  · 6 年前

    Get Data Verify Signal R 验证信号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}
    

    然后是我的日志

    enter image description here

    如您所见,我在Verify Singal R关键字中引用消息,但是get data为空。如何从python方法/关键字返回值?

    编辑 get data 它打印出一条消息,你可以在我的日志中看到,我得到一个空字段,这是因为 验证信号R

    希望这能让事情更清楚

    4 回复  |  直到 6 年前
        1
  •  0
  •   user1856001    6 年前

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

        2
  •  0
  •   JaPyR    6 年前

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

    1. 关键字 get data 什么也没印因为 ${Notification} 变量从一开始就是空的,从未被修改过。
    2. verify signal r 你有 Notification received: {....} presenceservice1.client.on('StaffPresenceNotified', get_data) 调用DES get_data
        3
  •  0
  •   AutoTester213    6 年前

    我通过创建另一个方法并使用 global

    def get_data(self, notification):
        global var2
        var2 = notification
        print("Message Received From Client!")
    
    
    def print_data(self):
    
        print(var2)
    
        4
  •  0
  •   Bob    6 年前

    我不确定你是否想要这个。 只需添加 在关键字前面(带/不带) '=' 都很好)

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