2013-05-12 33 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