【问题标题】:how to pass values from python code to variable of robot framework如何将值从python代码传递到机器人框架的变量
【发布时间】:2017-06-06 20:30:25
【问题描述】:

我是机器人框架的初学者。我想将python文件中的值传递给机器人框架的变量,但仍然无法成功。

globe.py是我的python文件,很简单。

a = 'this is testing'

下面是机器人所需的测试用例配置

*** Setting ***
|Variables|globe.py

*** Variables ***
|${myTest}|${a}

但是机器人抛出错误:

“文件错误:设置变量 '${myTest}' 失败:找不到变量 '${a}'。”

您能对此提出一些建议吗?

here is screen about my execution steps and result

【问题讨论】:

  • @A. Kootstra,我像你一样修改了我的配置,使用了制表符分隔的方法,仍然无法工作。添加有关我的执行步骤和结果的屏幕,请查看。

标签: robotframework


【解决方案1】:

在我看来,您的示例确实有效。我使用制表符分隔的方法,但这不应该是原因。

*** Setting ***
Variables   globe.py

*** Variables ***
${myTest}   ${a}

*** Test Cases ***
A Test Case
     Log To Console    ${myTest}

这导致了 Robot Framework 的响应,这似乎是您正在寻找的。​​p>

Suite Executor: Robot Framework 3.0 (Python 2.7.9 on win32)
==============================================================================
MyLibrary                                                                     
==============================================================================
MyLibrary.Test                                                                
==============================================================================
A Test Case                                                           this is testing
| PASS |
------------------------------------------------------------------------------
MyLibrary.Test                                                        | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
MyLibrary                                                             | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================

【讨论】:

    【解决方案2】:

    您也可以尝试在使用前导入变量.py文件..

    Import Library   <yourPythonFile.py>
    #use variables from python variables file after successful import..
    

    【讨论】:

      【解决方案3】:

      另一种解决方法是使用 --variablefile 选项的 robotsframework。

      Test_varaibles.robot

      *** Settings ***
      *** Variables ***
      *** Test Cases ***
      print message to console
        print msg
      *** Keywords ***
      print msg
        log to console ${msg}
      

      在python文件中声明一个变量msg

      variable.py

      msg='Hello!! This is First msg!'
      

      要传递变量文件,我们需要将–variablefile 或-V 作为命令行参数传递给pybot

      在命令下运行

      pybot -V variable.py Test_variables.robot
      

      结果

      更多描述性细节,你也可以参考下面

      https://automationlab0000.wordpress.com/2018/11/20/how-to-pass-python-variable-file-in-robotframework/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-23
        • 1970-01-01
        • 2023-03-27
        • 2019-04-07
        • 2017-07-31
        相关资源
        最近更新 更多