问题
I have written a Robot test case which takes input list from command line. I ran the test case from command line and it executed successfully. All the issue comes when i run the same script from Eclipse, the test case fails and gives a console message -
'List variable '@{list_of_vars}' has no item in index 0.'
Below is my code -
[Tags] TestCLI
@{list_of_vars} Split String ${my_vars}
Log @{list_of_vars}[0]
Log @{list_of_vars}[1]
Syntax used for executing test case from command line:
python -m robot -v my_vars:one,two -E space:, -t "TestCLI" C:\Users\user1\eclipse-workspace\RobotTests\robot\firstTest.robot
I understood that @{list_of_vars} is looking for input elements when running the test case from eclipse. I have used Run and Start Process keywords to start the command line and couldn't succeed. Is there any way to resolve the error and run the same script from eclipse.
Additional details -
- Robot framework version - 3.0.2,
- Eclipse oxygen,
- Python version 3.6.4,
- RED Editor 0.8.3.2018xxx
回答1:
When running your example I was not able to replicate your results. Instead I observe the desired behavior. Below are the settings I used.
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]
The additional command line variables -v my_vars:one,two -E space:,
need to be set on the run configuration.
This then results in the following message log:
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
And console log. I've seperated the command into seperate lines and removed some of the --listener
folder path for readability.
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
来源:https://stackoverflow.com/questions/49654291/how-to-execute-robot-testcase-from-eclipse-which-takes-command-line-list-argumen