无法从命令行 运行 基于 Robot Framework 中的标记的测试用例

Unable to Run Testcases Based on Tag in Robot Framework form cmd line

今天,突然我的机器人Runner.py不工作了。基本上 Runner.py 包含 运行 我的基于标签的机器人测试用例的命令行命令。 每次 Runner.py 为 运行 时,将执行一个 requirements.txt 文件,其中的所有库将由 python 解释器安装。

cmd="pip install -r Requirements.txt --trusted-host files.pythonhosted.org --user"
os.system(cmd)

然后测试用例由 python 解释器 运行 使用:

cmd="robot -i RunNow -d ../Output/Execution_%s -P ../CustomLibrary/  --extension robot ../TestSuite "%(dts)
os.system(cmd)

报告生成使用:

cmd="python3 -m robotmetrics -R ExecutionMetrics -I ../Output/Execution_%s --logo  ../../Resources/logo.png  --ignorelib  ['OperatingSystem'] --ignoretype ['for']" %(dts)
os.system(cmd)

其中 RunNow 是我在测试用例中使用的标签,TestSuite 是我的文件夹,其中包含我的 .robot 测试文件。

直到昨天所有这些命令都运行良好,但今天它不起作用,我得到的第一个错误是

Requirement already satisfied: filelock<4,>=3.0.0 in c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages (from virtualenv>=1.11.2->tox==3.0.0->robotframework-jsonlibrary->-r Requirements.txt (line 4)) (3.0.12) [ ERROR ] Unexpected error: ValueError: not enough values to unpack (expected 3, got 1) Traceback (most recent call last): File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\utils\application.py", line 83, in _execute rc = self.main(arguments, **options) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\run.py", line 433, in main suite = builder.build(*datasources) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\running\builder\builders.py", line 45, in build suite = parser.parse(structure) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\running\builder\builders.py", line 93, in parse structure.visit(self) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\parsing\suitestructure.py", line 46, in visit visitor.visit_directory(self) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\parsing\suitestructure.py", line 165, in visit_directory child.visit(self) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\parsing\suitestructure.py", line 46, in visit visitor.visit_directory(self) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\parsing\suitestructure.py", line 165, in visit_directory child.visit(self) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\parsing\suitestructure.py", line 44, in visit visitor.visit_file(self) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\running\builder\builders.py", line 99, in visit_file suite, _ = self._build_suite(structure) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\running\builder\builders.py", line 129, in _build_suite suite = parser.parse_suite_file(source, defaults) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\running\builder\parsers.py", line 53, in parse_suite_file return self._build(suite, source, defaults) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\running\builder\parsers.py", line 64, in _build model = get_model(self._get_source(source), data_only=True, File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\parsing\parser\parser.py", line 45, in get_model tokens = get_tokens(source, data_only) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\parsing\lexer\lexer.py", line 46, in get_tokens lexer.input(source) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\parsing\lexer\lexer.py", line 82, in input for statement in Tokenizer().tokenize(self._read(source), File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\parsing\lexer\tokenizer.py", line 30, in tokenize tokens = self._tokenize_line(line, lineno, not data_only) File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\parsing\lexer\tokenizer.py", line 49, in _tokenize_line for value, is_data in splitter(rstrip(line)): File "c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages\robot\parsing\lexer\tokenizer.py", line 68, in _split_from_pipes _, separator, rest = splitter.split(line, 1) output.xml file is missing: C:\Users\kbhuva2\git\smartpra-qaautomation\Output\Execution_20200813_053058\output.xml

然后我尝试 pip freeze > file.txt 安装了所有库,通过命令卸载了所有库

cmd="pip uninstall -r file.txt"
os.system(cmd)

当我在命令提示符下运行 runner.py文件时,它首先卸载了file.txt中的所有库并安装了Requirements.txt中的所有库并结束了说

robot is not recognized as internal or external command robotframework, robotmetrics is not recognized as internal or external command robotframework

所以经过一些研究我更换了

cmd="robot -i RunNow -d ../Output/Execution_%s -P ../CustomLibrary/  --extension robot ../TestSuite "%(dts)

cmd="python3 -m robot -i RunNow -d ../Output/Execution_%s -P ../CustomLibrary/  --extension robot ../TestSuite "%(dts)

cmd="robotmetrics -R ExecutionMetrics -I ../Output/Execution_%s --logo  ../../Resources/logo.png  --ignorelib  ['OperatingSystem'] --ignoretype ['for']" %(dts)

cmd="python3 -m robotmetrics -R ExecutionMetrics -I ../Output/Execution_%s --logo  ../../Resources/logo.png  --ignorelib  ['OperatingSystem'] --ignoretype ['for']" %(dts)

现在,在进行此更改后,我没有收到机器人,或者 robotmetrics 未被识别为内部或外部命令 robotframework,但 **我的测试用例未根据标签拾取,实际上它只是执行安装所有库的命令在 Requirements.txt 并停止。

在 运行ning Runner.py 之后,我的命令提示符如下所示:

Requirement already satisfied: RESTinstance in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 1)) (1.0.2) Requirement already satisfied: robotframework in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 2)) (3.2.1) Requirement already satisfied: robotframework-metrics in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 3)) (3.1.6) Requirement already satisfied: robotframework-jsonlibrary in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 4)) (0.3.1) Requirement already satisfied: robotframework-jsonvalidator in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 5)) (2.0.0) Requirement already satisfied: robotframework-seleniumlibrary in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 6)) (4.5.0) Requirement already satisfied: robotframework-databaselibrary in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 7)) (1.2.4) Requirement already satisfied: robotframework-dependencylibrary in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 8)) (1.0.0.post1) Requirement already satisfied: robotframework-pabot in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 9)) (1.8.1) Requirement already satisfied: robotframework-datadriver in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 10)) (0.3.6) Requirement already satisfied: robotframework-csvlib in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 11)) (1.0.1) Requirement already satisfied: webdrivermanager in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 12)) (0.8.0) Requirement already satisfied: PyMySQL in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 13)) (0.10.0) Requirement already satisfied: pypyodbc in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 14)) (1.3.4) Requirement already satisfied: deepdiff in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 15)) (5.0.2) Requirement already satisfied: jsondiff in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 16)) (1.2.0) Requirement already satisfied: DateTimeRange in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 17)) (1.0.0) Requirement already satisfied: pypika in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 18)) (0.38.0) Requirement already satisfied: robotframework-excellib in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from -r Requirements.txt (line 19)) (2.0.1) Requirement already satisfied: tzlocal in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from RESTinstance->-r Requirements.txt (line 1)) (2.1) Requirement already satisfied: requests in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from RESTinstance->-r Requirements.txt (line 1)) (2.24.0) Requirement already satisfied: rfc3987 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from RESTinstance->-r Requirements.txt (line 1)) (1.3.8) Requirement already satisfied: flex in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from RESTinstance->-r Requirements.txt (line 1)) (6.14.1) Requirement already satisfied: pygments in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from RESTinstance->-r Requirements.txt (line 1)) (2.6.1) Requirement already satisfied: pytz in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from RESTinstance->-r Requirements.txt (line 1)) (2020.1) Requirement already satisfied: docutils in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from RESTinstance->-r Requirements.txt (line 1)) (0.16) Requirement already satisfied: jsonpath-ng in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from RESTinstance->-r Requirements.txt (line 1)) (1.5.1) Requirement already satisfied: strict-rfc3339 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from RESTinstance->-r Requirements.txt (line 1)) (0.7) Requirement already satisfied: jsonschema in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from RESTinstance->-r Requirements.txt (line 1)) (3.2.0) Requirement already satisfied: GenSON in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from RESTinstance->-r Requirements.txt (line 1)) (1.2.1) Requirement already satisfied: beautifulsoup4 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from robotframework-metrics->-r Requirements.txt (line 3)) (4.9.1) Requirement already satisfied: coverage in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from robotframework-jsonlibrary->-r Requirements.txt (line 4)) (5.2.1) Requirement already satisfied: jsonpath-rw-ext>=0.1.9 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from robotframework-jsonlibrary->-r Requirements.txt (line 4)) (1.2.2) Requirement already satisfied: tox==3.0.0 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from robotframework-jsonlibrary->-r Requirements.txt (line 4)) (3.0.0) Requirement already satisfied: jsonpath-rw==1.4.0 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from robotframework-jsonlibrary->-r Requirements.txt (line 4)) (1.4.0) Requirement already satisfied: pyjsonselect>=0.2.2 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from robotframework-jsonvalidator->-r Requirements.txt (line 5)) (0.2.2) Requirement already satisfied: objectpath>=0.5 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from robotframework-jsonvalidator->-r Requirements.txt (line 5)) (0.6.1) Requirement already satisfied: robotframework-pythonlibcore>=2.1.0 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from robotframework-seleniumlibrary->-r Requirements.txt (line 6)) (2.1.0) Requirement already satisfied: selenium>=3.141.0 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from robotframework-seleniumlibrary->-r Requirements.txt (line 6)) (3.141.0) Requirement already satisfied: tqdm in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from webdrivermanager->-r Requirements.txt (line 12)) (4.48.2) Requirement already satisfied: lxml in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from webdrivermanager->-r Requirements.txt (line 12)) (4.5.2) Requirement already satisfied: appdirs in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from webdrivermanager->-r Requirements.txt (line 12)) (1.4.4) Requirement already satisfied: setuptools in c:\users\kbhuva2\appdata\local\programs\python\python38\lib\site-packages (from pypyodbc->-r Requirements.txt (line 14)) (41.2.0) Requirement already satisfied: ordered-set>=4.0.1 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from deepdiff->-r Requirements.txt (line 15)) (4.0.2) Requirement already satisfied: typepy[datetime]<2,>=1.0.0 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from DateTimeRange->-r Requirements.txt (line 17)) (1.1.1) Requirement already satisfied: python-dateutil<3,>=2.4.2 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from DateTimeRange->-r Requirements.txt (line 17)) (2.8.1) Requirement already satisfied: openpyxl>=2.4.1 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from robotframework-excellib->-r Requirements.txt (line 19)) (3.0.4) Requirement already satisfied: certifi>=2017.4.17 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from requests->RESTinstance->-r Requirements.txt (line 1)) (2020.6.20) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from requests->RESTinstance->-r Requirements.txt (line 1)) (1.25.10) Requirement already satisfied: idna<3,>=2.5 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from requests->RESTinstance->-r Requirements.txt (line 1)) (2.10) Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from requests->RESTinstance->-r Requirements.txt (line 1)) (3.0.4) Requirement already satisfied: six>=1.7.3 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from flex->RESTinstance->-r Requirements.txt (line 1)) (1.15.0) Requirement already satisfied: PyYAML>=3.11 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from flex->RESTinstance->-r Requirements.txt (line 1)) (5.3.1) Requirement already satisfied: jsonpointer>=1.7 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from flex->RESTinstance->-r Requirements.txt (line 1)) (2.0) Requirement already satisfied: click>=3.3 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from flex->RESTinstance->-r Requirements.txt (line 1)) (7.1.2) Requirement already satisfied: validate-email>=1.2 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from flex->RESTinstance->-r Requirements.txt (line 1)) (1.3) Requirement already satisfied: decorator in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from jsonpath-ng->RESTinstance->-r Requirements.txt (line 1)) (4.4.2) Requirement already satisfied: ply in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from jsonpath-ng->RESTinstance->-r Requirements.txt (line 1)) (3.11) Requirement already satisfied: pyrsistent>=0.14.0 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from jsonschema->RESTinstance->-r Requirements.txt (line 1)) (0.16.0) Requirement already satisfied: attrs>=17.4.0 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from jsonschema->RESTinstance->-r Requirements.txt (line 1)) (19.3.0) Requirement already satisfied: soupsieve>1.2 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from beautifulsoup4->robotframework-metrics->-r Requirements.txt (line 3)) (2.0.1) Requirement already satisfied: pbr>=1.8 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from jsonpath-rw-ext>=0.1.9->robotframework-jsonlibrary->-r Requirements.txt (line 4)) (5.4.5) Requirement already satisfied: pluggy<1.0,>=0.3.0 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from tox==3.0.0->robotframework-jsonlibrary->-r Requirements.txt (line 4)) (0.13.1) Requirement already satisfied: virtualenv>=1.11.2 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from tox==3.0.0->robotframework-jsonlibrary->-r Requirements.txt (line 4)) (20.0.30) Requirement already satisfied: py>=1.4.17 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from tox==3.0.0->robotframework-jsonlibrary->-r Requirements.txt (line 4)) (1.9.0) Requirement already satisfied: mbstrdecoder<2,>=1.0.0 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from typepy[datetime]<2,>=1.0.0->DateTimeRange->-r Requirements.txt (line 17)) (1.0.0) Requirement already satisfied: et-xmlfile in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from openpyxl>=2.4.1->robotframework-excellib->-r Requirements.txt (line 19)) (1.0.1) Requirement already satisfied: jdcal in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from openpyxl>=2.4.1->robotframework-excellib->-r Requirements.txt (line 19)) (1.4.1) Requirement already satisfied: distlib<1,>=0.3.1 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from virtualenv>=1.11.2->tox==3.0.0->robotframework-jsonlibrary->-r Requirements.txt (line 4)) (0.3.1) Requirement already satisfied: filelock<4,>=3.0.0 in c:\users\kbhuva2\appdata\roaming\python\python38\site-packages (from virtualenv>=1.11.2->tox==3.0.0->robotframework-jsonlibrary->-r Requirements.txt (line 4)) (3.0.12)

Requirements.txt 的内容是

RESTinstance
robotframework
robotframework-metrics
robotframework-jsonlibrary
robotframework-jsonvalidator
robotframework-seleniumlibrary
robotframework-databaselibrary
robotframework-dependencylibrary
robotframework-pabot
robotframework-datadriver
robotframework-csvlib
webdrivermanager
PyMySQL
pypyodbc
deepdiff
jsondiff
DateTimeRange
pypika
robotframework-excellib

请帮忙解决这个问题...

要理解发生的事情并不容易。当你说:

Till Yesterday all this commands were working perfectly, but today it was not working, the first error I got is

unexpected error: valueerror: not enough values to unpack (expected 3, got 1) robot

您首先需要确定错误的来源。也许错误之前省略的行可以帮助做到这一点。

我在这种(奇怪的)安装方式和 运行 robot 中看到的一个问题是您没有为软件包设置特定版本。如果一个包的新版本导致错误,那么你可能就是现在的情况。