简体   繁体   English

使用Robot Framework从Python中的方法返回值

[英]Return Value from Method in Python using Robot Framework

So lets say i have this method in python 所以可以说我在python中有这个方法

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

And then i Have another method that recives a event and gets the value of that event. 然后我有另一种方法来接收一个事件并获取该事件的值。

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)

Once the Keyword Verify_Signal runs I get the values I need and i print them onto the console 关键字Verify_Signal运行后,我会得到所需的值并将其打印到控制台上

How can I use the value of the get_data in robot framework? 如何在机器人框架中使用get_data的值?

I tried to simply use 我试图简单地使用

*** Test Cases ***

Get Event Back
     verify_singal_r
     get_data

But that does not work as get_data expects an argument. 但这不起作用,因为get_data需要一个参数。

your function 你的职能

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

Expects an argument 期待一个论点

However when you are calling this in robot framework 但是,当您在机器人框架中调用此命令时

*** Test Cases ***

Get Event Back
     verify_singal_r
     get_data

You are not providing any argument to it. 您没有提供任何参数。

You can try something like this 您可以尝试这样的事情

*** Variables ***
${notification}    Test
*** Test Cases ***

Get Event Back
     verify_singal_r
     get_data    ${notification}

This will solve your problem. 这样可以解决您的问题。

Your method 你的方法

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

does not return anything, so robot framework keyword will not return anything too. 不返回任何内容,因此robot框架关键字也不会返回任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM