【问题标题】:Return Value from Method in Python using Robot Framework使用机器人框架从 Python 中的方法返回值
【发布时间】:2018-10-03 14:54:20
【问题描述】:

所以可以说我在python中有这个方法

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

然后我有另一种方法来接收事件并获取该事件的值。

def verify_singal_r():
    with Session() as session:
        connection = Connection("http://example/signalr", session)
        print(connection)
        logging.info("got the connection")
        presenceservice = connection.register_hub('MyHub')
        connection.start()
        def print_error(error):
            print('error: ', error)


        connection.error += print_error

        # TODO: NEED TO ADD POST REQUEST HERE
        presenceservice.client.on('Notified', get_data)
        connection.wait(10)

一旦关键字 Verify_Signal 运行,我就会得到我需要的值并将它们打印到控制台上

如何在机器人框架中使用get_data 的值?

我试着简单地使用

*** Test Cases ***

Get Event Back
     verify_singal_r
     get_data

但这不起作用,因为 get_data 需要一个参数。

【问题讨论】:

    标签: python selenium robotframework


    【解决方案1】:

    你的功能

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

    期待一个参数

    但是当你在机器人框架中调用它时

    *** Test Cases ***
    
    Get Event Back
         verify_singal_r
         get_data
    

    你没有提供任何论据。

    你可以试试这样的

    *** Variables ***
    ${notification}    Test
    *** Test Cases ***
    
    Get Event Back
         verify_singal_r
         get_data    ${notification}
    

    这将解决您的问题。

    【讨论】:

    • 我用了你的例子,但我只是得到Notification Recived: 我怎样才能得到python脚本中生成的值?
    • 那么在你的python函数中你需要返回一些东西。
    • 经过一番调试,我发现get data在信号被验证后被调用,这使得它“空”,我如何从verify signal r关键字中获取返回值?
    【解决方案2】:

    你的方法

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

    不返回任何内容,因此机器人框架关键字也不会返回任何内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-21
      • 1970-01-01
      • 2021-04-13
      相关资源
      最近更新 更多