我想使用 chromium headless 来使用 selenium 进行自动化测试。 ( https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md )
我确实已经在 9222 上运行了无头版本。所以如果我打开 http://10.252.100.33:9222/json/ ,我会得到
[ {
"description": "",
"devtoolsFrontendUrl": "/devtools/inspector.html?ws=127.0.0.1:9223/devtools/page/0261be06-1271-485b-bdff-48e443de7a91",
"id": "0261be06-1271-485b-bdff-48e443de7a91",
"title": "The Chromium Projects",
"type": "page",
"url": "https://www.chromium.org/",
"webSocketDebuggerUrl": "ws://127.0.0.1:9223/devtools/page/0261be06-1271-485b-bdff-48e443de7a91"
} ]
作为下一步,我想将硒连接到无头铬。但是当我尝试
final DesiredCapabilities caps = DesiredCapabilities.chrome();
final WebDriver driver = new RemoteWebDriver(new URL("http://localhost:9222/json"), caps);
driver.get("http://www.google.com");
我确实收到以下注销
Jän 24, 2017 7:14:45 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMATION: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Jän 24, 2017 7:14:45 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMATION: Falling back to original OSS JSON Wire Protocol.
Jän 24, 2017 7:14:45 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMATION: Falling back to straight W3C remote end connection
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{browserName=chrome, version=, platform=ANY}], required capabilities = Capabilities [{}]
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'Geralds-MacBook-Pro.local', ip: '192.168.0.249', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.2', java.version: '1.8.0_111'
Driver info: driver.version: RemoteWebDriver
问题是:
- RemoteWebDriver 是连接到无头铬的正确驱动程序吗?
- 我了解了 DevTool 协议 ( https://docs.google.com/presentation/d/1gqK9F4lGAY3TZudAtdcxzMQNEE7PcuQrGu83No3l0lw/ ),但我不确定如何使用 selenium 创建这样的客户端。
- 使用 Chrome DevTools 连接 Chromium Headless 工作 ( https://developers.google.com/web/tools/chrome-devtools/remote-debugging/ ) 除了一些分段库 ;-)
原文由 geri-m 发布,翻译遵循 CC BY-SA 4.0 许可协议
我认为自述文件有点误导。您不必启动 Chromium 本身,您可以使用
RemoteWebDriver
。确保安装了 chromedriver ( https://sites.google.com/a/chromium.org/chromedriver/home )。./chromedriver
或./chromedriver --port=9515
)--headless
作为附加参数代码应如下所示:
在 Ubuntu Linux 上为我工作。