如何使用 docker 构建 Selenium 环境并启动 chrome
How to build Selenium environment with docker and launch chrome
我想使用 docker 启动 Selenium 环境,并在我的本地 mac 上进行 e2e 测试。
如果docker环境下当前创建的是Selenium,测试会通过,但是chrome浏览器不会启动。
如果 "selenium-standalone start" 在我的本地 mac 中完成,chrome 将启动。
有人让我知道在用 docker 构建时 chrome 没有启动的原因吗?
复制过程如下
开始docker
docker run -i -t -p 4444:4444 --rm --name e2e-test selenium/standalone-chrome:3.1.0
local with 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 执行“./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 并在本地启动 selenium-standalone mac.
$ npm install selenium-standalone@latest -g
$ selenium-standalone install
$ selenium-standalone start
执行"wdio repl chrome"
$ ./node_modules/.bin/wdio repl chrome
结果
chrome 将启动
执行“./node_modules/.bin/wdio repl chrome”时的selenium-standalone日志
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
将 docker 容器视为远程 selenium。在您的代码中,您必须使用 RemoteWebDriver 并使用 4444 端口连接它。 Chrome 将 运行 在没有图形反馈的容器内(你不会看到 Chrome 运行ning)
此致
我的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
我想使用 docker 启动 Selenium 环境,并在我的本地 mac 上进行 e2e 测试。
如果docker环境下当前创建的是Selenium,测试会通过,但是chrome浏览器不会启动。
如果 "selenium-standalone start" 在我的本地 mac 中完成,chrome 将启动。
有人让我知道在用 docker 构建时 chrome 没有启动的原因吗?
复制过程如下
开始docker
docker run -i -t -p 4444:4444 --rm --name e2e-test selenium/standalone-chrome:3.1.0
local with 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 执行“./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 并在本地启动 selenium-standalone mac.
$ npm install selenium-standalone@latest -g
$ selenium-standalone install
$ selenium-standalone start
执行"wdio repl chrome"
$ ./node_modules/.bin/wdio repl chrome
结果
chrome 将启动
执行“./node_modules/.bin/wdio repl chrome”时的selenium-standalone日志
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
将 docker 容器视为远程 selenium。在您的代码中,您必须使用 RemoteWebDriver 并使用 4444 端口连接它。 Chrome 将 运行 在没有图形反馈的容器内(你不会看到 Chrome 运行ning)
此致
我的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