Selenium测试在由Jenkins运行时失败,但在命令行运行时成功 [英] Selenium tests fail when run by Jenkins, but succeed when run by command line

查看:167
本文介绍了Selenium测试在由Jenkins运行时失败,但在命令行运行时成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个运行Windows Server 2012的虚拟机.一个运行Jenkins,另一个运行Jenkins的构建作业之一.作业从Subversion中检出测试代码,然后在Windows批处理脚本中运行mvn test -Dtest=com.package.name.TestName.该测试会编译并运行,但失败,并显示ElementNotVisibleException.这些是使用Selenium和Firefox驱动程序的TestNG测试.

I have two virtual machines running Windows Server 2012. One is running Jenkins, and another that is running one of Jenkins' build jobs. The job checks out test code from subversion and then runs mvn test -Dtest=com.package.name.TestName in a windows batch script. The test compiles and runs, but fails with an ElementNotVisibleException. These are TestNG tests with Selenium and a Firefox driver.

如果我使用完全相同的命令并从Windows命令行运行它,则测试成功.我注意到的另一件事是,从命令行运行时,浏览器窗口会出现,并且我可以观察它在测试中的运行情况,但是当由Jenkins运行时,则不会出现任何窗口.

If I take the exact same command and run it from the Windows command line, the test succeeds. Another thing I notice is that when run from the command line, the browser window appears and I can watch it run through the test, but when run by Jenkins no window appears.

我发现了这个问题,表明这是因为我们的詹金斯作为服务运行,并且编写测试时需要在前台使用浏览器窗口.更改测试以使用无头驱动程序不是我们的选择,因为这将导致测试结果不准确.有没有办法让这些测试与Jenkins一起使用?

I found this question that suggests this is because our Jenkins is running as a service, and the tests are written to require a browser window in the foreground. Altering the tests to use a headless driver isn't an option for us, as that will result in inaccurate test results. Is there a way to get these tests working with Jenkins?

推荐答案

我建议使用Selenium Grid.它的显式功能是同时服务几个不同的测试.

I'd recommend using the Selenium Grid. Its explicit function is to serve several different tests at the same time.

您的詹金斯将针对网格触发测试,这会将所有测试指向您的节点.

Your jenkins would fire off tests against the grid which would point all the tests towards your nodes.

这篇关于Selenium测试在由Jenkins运行时失败,但在命令行运行时成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆