自动化工具 使用 Jenkins 和 gradle,怎么向 Selenium 工程中传递参数

dy20082250 · 2017年12月16日 · 最后由 dy20082250 回复于 2017年12月17日 · 1512 次阅读

我对 selenium 进行封装,能够实现

脚本在 IE,Firefox 和 Chrome 浏览器中分别运行

但是现在不了解如何使用 jenkins 和 gradle 向
工程中传递浏览器类型,

我有看到 jenkins 中有参数化构建
只是设置了参数后,如何将参数通过 gradle 传递到 selenium 程序中去呢?

希望有经验的网友给一点指点。

共收到 7 条回复 时间 点赞

标记一下

anyone?

写 shell 就好了。 或者写 python 都行。 参数化构建后你在 Jenkins 里可以用 $ 符号引用了。 下面设置构建任务的时候,弄一个构建前的 shell 脚本。 把参数写进去就行了

孙高飞 回复

不是特别明白

我在网上找到一个使用 jenkins 的参数化构建中定义 String

然后使用 ant 工具在构建时,将参数传递给 JAVA 程序的方法

正在照虎画猫
只是我对 gradle 了解太少,还在试验中
你说的 shell,我不清楚具体该怎么做

dy20082250 回复

差不多是这种感觉

孙高飞 回复

谢谢,我试试

在 CSDN 中找到了问题的解决方法

经过试验,方法如下:

在 build.gradle 文件中设置:

test {
   // enable TestNG support (default is JUnit)
   useTestNG()




   // set a system property for the test JVM(s)
    systemProperty 'browser', project.getProperty("browser")




   // explicitly include or exclude tests
   include 'com/eisoo/content/script/TestLogin.class'
   //include 'com/eisoo/content/script/TestEnterpriseCenter.class'
   //include 'com/eisoo/content/script/TestStatistics.class'
   //include 'com/eisoo/content/script/TestContentCenter.class'

   ignoreFailures = true

   // show standard out and standard error of the test JVM(s) on the console
   testLogging.showStandardStreams = true

   // set heap size for the test JVM(s)
   minHeapSize = "64m"
   maxHeapSize = "512m"

}

然后使用指令 gradle clean test -Pbrowser="firefox"
就可以将选个浏览器的类型传递到 gradle 中

然后 systemProperty 'browser', project.getProperty("browser") 将浏览器类型设置为系统变量

最后在 java 程序中使用 System.getProperty('browser') 将值传递给构造函数,来构造不同的 driver!

dy20082250 关闭了讨论 12月17日 15:04
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册