我正在尝试设置一个将运行机器人测试的 gradle 任务。Robot 使用 python 库与 Selenium 交互,以便通过浏览器测试网页。但不幸的是,安装https://github.com/robotframework/Selenium2Library的唯一方法似乎是通过 pip - pip install robotframework-selenium2library
。有没有办法让 Gradle 在我的任务中运行这个命令?
这是我所拥有的:
构建.gradle:
configurations {
//...
acceptanceTestRuntime {extendsFrom testCompile, runtime}
}
dependencies {
//...
acceptanceTestRuntime group: 'org.robotframework', name: 'robotframework', version: '2.8.7'
//The following doesn't work, apparently this library isn't on maven...
//acceptanceTestRuntime group: 'org.robotframework', name: 'Selenium2Library', version: '1.+'
}
sourceSets {
//...
acceptanceTest {
runtimeClasspath = sourceSets.test.output + configurations.acceptanceTestRuntime
}
}
task acceptanceTest(type: JavaExec) {
classpath = sourceSets.acceptanceTest.runtimeClasspath
main = 'org.robotframework.RobotFramework'
args '--variable', 'BROWSER:gc'
args '--outputdir', 'target'
args 'src/testAcceptance'
}
我的机器人资源文件 - login.resource.robot:
*** Settings ***
Documentation A resource file for my example login page test.
Library Selenium2Library
*** Variables ***
${SERVER} localhost:8080
(etc.)
*** Keywords ***
Open Browser to Login Page
Open Browser ${LOGIN_URL} ${BROWSER}
Maximize Browser Window
Set Selenium Speed ${DELAY}
Login Page Should Be Open
Login Page Should Be Open
Location Should Be ${LOGIN_URL}
当我运行这个任务时,我的机器人测试运行了,但它们失败了。因为在robotframework-selenium2Library 中定义的某些关键字无法识别,例如“打开浏览器”,因此会引发异常。
我怎样才能让 gradle 为这个任务导入这个 selenium 库?我可以通过一些 python 插件安装和调用 pip 吗?