python - 如何从 eclipse 执行 Robot 测试用例,它将命令行列表参数作为输入?

标签 python eclipse robotframework

我编写了一个机器人测试用例,它从命令行获取输入列表。我从命令行运行测试用例并且执行成功。 当我从 Eclipse 运行相同的脚本时,所有问题都会出现,测试用例失败并给出控制台消息 -

'List variable '@{list_of_vars}' has no item in index 0.'

下面是我的代码 -

[Tags]    TestCLI   
    @{list_of_vars}    Split String    ${my_vars}
    Log   @{list_of_vars}[0]
    Log   @{list_of_vars}[1]

用于从命令行执行测试用例的语法:

python -m robot -v my_vars:one,two -E space:, -t "TestCLI" C:\Users\user1\eclipse-workspace\RobotTests\robot\firstTest.robot

我了解到 @{list_of_vars} 在从 eclipse 运行测试用例时正在寻找输入元素。我已使用“运行”和“启动进程”关键字来启动命令行,但无法成功。 有什么方法可以解决该错误并从 eclipse 运行相同的脚本吗?

其他详细信息 -

  1. 机器人框架版本 - 3.0.2,
  2. eclipse 氧气,
  3. Python 版本 3.6.4,
  4. RED 编辑器 0.8.3.2018xxx

最佳答案

运行您的示例时,我无法复制您的结果。相反,我观察到了所需的行为。以下是我使用的设置。

firstTest.robot

*** Settings ***
Library    String    

*** Test Cases ***

TC
    [Tags]    TestCLI   
    Log    ${my_vars}
    @{list_of_vars}    Split String    ${my_vars}
    Log   @{list_of_vars}[0]
    Log   @{list_of_vars}[1]

需要在运行配置上设置附加命令行变量-v my_vars:one,two -E space:,enter image description here

这会产生以下消息日志:

Starting test: RunWithVars.firstTest.TC
20180404 20:45:06.445 : INFO : one two
20180404 20:45:06.447 : INFO : @{list_of_vars} = [ one | two ]
20180404 20:45:06.448 : INFO : one
20180404 20:45:06.449 : INFO : two
Ending test: RunWithVars.firstTest.TC

控制台日志。我已将命令分成单独的行,并删除了一些 --listener 文件夹路径以提高可读性。

Command: C:\Python\RF_P27\Scripts\python.exe 
 -m robot.run 
 --listener C:\Users\..\TestRunnerAgent.py:51805 
 -s RunWithVars.FirstTest 
 -v my_vars:one,two -E space:, C:\TA\W\StackOverflow\RunWithVars
Suite Executor: Robot Framework 3.0.2 (Python 2.7.13 on win32)
==============================================================================
RunWithVars                                                                   
==============================================================================
RunWithVars.firstTest                                                         
==============================================================================
TC                                                                    | PASS |
------------------------------------------------------------------------------
RunWithVars.firstTest                                                 | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
RunWithVars                                                           | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output:  C:\TA\W\StackOverflow\RunWithVars\output.xml
Log:     C:\TA\W\StackOverflow\RunWithVars\log.html
Report:  C:\TA\W\StackOverflow\RunWithVars\report.html

关于python - 如何从 eclipse 执行 Robot 测试用例,它将命令行列表参数作为输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49654291/

相关文章:

python - Spark - 如何从数据集中提取 n 行?

python - "Expected type ' Union[str, bytearray] ' got ' int ' instead"write 方法警告

python - Matplotlib 中的非线性第二轴

eclipse - 如何自定义 Eclipse 工具栏(Kepler 或一般)

java - 简而言之,主要功能行为 - 一个源文件中的多个类

windows-7 - 在 Windows 7 上使用 Python 安装 Robot Framework 时发生错误

python - 如何获取 Robotframework 测试套件中所有测试用例的名称

python - 数据类和属性装饰器

tags - 如何在pycharm机器人框架中基于标签运行测试用例

java - 经典错误 : Unable to update index for central|http://repo1. maven.org/maven2