CFSelenium“无法启动新的浏览器会话”

CFSelenium " Failed to start new browser session"

我在使用 CFSelenium/TestBox 时遇到问题。我正在 Windows 7 VM Coldfusion 10 上进行开发。我从 https://github.com/teamcfadvance/CFSelenium/archive/master.zip 下载了 cfselenium 的新副本。

我的文件结构是

wwwroot |
  cfselenium |
    Selenium-RC |
        Selenium-server-standalone-2.46.0.jar
    Selenium.cfc
    Server.cfc
  Testbox |
    … various testbox files
   MySite |
    Tests|
        Specs |
            … my test files
            seleniumtest.cfc
        Application.cfc
        Index.cfm

MySite/Test/Application.cfc 包含 testbox/ 和 cfselenium/ 的映射。

测试套件,seleniumtest.cfc 扩展了 testbox.system.BaseSpec,它的 beforeAll() 和 afterAll() 函数实例化 selenium,启动它,然后拆除它:

component extends="testbox.system.BaseSpec" {

function beforeAll( ){
        // create Selenium class
        selenium = new cfselenium.Selenium();
        // Start it up.
        selenium.start( "mysite", "*chrome" );
    }

    // executes after all suites+specs in the run() method
    function afterAll(){
        selenium.stop();
        selenium.stopServer();
    }

function run( testResults, testBox ){
    describe('selenium', function(){
        // hello world equivalent
        describe('equality', function(){
            it('true should be true', function(){
                expect( true ).toBe(true);
            });
        });
    });
}
}

新行为:将以下内容传递给 selenium.start() 时:

selenium.start( "https://www.google.com", "*googlechrome" );

我收到以下错误:

The Response of the Selenium RC is invalid: Failed to start new browser session: java.lang.RuntimeException: org.openqa.selenium.os.WindowsRegistryException: Problem while managing the registry, OS Version '6.1', regVersion1 = false Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03' System info: host: 'myhostname', ip: 'myvm_ip_address', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_67' Driver info: driver.version: unknown

对于我传递给 selenium.start() 的所有其他 url 或浏览器版本(我已经尝试过 '*chrome'、'*firefox'、'*iexplore'、 '*iexploreproxy'), 我收到以下错误:

The Response of the Selenium RC is invalid: Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException: Error while launching browser

从堆栈跟踪中,我可以看到它在 selenium.DoCommand() 处失败。

来自另一个 SO post,建议如果端口 4444 当前正在使用,它可能会干扰 selenium-RC 服务器。我重新启动了我的 VM 并验证端口 4444 没有被 运行ning

使用
Netstat –an | find “4444”

再次运行测试套件后,运行使用相同命令的 netstat 显示

TCP    0.0.0.0:4444           0.0.0.0:0              LISTENING
TCP    127.0.0.1:4444         127.0.0.1:49209        ESTABLISHED
TCP    127.0.0.1:49209        127.0.0.1:4444         ESTABLISHED
TCP    [::]:4444              [::]:0                 LISTENING
TCP    [::1]:4444             [::1]:49208            ESTABLISHED
TCP    [::1]:49208            [::1]:4444             ESTABLISHED

通过查看 cf 日志,我看到以下内容:

Apr 29, 2016 09:44:23 AM Information [ajp-bio-8012-exec-3] - Starting HTTP request {URL='http://localhost:4444/selenium-server/driver/', method='POST'}

wwwroot下应该有一个selenium-server文件夹吗?那是网络驱动程序吗?

编辑:Per Dan 的回答,我已经从 http://chromedriver.storage.googleapis.com/index.html?path=2.21/ 下载了 chromedriver_win32,解压缩到 C:\Program Files (x86)\chromedriver,将其添加到我的 PATH ,并重新启动虚拟机。将驱动程序从“*googlechrome”更改为“*chrome”后,它似乎可以正常工作...我能够 运行 成功进行以下测试:

function testIncludes(){
      selenium.open("https://www.google.com");
      $assert.isEqual("Google", selenium.getTitle());
 }

所以我想我们正在路上。

似乎 IE 驱动程序也能正常工作。

Selenium 无法在没有 Chrome 驱动程序的情况下启动 Chrome(因为 Chrome 不再是 webkit 的一部分)并且默认情况下 Selenium 只能启动 webkit 浏览器。您应该能够启动 Firefox(如果已安装)而无需任何其他二进制文件。

要使 Chrome 正常工作,您需要执行以下操作:

  1. 下载 chrome 驱动程序 bin。
  2. 将其添加到您的路径中。
  3. Selenium 应该能够启动浏览器。

代码中可能还有一些其他问题,但我觉得评论在这方面提供了足够的反馈。

您可以从以下网址下载驱动程序:https://sites.google.com/a/chromium.org/chromedriver/downloads

已更新

IE 也需要驱动程序:

The Internet Explorer Driver Server This is required if you want to make use of the latest and greatest features of the WebDriver InternetExplorerDriver. Please make sure that this is available on your $PATH (or %PATH% on Windows) in order for the IE Driver to work as expected.

Download version 2.53.0 for (recommended) 32 Bit Windows IE or 64 bit Windows IE

以上内容来自:http://www.seleniumhq.org/download/ 关于驾驶 windows。看来带浏览器的楼主需要运行一个IE专用的Selenium Web Driver

Firefox 也发布了自己的驱动程序:

Firefox driver is included in the selenium-server-stanalone.jar available in the downloads. The driver comes in the form of an xpi (firefox extension) which is added to the firefox profile when you start a new instance of FirefoxDriver.

可以找到更多详细信息 here。它的操作类似于 Chrome 和 IE 驱动程序。需要意识到的重要一点是,因为测试是在一台主机上进行的 运行,并且浏览器距离执行测试的位置很远,所以您可能还想看看 Selenium Grid。