如何让我的gradle测试任务对不在maven central上的库使用python pip install?

我正在尝试设置一个将运行机器人测试的gradle任务. Robot使用python库与Selenium交互,以便通过浏览器测试网页.但不幸的是,似乎安装https://github.com/robotframework/Selenium2Library的唯一方法是通过pip – pip install robotframework-selenium2library.有没有办法让Gradle在我的任务中运行此命令?

这就是我所拥有的:

的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中定义的某些关键字,例如“Open Browser”,所以会抛出异常.

如何让gradle导入此selenium库以执行此任务?我可以通过一些python插件安装和调用pip吗?

解决方法:

我不得不使用gradle Exec任务来运行python脚本,然后启动机器人测试.所以它看起来像这样:

的build.gradle

task acceptanceTest(type: Exec) {
    workingDir 'src/testAcceptance'
    commandLine 'python', 'run.py'
}

SRC / testAcceptance / run.py

import os
import robot
import setup 
#Which runs setup.py

os.environ['ROBOT_OPTIONS'] = '--variable BROWSER.gc --outputdir results'
robot.run('.')

SRC / testAcceptance / setup.py

import os
import sys
import pip
import re

pip.main(['install', 'robotframework==3.0'])
pip.main(['install', 'robotframework-selenium2library==1.8.0'])
# Checksums can be looked up by chromedriver version here - http://chromedriver.storage.googleapis.com/index.html
pip.main(['install', '--upgrade', 'chromedriver_installer',
    '--install-option=--chromedriver-version=2.24',
    '--install-option=--chromedriver-checksums=1a46c83926f891d502427df10b4646b9,d117b66fac514344eaf80691ae9a4687,' +
    'c56e41bdc769ad2c31225b8495fc1a93,8e6b6d358f1b919a0d1369f90d61e1a4'])

#Add the Scripts dir to the path, since that's where the chromedriver is installed
scriptsDir = re.sub('[A-Za-z0-9\\.]+$', '', sys.executable) + 'Scripts'
os.environ['PATH'] += os.pathsep + scriptsDir
上一篇:如何在不使用机器人框架和python滚动的情况下获取所有匹配元素?


下一篇:java – 与Selenium对象模式设计的Robot框架关键字管理集成