Using robotframework python libraries in mvn projects

六月ゝ 毕业季﹏ 提交于 2019-12-24 11:35:09

问题


I'm starting a new RobotFramework project, but I'm using the mvn plugin to manage the project. I want to add some python libraries (I have python installed on my computer), but when I try to run the project using the mvn run command, there are several errors related with the lack of python libraries installed.

[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.
------------------------------------------------------------------------------

If I run the project using the Pybot command, everything works fine. How can I use Python libraries when I'm using the maven plugin? Or can I add the Pybot command to the pom.xml?


回答1:


I assume that you already installed requests library, as alpert said, it's not a built in library.

And since you use maven, add the path_to_python_libraries to the robotframework plugin in the pom.xml file. In my case the path is /Library/Python/2.7/site-packages

In pom.xml, use extraPathDirectories tag in robotframework plugin to include the mentioned path. This is a sample of how the robotframework plugin would look like with the extraPathDirectories used to specify a the 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>


来源:https://stackoverflow.com/questions/32115088/using-robotframework-python-libraries-in-mvn-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!