我想使用docker启动Selenium环境,并使用我的本地mac进行e2e测试。
如果是当前在docker环境中创建的Selenium,则测试将通过,但Chrome浏览器将无法启动。
如果" selenium-standalone开始"在我的本地mac中完成,chrome将启动。
有人告诉我,如果使用docker构建时没有启动chrome的原因吗?
复制程序如下
启动泊坞广告
docker run -i -t -p 4444:4444 --rm --name e2e-test selenium/standalone-chrome:3.1.0
本地使用npm install webdriverio
$ mkdir -p webdriverio-test
$ cd webdriverio-test
$ npm install webdriverio --save-dev
执行" wdio repl chrome"
$ ./node_modules/.bin/wdio repl chrome
结果
$ ./node_modules/.bin/wdio repl chrome
[11:48:07] DEBUG Queue has stopped!
[11:48:07] DEBUG You can now go into the browser or use the command line as REPL
[11:48:07] DEBUG (To exit, press ^C again or type .exit)
>
chrome无法启动。
docker log" ./ node_modules / .bin / wdio repl chrome"执行
$ ./node_modules/.bin/wdio repl chrome
2018-04-11 03:22:54.699:INFO:osjs.Server:main: Started @290ms
03:22:54.700 INFO - Selenium Server is up and running
03:23:25.398 INFO - SessionCleaner initialized with insideBrowserTimeout 0 and clientGoneTimeout 1800000 polling every 180000
03:23:25.420 INFO - Executing: [new session: Capabilities [{rotatable=true, locationContextEnabled=true, loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@56231b66, browserName=chrome, javascriptEnabled=true, handlesAlerts=true, requestOrigins={name=webdriverio, version=4.12.0, url=http://webdriver.io}}]])
03:23:25.433 INFO - Creating a new session for Capabilities [{rotatable=true, locationContextEnabled=true, loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@56231b66, browserName=chrome, javascriptEnabled=true, handlesAlerts=true, requestOrigins={name=webdriverio, version=4.12.0, url=http://webdriver.io}}]
Starting ChromeDriver 2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320) on port 11322
Only local connections are allowed.
03:23:26.005 INFO - Detected dialect: OSS
03:23:26.021 INFO - Done: [new session: Capabilities [{rotatable=true, locationContextEnabled=true, loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@56231b66, browserName=chrome, javascriptEnabled=true, handlesAlerts=true, requestOrigins={name=webdriverio, version=4.12.0, url=http://webdriver.io}}]]
chrome启动的过程如下
安装selenium-standalone并在本地mac中启动selenium-standalone。
$ npm install selenium-standalone@latest -g
$ selenium-standalone install
$ selenium-standalone start
执行" wdio repl chrome"
$ ./node_modules/.bin/wdio repl chrome
结果
chrome将启动
selenium-standalone log" ./ node_modules / .bin / wdio repl chrome"执行
12:25:15.793 INFO - /status: Executing GET on /status (handler: Status)
Selenium started
12:25:35.625 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession@538ac7ad
12:25:35.626 INFO - /session: Executing POST on /session (handler: BeginSession)
12:25:35.681 INFO - Capabilities are: Capabilities {browserName: chrome, handlesAlerts: true, javascriptEnabled: true, locationContextEnabled: true, loggingPrefs: org.openqa.selenium.logging..., requestOrigins: {name: webdriverio, url: http://webdriver.io, version: 4.12.0}, rotatable: true}
12:25:35.684 INFO - Capabilities {browserName: chrome, handlesAlerts: true, javascriptEnabled: true, locationContextEnabled: true, loggingPrefs: org.openqa.selenium.logging..., requestOrigins: {name: webdriverio, url: http://webdriver.io, version: 4.12.0}, rotatable: true} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8) on port 40458
Only local connections are allowed.
12:25:36.939 INFO - Detected dialect: OSS
答案 0 :(得分:1)
我的docker-compose.yml
version: "3"
services:
selenium-hub:
image: selenium/hub
container_name: selenium-hub
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome
container_name: chrome
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
- JAVA_OPTS=-Dwebdriver.chrome.whitelistedIps=
https://gist.github.com/GetoXs/1d1469b4fb4ac83d39e7efc3d24cd630
答案 1 :(得分:0)
将docker容器视为远程selenium。在您的代码中,您必须使用RemoteWebDriver并使用4444端口连接它。 Chrome将在容器内运行而没有图形反馈(您将看不到Chrome正在运行)
问候