問題描述
我需要在 Java 中使用 selenium chrome 驅動程序進行測試.但不應打開 chrome 窗口.假設這是一個產品,不應打開任何窗口.
I need to test with selenium chrome driver in Java. But chrome window should't be opened. Assume this a product and no window should be opened.
我也看過這個;是否可以在 Selenium RC 中隱藏瀏覽器?但對我來說沒有解決方案.測試應該是獨立于操作系統的,我已經嘗試過 HtmlUnitDriver 進行測試而不打開任何窗口,但它有一些問題.當有通過 id 查找組件時,它可能無法通過 id 查找組件.一些服務器可能會根據瀏覽器發送組件 id,我不知道應該使用什么 id 來測試.
I've also looked at this one ; Is it possible to hide the browser in Selenium RC? But no solution for me. The testing should be operating system independent and I've tried HtmlUnitDriver for testing without opening any window but it has some problem. When there is finding components by id, it may not find the component by id. Some servers may send the component id according to browser and I can't know what id I should use to test.
因此,我正在嘗試使用 chrome 驅動程序.
Because of that I'm trying to use chrome driver.
有沒有辦法在不打開 chrome 窗口的情況下使用 chromedriver,或者在 Java 中不打開任何 Selenium 窗口的情況下進行測試?
謝謝!
推薦答案
使用 PhantomJS 但是如果需要在 chromedriver 中運行它們并且你有資源,這個博客有一個很好的秘訣running headless selenium with chrome.要求您下載以下...
Go with PhantomJS but if running them in chromedriver is required and you have the resources, this blog has a good recipe on running headless selenium with chrome. Requiring you to download the following...
- 虛擬盒子
- 流浪者
- NodeJS
如果您計劃在未來實施 Jenkins 或任何其他 CI,我強烈建議您使用 PhantomJS.
If you plan to implement Jenkins or any other CI in the future, I strongly suggest going with PhantomJS though.
這篇關于在不打開任何瀏覽器的情況下使用 Java 中的 selenium 驅動程序進行測試的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!