我正在开始一个新的RobotFramework项目,但我正在使用mvn插件来管理项目。 我想添加一些python库(我的计算机上安装了python),但是当我尝试使用mvn run命令运行项目时,有几个错误与缺少安装的python库有关。
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building robot-framework 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- robotframework-maven-plugin:1.2:run (default-cli) @ robot-framework ---
==============================================================================
Acceptance
==============================================================================
[ ERROR ] Error in file 'C:\TEMP\robot3\src\test\robotframework\acceptance\Basic_Test.txt': Importing test library 'RequestsLibrary' failed: ImportError: No module named requests
Traceback (most recent call last):
File "C:\TEMP\robot3\src\test\resources\robotframework\libraries\RequestsLibrary\__init__.py", line 1, in <module>
from RequestsKeywords import RequestsKeywords
File "C:\TEMP\robot3\src\test\resources\robotframework\libraries\RequestsLibrary\RequestsKeywords.py", line 1, in <module>
import requests
PYTHONPATH:
C:\TEMP\robot3\src\test\resources\robotframework\libraries
C:\Users\support\.m2\repository\org\robotframework\robotframework\2.8.1\robotframework-2.8.1.jar\Lib\robot\libraries
C:\Users\support\.m2\repository\org\robotframework\robotframework\2.8.1\robotframework-2.8.1.jar\Lib
C:\Users\support\.m2\repository\org\robotframework\robotframework\2.8.1\Lib
__classpath__
__pyclasspath__/
.
C:\TEMP\robot3
CLASSPATH:
C:\Program Files\Apache Software Foundation\apache-maven-3.0.4\bin\..\boot\plexus-classworlds-2.4.jar
Acceptance.Basic Test
==============================================================================
Basic Test | FAIL |
No keyword with name 'Create Session' found.
------------------------------------------------------------------------------
如果我使用Pybot命令运行项目,一切正常。当我使用maven插件时,如何使用Python库?或者我可以将Pybot命令添加到pom.xml吗?
答案 0 :(得分:1)
我认为你已经安装了请求库,正如alpert所说,它不是内置的库。
由于您使用maven,请将path_to_python_libraries添加到pom.xml文件中的robotframework插件中。在我的情况下,路径是 /Library/Python/2.7/site-packages
在pom.xml中,在robotframework插件中使用 extraPathDirectories 标记来包含上述路径。这是使用 extraPathDirectories 指定path_to_python_libraries时机器人框架插件的样子的示例:
<plugin>
<groupId>org.robotframework</groupId>
<artifactId>robotframework-maven-plugin</artifactId>
<version>1.4.5</version>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<includes />
<excludes />
<criticalTags />
<testCasesDirectory>${project.basedir}/path-to-suites
</testCasesDirectory>
<outputDirectory>${project.basedir}/target/path-to-output
</outputDirectory>
<extraPathDirectories>
<extraPathDirectory>/Library/Python/2.7/site-packages
</extraPathDirectory>
</extraPathDirectories>
</configuration>
</plugin>