2013-05-12 35 views
1

我试图使用PhantomJS作为PHPUnit硒测试的浏览器。GhostDriver与PHPUnit

我已经将Selenium设置为以网格模式运行,并使用webdriver启动phantomjs,并将其注册到网格中,如GhostDriver Readme中所述。

当我运行一个硒测试时,它会失败并出现一个未知的命令错误 - GhostDriver只是不理解PHPUnit在说什么。

[ERROR - 2013-05-12T16:23:06.326Z] RouterReqHand - _handle - Thrown => { 
    "message": "Request => {\"headers\":{\"Accept\":\"*/*\",\"Connection\":\"Keep-Alive\",\"Content-Length\":\"85\",\"Content-Type\":\"application/x-www-form-urlencoded; charset=utf-8\",\"Host\":\"127.0.0.1:4444\"},\"httpVersion\":\"1.1\",\"method\":\"POST\",\"post\":\"cmd=getNewBrowserSession&1=phantomjs&2=https%3A%2F%2Ftest.testurl.com%2F&\",\"url\":\"/\",\"urlParsed\":{\"anchor\":\"\",\"query\":\"\",\"file\":\"\",\"directory\":\"/\",\"path\":\"/\",\"relative\":\"/\",\"port\":\"\",\"host\":\"\",\"password\":\"\",\"user\":\"\",\"userInfo\":\"\",\"authority\":\"\",\"protocol\":\"\",\"source\":\"/\",\"queryKey\":{},\"chunks\":[\"\"]}}", 
    "name": "Unknown Command", 
    "line": 87, 
    "sourceId": 139810136032448, 
    "sourceURL": ":/ghostdriver/request_handlers/router_request_handler.js", 
    "stack": "Unknown Command: Request => {\"headers\":{\"Accept\":\"*/*\",\"Connection\":\"Keep-Alive\",\"Content-Length\":\"85\",\"Content-Type\":\"application/x-www-form-urlencoded; charset=utf-8\",\"Host\":\"127.0.0.1:4444\"},\"httpVersion\":\"1.1\",\"method\":\"POST\",\"post\":\"cmd=getNewBrowserSession&1=phantomjs&2=https%3A%2F%2FFtest.testurl.com%2F&\",\"url\":\"/\",\"urlParsed\":{\"anchor\":\"\",\"query\":\"\",\"file\":\"\",\"directory\":\"/\",\"path\":\"/\",\"relative\":\"/\",\"port\":\"\",\"host\":\"\",\"password\":\"\",\"user\":\"\",\"userInfo\":\"\",\"authority\":\"\",\"protocol\":\"\",\"source\":\"/\",\"queryKey\":{},\"chunks\":[\"\"]}}\n at :/ghostdriver/request_handlers/router_request_handler.js:87", 
    "stackArray": [ 
    { 
     "sourceURL": ":/ghostdriver/request_handlers/router_request_handler.js", 
     "line": 87 
    } 
    ] 
} 

这个同样的问题被要求与建议,它的PHPUnit来归咎于GhostDriver site关闭无人接听。情况可能如此,但我仍然没有做出这项工作。有没有人有任何想法如何解决它?

回答

3

它看起来像你正在使用延伸PHPUnit_Extensions_SeleniumTestCase的测试类。改为使用PHPUnit_Extensions_Selenium2TestCase

不幸的是,这不是故事的结尾。当您更换基类时,Selenium相关方法的语法会发生变化。

的过时PHPUnit_Extensions_SeleniumTestCase

相比之下,PHPUnit_Extensions_Selenium2TestCase

  • 使用的webdriver API
  • 支持Phantom.js
  • 需要不同的命令集的未充分记载 - this test case通过实施例证明它,这是关于它
  • 不适用于从Selenium IDE导出的代码,无需大量重写。

因此,使用PhantomJS可以更快地运行PHPUnit驱动的Selenium测试,但它确实需要付出代价。

+0

感谢 - 说实话,速度和速度都比较慢,而且更多的是关于Selenium在去年不再使用Firefox的事实,并且没有任何修复的迹象。我在绝望中寻找替代品。我想在这个新API中重写测试是前进的方向。谢谢。 – Hippyjim 2013-07-01 13:40:02

+1

FWIW,FF适合我。我是Selenium的新手,上周设置了整个shebang,所以我的机器上没有遗留的东西。 Firefox开箱即用,IDE,独立服务器,网格节点......甚至在Windows主机上;) – hashchange 2013-07-01 14:08:31

+0

是的,但是Firefox和“无法访问死对象”错误仍然存​​在问题。该页面非常活跃,JS创建/替换元素。从Firefox 15开始,我就无法通过一个单独的webdriver测试,但它不会因此而死亡。 – Hippyjim 2013-07-01 14:21:05