我想設置一個將運行機器人測試的gradle任務。 Robot使用Python庫與Selenium進行交互,以便通過瀏覽器測試網頁。但不幸的是,似乎安裝https://github.com/robotframework/Selenium2Library的唯一方法是通過pip - pip install robotframework-selenium2library
。有沒有辦法讓Gradle在我的任務中運行這個命令?我怎樣才能讓我的gradle測試任務使用python pip安裝在不在maven中心的庫上?
這是我有:
的build.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導入此硒庫的任務?我可以通過一些python插件安裝並調用pip嗎?