在docker上进行本地测试。自定义Dockerfile
目标是在无头的Chrome中在Docker中执行守夜框架测试。
我尝试更改chrome参数 我试过更改Chrome二进制路径 我尝试过更改Chrome版本
我构建我的dockerfile-docker build -t coi-automation。 我docker运行-it -p 4444:4444 -v / dev / shm coi-automation:latest
Dockerfile
FROM ubuntu:18.04
RUN apt-get update
#RUN apt-get install --only-upgrade bash
#RUN apt-get install --only-upgrade curl
#RUN apt-get install --only-upgrade sed
#RUN apt-get install --only-upgrade git
RUN ln -s /bin/bash /usr/bin/bash && ln -s /bin/sed /usr/bin/sed && ln -s /bin/sh /usr/bin/sh
RUN apt-get install -y --no-install-recommends software-properties-common
RUN add-apt-repository -y ppa:openjdk-r/ppa
RUN apt-get update
RUN apt-get install -y openjdk-8-jdk
RUN apt-get install -y openjdk-8-jre
RUN update-alternatives --config java
RUN update-alternatives --config javac
RUN apt update \
&& apt install -y \
curl \
bash \
git \
sed \
gnupg \
gcc \
g++ \
make \
&& curl -sL https://deb.nodesource.com/setup_10.x | bash - \
&& apt install -y nodejs \
&& rm -rf /var/lib/apt/lists/*
# Install Chrome for Selenium
RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb
RUN dpkg -i /chrome.deb || apt-get install -yf
RUN rm /chrome.deb
# Install chromedriver for Selenium
RUN curl https://chromedriver.storage.googleapis.com/2.31/chromedriver_linux64.zip -o /usr/local/bin/chromedriver
RUN chmod +x /usr/local/bin/chromedriver
COPY ./ ./
RUN npm install
EXPOSE 4444
nightwatch.json:
{
"src_folders" : ["./tests"],
"output_folder" : "./test-results",
"custom_commands_path" : "./custom_commands",
"page_objects_path" : "./page",
"custom_assertions_path" : "",
"globals_path" : "",
"live_output" : false,
"disable_colors": false,
"selenium" : {
"start_process" : true,
"server_path" : "./node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-3.8.1.jar",
"log_path" : "",
"port" : 4444,
"cli_args" : {
"webdriver.gecko.driver" : "./node_modules/geckodriver/bin/geckodriver",
"webdriver.chrome.driver" : "./node_modules/chromedriver/bin/chromedriver"
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions" : {
"args" : [
"--window-size=1325x744",
"--disable-gpu",
"--headless",
"--no-sandbox",
"--ignore-certificate-errors"],
"binary": "/usr/bin/google-chrome"
},
"javascriptEnabled": true,
"acceptSslCerts": true,
"loggingPrefs": { "browser": "ALL" }
}
}
},
"globals" : {
"waitForConditionTimeout": 5000,
"retryAssertionTimeout": 20000
}
}
错误:
>
root@0dd3100c6606:/# npm test
> coi-automation@1.0.0 test /
> nightwatch
[Smoketests/Coi Smoke Tests] Test Suite
=======================================
Response 500 POST /wd/hub/session (1035ms)
{ value:
{ error:
[ ' (unknown error: DevToolsActivePort file doesn\'t exist)',
' (The process started from chrome location ./node_modules/chromedriver/bin/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)',
' (Driver info: chromedriver=2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926),platform=Linux 4.9.125-linuxkit x86_64) (WARNING: The server did not provide any stacktrace information)',
'Command duration or timeout: 194 milliseconds',
'Build info: version: \'3.8.1\', revision: \'6e95a6684b\', time: \'2017-12-01T19:05:32.194Z\'',
'System info: host: \'0dd3100c6606\', ip: \'172.17.0.2\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'4.9.125-linuxkit\', java.version: \'1.8.0_212\'',
'Driver info: driver.version: unknown' ],
message: 'unknown error: Chrome failed to start: exited abnormally' },
status: 13 }
Error: An error occurred while retrieving a new session: "unknown error: Chrome failed to start: exited abnormally"
at endReadableNT (_stream_readable.js:1125:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
_________________________________________________
TEST FAILURE: 1 error during execution 0 tests failed, 0 passed. 2.128s