1

背景

我一直致力于自动化我在 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 SocketListener0@0.0.0.0: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!)我读到xvfb作为 linux 的解决方案,但我在 Windows Server 上2003. 最可能的解决方案似乎是使用 Selenium Grid,它可以在其他机器上启动真正的浏览器。不幸的是,对于 Selenium 2,Grid 还不存在,所以这意味着暂时坚持使用 Selenium RC。不理想,但我可以忍受。

问题

我还没有看过 Grid,所以可能是一个幼稚的问题:Grid(在 TeamCity 中无头运行)在远程机器上打开真正的浏览器会有什么问题吗?

有没有办法通过持续集成连接 Selenium 2(没有网格支持)?

4

2 回答 2

1

天真的答案是:

Grid 在远程机器上打开真实浏览器应该没有任何问题。

您应该能够使用带有网格支持的 Selenium 2,它应该与使用 Selenium 1 相同

注意我应该刚刚阅读“问题”并回答;-)

于 2011-03-23T06:57:32.523 回答
1

关于无尽的错误消息,我遇到了类似的问题,例如:

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

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!

于 2011-06-22T21:47:26.530 回答