我正在尝试将PhantomJS用作PHPUnit Selenium测试的浏览器。
我已将Selenium设置为以网格模式运行,并使用webdriver启动了phantomjs,并将其注册到网格,如GhostDriver Readme中所示。
当我运行selenium测试时,它因未知命令错误而失败--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
}
]
}
同样的问题在GhostDriver site上被提出并且没有得到答复,并建议将其归咎于PHPUnit。情况可能如此,但我仍然没有接近这项工作。有没有人知道如何解决它?
答案 0 :(得分:3)
您似乎正在使用扩展PHPUnit_Extensions_SeleniumTestCase
的测试类。请改用PHPUnit_Extensions_Selenium2TestCase
。
不幸的是,这不是故事的结局。换出基类时,Selenium相关方法的语法会发生变化。
日期为PHPUnit_Extensions_SeleniumTestCase
的课程
相比之下,PHPUnit_Extensions_Selenium2TestCase
因此可以使用PhantomJS更快地运行PHPUnit驱动的Selenium测试,但它确实需要付出代价。