如何在机器人框架中存储 python 函数的结果并在 Reports 中显示?

How to store the result of a python function in robot framework and display it in Reports?

我正在测试一个使用蓝牙的应用程序, 我有一个 python 函数,可以将它连接到服务器并显示一些字符串。 我想将该字符串存储在变量中并将其与其他字符串进行比较。

我已将结果存储在结果变量中,但可以使用它来比较字符串

*** Settings ***
Library         AppiumLibrary     run_on_failure=Capture Page Screenshot
Library         String
Library         bt.py
*** Variable ***
${appium_1}=     http://0.0.0.0:4723/wd/hub
${platform_name}=    android
${platformVersion}=         9
${deviceName}=          b6722e70
${app}=      /home/user/Downloads/pre-prod.apk
${result}
*** Test Cases ***
App_Test_1
[Documentation]    Test Case to Login
Open Application        ${appium_1}     
platformName=${platform_name}       deviceName=${deviceName}        
app=${app}     
Capture Page Screenshot
Click Element   id=com.vendekin:id/intro_btn_skip
Sleep   4
Wait Until Element Is Visible   id=com.vendekin:id/phone
input text      id=com.vendekin:id/phone    
Click Element   id=com.vendekin:id/login
Sleep   5
Wait Until Element Is Visible   id=com.vendekin:id/otp  
Click Element   id=com.vendekin:id/otp
sleep  15
Wait Until Element Is Visible   id=com.vendekin:id/login
Click Element   id=com.vendekin:id/login
Sleep   6
Input Text  id=com.vendekin:id/promocode    010331
sleep   2
click element   id=com.vendekin:id/add
${result}=           connect     29476601-52BE-11CB-8642-D50A896F8D2A
log  ${result}
capture page screenshot
quit application

我预计函数的输出将作为字符串存储在结果中进行比较,但它显示 "None"

要让变量获得函数的 return 值,该函数首先必须 return 它。获得 None 意味着您的函数没有(或 return 是文字 None :)。

所以connect一定是这样的:

def connect(data):
    output = does_its_magic(data)
    return output