连接 Selenium 以在 Windows 上进行持续集成
背景
我一直致力于自动化我在 Selenium 1.0 (RC) 下开发的 Selenium 测试套件,并将其连接到持续集成系统 (TeamCity”。我很快发现我可以在构建机器上手动运行该套件,但在 TeamCity 运行时失败。
为了完整起见,下面是 selenium 服务器日志在成功时的样子:
18:26:09.025 INFO [12] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: getNewBrowserSession[*iexplore, http://dev2mx:8080/, ] on session null
18:26:09.041 INFO [12] org.openqa.selenium.server.BrowserSessionFactory - creating new remote session
18:26:09.072 DEBUG [12] org.openqa.selenium.server.browserlaunchers.BrowserLauncherFactory - Requested browser string '*iexplore' matches *iexplore
18:26:09.072 INFO [12] org.openqa.selenium.server.BrowserSessionFactory - Allocated session 1c8363f1edbc40b9b251e3bf4bd3d74f for http://portaldev2:80/, launching...
18:26:09.103 DEBUG [12] org.openqa.selenium.server.browserlaunchers.ResourceExtractor - Extracting /core to C:\DOCUME~1\devadmin\LOCALS~1\Temp\5\customProfileDir1c8363f1edbc40b9b251e3bf4bd3d74f\core
18:26:09.244 INFO [12] org.openqa.selenium.server.browserlaunchers.HTABrowserLauncher - Launching Embedded Internet Explorer...
18:26:09.260 DEBUG [12] org.openqa.selenium.browserlaunchers.locators.BrowserLocator - Discovering Internet Explorer...
18:26:09.260 DEBUG [12] org.openqa.selenium.browserlaunchers.locators.BrowserLocator - Checking whether Internet Explorer launcher at :'C:\Program Files\Internet Explorer\iexplore.exe' is valid...
18:26:09.260 DEBUG [12] org.openqa.selenium.browserlaunchers.locators.BrowserLocator - Discovered valid Internet Explorer launcher : 'C:\Program Files\Internet Explorer\iexplore.exe'
18:26:09.275 INFO [12] org.openqa.selenium.server.browserlaunchers.HTABrowserLauncher - Launching Internet Explorer HTA...
18:26:09.291 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for window 'null' local frame 'null' for 1800 more secs
18:26:09.291 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for condition for 1000 more ms
18:26:10.307 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - got condition? : false
18:26:10.307 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for window 'null' local frame 'null' for 1799 more secs
18:26:10.307 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for condition for 1000 more ms
18:26:10.994 DEBUG [13] org.openqa.jetty.http.HttpConnection - new HttpConnection: Socket[addr=/127.0.0.1,port=3255,localport=4444]
18:26:11.010 DEBUG [13] org.openqa.jetty.http.HttpConnection - REQUEST from [email protected]:4444:
日志中显示的失败模式是永远不会到达最后两行。上面的等待队伍一直在等待、等待、等待:
12:19:16.191 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for window 'null' local frame 'null' for 1800 more secs
12:19:16.191 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for condition for 1000 more ms
12:19:17.191 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - got condition? : false
12:19:17.191 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for window 'null' local frame 'null' for 1799 more secs
12:19:17.191 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for condition for 1000 more ms
12:19:18.207 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - got condition? : false
12:19:18.238 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for window 'null' local frame 'null' for 1798 more secs
12:19:18.238 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for condition for 1000 more ms
12:19:19.254 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - got condition? : false
12:19:19.254 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for window 'null' local frame 'null' for 1797 more secs
12:19:19.254 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for condition for 1000 more ms
12:19:20.269 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - got condition? : false
我想了多种角度来检查问题,首先从 Selenium RC 升级到 Selenium 2.0b2,然后只交换服务器 jar 和库引用。相同的结果。
接下来我考虑进一步转换为 WebDriver 和 Selenium 2.0,替换
selenium = new DefaultSelenium("localhost", port, browserType, pageToOpen);
为
selenium = new WebDriverBackedSelenium(driver, pageToOpen);
我立即遇到的是 WebDriver 对框架更严格!我的测试失败了,直到我更严格地指定后续对象应该位于哪个框架中。这项返工仍在进行中,因此关于我原来的问题还没有得出结论,但我怀疑我知道答案,因为......
并行,我开始阅读有关 Selenium 和无头配置以及持续集成的内容。看起来,几乎按照定义,持续集成服务器必须无头运行所有内容,但 selenium 需要显示器。冲突。 (我不想使用 HtmlUnitDriver,因为我想针对真实的浏览器进行测试;更不用说 2.0b2 中的 .NET 还不存在 HtmlUnitDriver!) org/releases/X11R7.6/doc/man/man1/Xvfb.1.xhtml" rel="nofollow">xvfb 作为 Linux 的解决方案,但我使用的是 Windows Server 2003。最有可能的解决方案似乎使用 Selenium Grid,它可以在其他机器上启动真正的浏览器。不幸的是,Selenium 2 尚不存在 Grid,因此这意味着暂时坚持使用 Selenium RC。不太理想,但我可以忍受。
问题
我还没有看过 Grid,所以可能是一个天真的问题:Grid(在 TeamCity 中无头运行)在远程计算机上打开真实浏览器时会遇到任何问题吗?
有没有办法通过持续集成连接 Selenium 2(没有网格支持)?
Background
I have been working towards automating my Selenium test suite that I developed under Selenium 1.0 (RC) and wiring this up to a continuous integration system (TeamCity in this case) on my build machine. I quickly ran into the fact that I could run the suite manually on the build machine but it failed when run by TeamCity.
For completeness, here is what the selenium server log looks like when successful:
18:26:09.025 INFO [12] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: getNewBrowserSession[*iexplore, http://dev2mx:8080/, ] on session null
18:26:09.041 INFO [12] org.openqa.selenium.server.BrowserSessionFactory - creating new remote session
18:26:09.072 DEBUG [12] org.openqa.selenium.server.browserlaunchers.BrowserLauncherFactory - Requested browser string '*iexplore' matches *iexplore
18:26:09.072 INFO [12] org.openqa.selenium.server.BrowserSessionFactory - Allocated session 1c8363f1edbc40b9b251e3bf4bd3d74f for http://portaldev2:80/, launching...
18:26:09.103 DEBUG [12] org.openqa.selenium.server.browserlaunchers.ResourceExtractor - Extracting /core to C:\DOCUME~1\devadmin\LOCALS~1\Temp\5\customProfileDir1c8363f1edbc40b9b251e3bf4bd3d74f\core
18:26:09.244 INFO [12] org.openqa.selenium.server.browserlaunchers.HTABrowserLauncher - Launching Embedded Internet Explorer...
18:26:09.260 DEBUG [12] org.openqa.selenium.browserlaunchers.locators.BrowserLocator - Discovering Internet Explorer...
18:26:09.260 DEBUG [12] org.openqa.selenium.browserlaunchers.locators.BrowserLocator - Checking whether Internet Explorer launcher at :'C:\Program Files\Internet Explorer\iexplore.exe' is valid...
18:26:09.260 DEBUG [12] org.openqa.selenium.browserlaunchers.locators.BrowserLocator - Discovered valid Internet Explorer launcher : 'C:\Program Files\Internet Explorer\iexplore.exe'
18:26:09.275 INFO [12] org.openqa.selenium.server.browserlaunchers.HTABrowserLauncher - Launching Internet Explorer HTA...
18:26:09.291 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for window 'null' local frame 'null' for 1800 more secs
18:26:09.291 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for condition for 1000 more ms
18:26:10.307 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - got condition? : false
18:26:10.307 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for window 'null' local frame 'null' for 1799 more secs
18:26:10.307 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for condition for 1000 more ms
18:26:10.994 DEBUG [13] org.openqa.jetty.http.HttpConnection - new HttpConnection: Socket[addr=/127.0.0.1,port=3255,localport=4444]
18:26:11.010 DEBUG [13] org.openqa.jetty.http.HttpConnection - REQUEST from [email protected]:4444:
The failure mode manifested in the log by never getting to those last two lines. The waiting lines just above kept waiting and waiting and waiting:
12:19:16.191 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for window 'null' local frame 'null' for 1800 more secs
12:19:16.191 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for condition for 1000 more ms
12:19:17.191 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - got condition? : false
12:19:17.191 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for window 'null' local frame 'null' for 1799 more secs
12:19:17.191 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for condition for 1000 more ms
12:19:18.207 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - got condition? : false
12:19:18.238 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for window 'null' local frame 'null' for 1798 more secs
12:19:18.238 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for condition for 1000 more ms
12:19:19.254 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - got condition? : false
12:19:19.254 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for window 'null' local frame 'null' for 1797 more secs
12:19:19.254 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for condition for 1000 more ms
12:19:20.269 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - got condition? : false
I thought of a variety of angles to examine the problem, starting with upgrading from Selenium RC to Selenium 2.0b2 and just swapping out the server jar and the library references. Same result.
Next I thought about further changeover to WebDriver and Selenium 2.0 by replacing
selenium = new DefaultSelenium("localhost", port, browserType, pageToOpen);
with
selenium = new WebDriverBackedSelenium(driver, pageToOpen);
What I encountered immediately is that WebDriver is more strict about frames! My tests failed until I specified more rigorously what frame the subsequent objects were supposed to be in. This rework is still in progress so no conclusion from it yet regarding my original problem, but I suspect I know the answer, because...
In parallel, I started reading about Selenium and headless configuration and continuous integration. It seems that a continuous integration server must, almost by definition, run everything headless, but selenium needs a display. Conflict. (I do not want to use HtmlUnitDriver because I want to test against real browsers; not to mention that HtmlUnitDriver does not exist yet for .NET in 2.0b2!) I read about xvfb as a solution for linux, but I am on Windows Server 2003. The most likely solution seems to be to use Selenium Grid, which could launch real browsers on other machines. Unfortunately, Grid does not yet exist for Selenium 2, so that means sticking with Selenium RC for the time being. Not ideal, but I could live with that.
Questions
I have not yet looked at Grid so probably a naive question: would Grid (running headless in TeamCity) have any problems opening real browsers on remote machines?
Is there any way to wire up Selenium 2 (having no Grid support) with continuous integration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
天真的答案是:
网格在远程计算机上打开真实浏览器时不应该有任何问题。
您应该能够使用具有网格支持的 Selenium 2,它应该与使用 Selenium 1
n.b 相同。我应该只阅读“问题”并回答;-)
naive answers are:
Grid should not have any problem with opening real browsers on remote machine.
You should be able to use Selenium 2 with grid support, it should be same as using Selenium 1
n.b. I should have just read "Questions" and answered ;-)
我遇到了类似的问题,涉及无尽的错误消息,例如:
事实证明,将构建代理作为 Windows 服务运行将导致浏览器的进程运行,但不会导致 selenium 可以与之交互的实际浏览器。如果您停止服务,导航到构建代理的
bin
目录,然后手动启动构建代理 (agent.bat start
),您应该会看到 selenium 测试针对您选择的功能起作用由 TeamCity 构建时的浏览器。希望有帮助!
I have run into a similar problem with regards to the endless error messages such as:
As it turns out, running the build agent as a windows service will cause the process for the browser to run, but not an actual browser with which selenium can interact. If you stop the service, navigate to the build agent's
bin
directory, and launch the build agent manually (agent.bat start
), you should see selenium tests functioning against your chosen browser when built by TeamCity.Hope that helps!