尝试通过 Selenium Docker 图像上的 Chrome 驱动程序与 Intern 进行 运行 javascript 单元测试时出现问题
Issue trying to run javascript unit tests with Intern through a Chrome Driver on a Selenium Docker Image
我正在尝试 运行 我的 javascript 单元测试通过 Chrome Selenium Docker 图像上的驱动程序(注意:这些测试 运行 通过本地版本的 Intern 和 Selenium 对我来说很好)。到目前为止,我已经完成了以下 5 个步骤:
下拉独立 Chrome 图片:
docker pull selenium/standalone-chrome
运行 独立 Chrome 容器:
docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome
使用 Docker 文件:
将 Chrome 驱动程序手动安装到独立 Chrome 映像上
# We need wget to set up the PPA and xvfb to have a virtual screen and unzip to install the Chromedriver
RUN sudo apt-get install -y wget xvfb unzip
# Set up the Chrome PPA
RUN sudo wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
# Update the package list and install chrome
RUN sudo apt-get update -y
RUN sudo apt-get install -y google-chrome-stable
# Set up Chromedriver Environment variables
ENV CHROMEDRIVER_VERSION 2.19
ENV CHROMEDRIVER_DIR /chromedriver
RUN sudo mkdir $CHROMEDRIVER_DIR
# Download and install Chromedriver
RUN sudo wget -q --continue -P $CHROMEDRIVER_DIR "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip"
RUN sudo unzip $CHROMEDRIVER_DIR/chromedriver* -d $CHROMEDRIVER_DIR
# Put Chromedriver into the PATH
ENV PATH $CHROMEDRIVER_DIR:$PATH
- 设置我的实习生配置文件:
proxyPort: 9000,
// A fully qualified URL to the Intern proxy
proxyUrl: 'http://localhost:9000/',
// Default desired capabilities for all environments. Individual capabilities can be overridden by any of the
maxConcurrency: 3,
// Whether or not to start Sauce Connect before running tests
useSauceConnect: false,
capabilities: {
'selenium-version': '4.0.0',
'seleniumProtocol': 'WebDriver',
'browserName': 'chrome',
'platform': 'Linux',
'version': '95.0',
'ignoreProtectedModeSettings': true,
'chromeOptions': {
'args': [ '-incognito', '--no-sandbox', '--disable-dev-shm-usage', '--headless' ]
}
},
environments: [
{ browserName: "chrome", 'platform': 'Linux', 'version': '95.0'}
],
runnerClientReporter: {
writeHtml: false
},
tunnel: 'NullTunnel',
webdriver: {
host: 'localhost',
port: 4444,
},
- 运行 javascript 测试抛出以下错误:
[exec] [10:39:17] Starting 'intern-tests'...
[exec] (node:80584) Warning: Accessing non-existent property 'VERSION' of module exports inside circular dependency
[exec] (Use `node --trace-warnings ...` to show where the warning was created)
[exec] SUITE ERROR
[exec] UnknownError: [POST http://localhost:4444/wd/hub/session/b63ae473e271e0927ede8816720cf81e/url / {"url":"http://localhost:9000/__intern/client.html?config=intern-config%2Fintern-config.js&reporters=%7B%22writeHtml%22%3Afalse%2C%22id%22%3A%22WebDriver%22%7D&basePath=%2F&initialBaseUrl=%2F&rootSuiteName=chrome%2095.0%20on%20Linux%20-%20unit%20tests&sessionId=b63ae473e271e0927ede8816720cf81e"}] unknown error: net::ERR_CONNECTION_REFUSED
[exec] (Session info: headless chrome=95.0.4638.54)
[exec] Build info: version: '4.0.0', revision: '3a21814679'
[exec] System info: host: '64d03736d73e', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.47-linuxkit', java.version: '11.0.11'
[exec] Driver info: driver.version: unknown
根据错误说 Driver info: driver.version: unknown 我尝试了上面的第 3 步(手动安装了 Chrome 驱动程序)所以我不确定这个错误是否是关于 Chrome 驱动程序的,我认为可能设置正确。
完全删除第 3 步
官方 selenium docker 像 selenium//standalone-chrome 这样的图像安装了浏览器和相应的驱动程序。
更新第 4 步的配置
删除以下变量及其各自值的所有痕迹:
platform; version;
同时注意到代理配置
// A fully qualified URL to the Intern proxy
proxyUrl: 'http://localhost:9000/',
根据以上内容,您声明代理已安装在您的本地计算机上,但是当您将驱动程序请求发送到 chrome 节点时,Chrome 浏览器将翻译代理在 localhost:9000 上实现,这是安装它的平台( 即 Docker 容器 )。
您需要使用托管代理和 Docker 容器的本地计算机的 IP 更新实习代理配置(即 proxyUrl: 'http://192.168.111.222: 9000/)
您也可以使用您选择的域名更新它(例如 my-machine),但是您需要更新您的 Docker 命令:
--add-host=my-machine:<ip-address>
因此您的 docker 运行 cmd 将如下所示:
docker run -d -p 4444:4444 -v /dev/shm:/dev/shm --add-host=my-machine:192.168.111.222 selenium/standalone-chrome
本地计算机主机文件已更新:
127.0.0.1 my-machine
实习生配置:
// A fully qualified URL to the Intern proxy
proxyUrl: 'http://my-machine:9000/',
我正在尝试 运行 我的 javascript 单元测试通过 Chrome Selenium Docker 图像上的驱动程序(注意:这些测试 运行 通过本地版本的 Intern 和 Selenium 对我来说很好)。到目前为止,我已经完成了以下 5 个步骤:
下拉独立 Chrome 图片:
docker pull selenium/standalone-chrome
运行 独立 Chrome 容器:
docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome
使用 Docker 文件:
将 Chrome 驱动程序手动安装到独立 Chrome 映像上
# We need wget to set up the PPA and xvfb to have a virtual screen and unzip to install the Chromedriver
RUN sudo apt-get install -y wget xvfb unzip
# Set up the Chrome PPA
RUN sudo wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
# Update the package list and install chrome
RUN sudo apt-get update -y
RUN sudo apt-get install -y google-chrome-stable
# Set up Chromedriver Environment variables
ENV CHROMEDRIVER_VERSION 2.19
ENV CHROMEDRIVER_DIR /chromedriver
RUN sudo mkdir $CHROMEDRIVER_DIR
# Download and install Chromedriver
RUN sudo wget -q --continue -P $CHROMEDRIVER_DIR "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip"
RUN sudo unzip $CHROMEDRIVER_DIR/chromedriver* -d $CHROMEDRIVER_DIR
# Put Chromedriver into the PATH
ENV PATH $CHROMEDRIVER_DIR:$PATH
- 设置我的实习生配置文件:
proxyPort: 9000,
// A fully qualified URL to the Intern proxy
proxyUrl: 'http://localhost:9000/',
// Default desired capabilities for all environments. Individual capabilities can be overridden by any of the
maxConcurrency: 3,
// Whether or not to start Sauce Connect before running tests
useSauceConnect: false,
capabilities: {
'selenium-version': '4.0.0',
'seleniumProtocol': 'WebDriver',
'browserName': 'chrome',
'platform': 'Linux',
'version': '95.0',
'ignoreProtectedModeSettings': true,
'chromeOptions': {
'args': [ '-incognito', '--no-sandbox', '--disable-dev-shm-usage', '--headless' ]
}
},
environments: [
{ browserName: "chrome", 'platform': 'Linux', 'version': '95.0'}
],
runnerClientReporter: {
writeHtml: false
},
tunnel: 'NullTunnel',
webdriver: {
host: 'localhost',
port: 4444,
},
- 运行 javascript 测试抛出以下错误:
[exec] [10:39:17] Starting 'intern-tests'...
[exec] (node:80584) Warning: Accessing non-existent property 'VERSION' of module exports inside circular dependency
[exec] (Use `node --trace-warnings ...` to show where the warning was created)
[exec] SUITE ERROR
[exec] UnknownError: [POST http://localhost:4444/wd/hub/session/b63ae473e271e0927ede8816720cf81e/url / {"url":"http://localhost:9000/__intern/client.html?config=intern-config%2Fintern-config.js&reporters=%7B%22writeHtml%22%3Afalse%2C%22id%22%3A%22WebDriver%22%7D&basePath=%2F&initialBaseUrl=%2F&rootSuiteName=chrome%2095.0%20on%20Linux%20-%20unit%20tests&sessionId=b63ae473e271e0927ede8816720cf81e"}] unknown error: net::ERR_CONNECTION_REFUSED
[exec] (Session info: headless chrome=95.0.4638.54)
[exec] Build info: version: '4.0.0', revision: '3a21814679'
[exec] System info: host: '64d03736d73e', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.47-linuxkit', java.version: '11.0.11'
[exec] Driver info: driver.version: unknown
根据错误说 Driver info: driver.version: unknown 我尝试了上面的第 3 步(手动安装了 Chrome 驱动程序)所以我不确定这个错误是否是关于 Chrome 驱动程序的,我认为可能设置正确。
完全删除第 3 步
官方 selenium docker 像 selenium//standalone-chrome 这样的图像安装了浏览器和相应的驱动程序。
更新第 4 步的配置
删除以下变量及其各自值的所有痕迹:
platform; version;
同时注意到代理配置
// A fully qualified URL to the Intern proxy
proxyUrl: 'http://localhost:9000/',
根据以上内容,您声明代理已安装在您的本地计算机上,但是当您将驱动程序请求发送到 chrome 节点时,Chrome 浏览器将翻译代理在 localhost:9000 上实现,这是安装它的平台( 即 Docker 容器 )。
您需要使用托管代理和 Docker 容器的本地计算机的 IP 更新实习代理配置(即 proxyUrl: 'http://192.168.111.222: 9000/)
您也可以使用您选择的域名更新它(例如 my-machine),但是您需要更新您的 Docker 命令:
--add-host=my-machine:<ip-address>
因此您的 docker 运行 cmd 将如下所示:
docker run -d -p 4444:4444 -v /dev/shm:/dev/shm --add-host=my-machine:192.168.111.222 selenium/standalone-chrome
本地计算机主机文件已更新:
127.0.0.1 my-machine
实习生配置:
// A fully qualified URL to the Intern proxy
proxyUrl: 'http://my-machine:9000/',