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

时间:2016-04-26 13:13:20

标签: selenium coldfusion coldfusion-10

我在使用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" );

我收到以下错误:

  

Selenium RC的响应无效:无法启动新的浏览器会话:java.lang.RuntimeException:org.openqa.selenium.os.WindowsRegistryException:管理注册表时出现问题,操作系统版本为“6.1”,regVersion1 = false构建信息:版本:'2.42.2',修订版:'6a6995d',时间:'2014-06-03 17:42:03'系统信息:主机:'myhostname',ip:'myvm_ip_address',os.name: 'Windows 7',os.arch:'amd64',os.version:'6.1',java.version:'1.7.0_67'驱动程序信息:driver.version:unknown

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

  

Selenium RC的响应无效:无法启动新的浏览器会话:org.openqa.selenium.server.RemoteCommandException:启动浏览器时出错

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

从另一篇SO帖子中,有人建议如果当前正在使用4444端口,它可能会干扰selenium-RC服务器。我重新启动了我的VM并通过运行

验证了端口4444没有被使用
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日志,我看到以下内容:

  

2016年4月29日上午09:44:23信息[ajp-bio-8012-exec-3] - 启动HTTP请求{URL ='http://localhost:4444/selenium-server/driver/',method ='POST'}

wwwroot下应该有一个selenium-server文件夹吗?那是webdriver吗?

编辑:根据Dan的回答,我从http://chromedriver.storage.googleapis.com/index.html?path=2.21/下载了chromedriver_win32,解压缩到C:\ Program Files(x86)\ chromedriver,将其添加到我的PATH,然后重新启动VM。将驱动程序从'* googlechrome'更改为'* chrome'后,它似乎有效...我能够成功运行以下测试:

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

所以我认为我们正在这里。

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

1 个答案:

答案 0 :(得分:3)

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

要让Chrome正常运行,您需要执行以下操作:

  1. 下载chrome driver bin。
  2. 将其添加到您的路径中。
  3. Selenium应该能够启动浏览器。
  4. 代码中可能还有其他一些问题,但我觉得这些意见在这方面提供了足够的反馈。

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

    <强>已更新

    IE也需要一个驱动程序:

      

    Internet Explorer驱动程序服务器   如果您想要使用WebDriver InternetExplorerDriver的最新和最强大的功能,则需要这样做。请确保在$ PATH(或Windows上的%PATH%)上可以使用它,以便IE驱动程序按预期工作。

         

    为(推荐)32 Bit Windows IE64 bit Windows IE

    下载2.53.0版

    以上来自:http://www.seleniumhq.org/download/关于驾驶窗户。看来带浏览器的主机需要专门为IE运行Selenium Web Driver

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

      

    Firefox驱动程序包含在下载中提供的selenium-server-stanalone.jar中。驱动程序以xpi(firefox扩展名)的形式出现,当你启动FirefoxDriver的新实例时,它会添加到firefox配置文件中。

    可以找到更多详细信息here。它的操作类似于Chrome和IE驱动程序。需要注意的重要一点是,因为测试是在一台主机上运行而浏览器远程执行测试的地方,所以你可能也想看看Selenium Grid。