在尝试使用Alpine Linux运行E2E测试时,我们遇到以下神秘错误:
E/launcher - spawn (...)/selenium/chromedriver_2.40 ENOENT
如何重现
docker run -it --name my-alpine --rm alpine:latest /bin/ash
apk add --update nodejs nodejs-npm chromium \
&& export CHROME_BIN=/usr/bin/chromium-browser
npm install -g @angular/cli
ng new testAlpine
cd testAlpine
ng e2e
结果
[14:10:54] I/file_manager - creating folder /testAlpine/node_modules/protractor/node_modules/webdriver-manager/selenium
ℹ 「wdm」: Compiled successfully.
[14:10:54] I/update - chromedriver: unzipping chromedriver_2.40.zip
[14:10:55] I/update - chromedriver: setting permissions to 0755 for /testAlpine/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.40
(node:121) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[14:10:55] I/launcher - Running 1 instances of WebDriver
[14:10:55] I/direct - Using ChromeDriver directly...
[14:10:55] E/launcher - spawn /testAlpine/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.40 ENOENT
[14:10:55] E/launcher - Error: spawn /testAlpine/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.40 ENOENT
at _errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
[14:10:55] E/launcher - Process exited with error code 199
An unexpected error occured: undefined
一些调查详情
假设量角器使用Nodejs spawn function,我们尝试从ash运行命令,结果是“未找到”消息!挖掘一下它发现这可能与缺少动态链接库有关。
为了验证假设,我们安装了binutils来检查动态链接依赖性。
apk add --update binutils
readelf -l /testAlpine/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.40
结果显示了Alpine Linux中没有的依赖性,
/lib64/ld-linux-x86-64.so.2
Elf file type is EXEC (Executable file)
Entry point 0x490000
There are 11 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000200040 0x0000000000200040
0x0000000000000268 0x0000000000000268 R 0x8
INTERP 0x00000000000002a8 0x00000000002002a8 0x00000000002002a8
0x000000000000001c 0x000000000000001c R 0x1
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
LOAD 0x0000000000000000 0x0000000000200000 0x0000000000200000
0x000000000028f27c 0x000000000028f27c R 0x1000
LOAD 0x0000000000290000 0x0000000000490000 0x0000000000490000
尝试使用webdriver-manager获取更新的chrome驱动程序版本也不起作用。下载的版本有同样的问题。
npm install -g webdriver-manager
webdriver-manager update
webdriver-manager: using global installed version 12.0.6
[14:30:20] I/file_manager - creating folder /usr/lib/node_modules/webdriver-manager/selenium
[14:30:21] I/update - chromedriver: unzipping chromedriver_2.40.zip
[14:30:21] I/update - chromedriver: setting permissions to 0755 for /usr/lib/node_modules/webdriver-manager/selenium/chromedriver_2.40
/testAlpine # /usr/lib/node_modules/webdriver-manager/selenium/chromedriver_2.40
/bin/ash: /usr/lib/node_modules/webdriver-manager/selenium/chromedriver_2.40: not found
随机强调
答案 0 :(得分:3)
有必要用musl libc重建chromedriver或使用alpine repos的chromedriver包,你可以用apk add --no-cache chromium-chromedriver
安装它。
你还需要告诉量角器使用正确的二进制文件
您的量角器配置中的chromeDriver: '/usr/bin/chromedriver'
。
答案 1 :(得分:1)
对于将来遇到此问题的人,我完全无法获得alpine
+ angular
+ protractor
+ webdriver-manager
的组合来进行合作任何开箱即用的支持方式。
经过反复修改后,我设法使它起作用
Dockerfile:
FROM node:12-alpine
RUN \
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
&& apk --no-cache update \
&& apk --no-cache upgrade \
&& apk add --no-cache --virtual .build-deps chromium chromium-chromedriver \
&& rm -rf /var/cache/apk/* /tmp/*
ENV CHROME_BIN /usr/bin/chromium-browser
protractor.conf.js
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--headless', '--disable-gpu', '--no-sandbox'],
},
},
directConnect: true,
脚本看起来像这样:
before_script:
- yarn install --frozen-lockfile --cache-folder "$CI_PROJECT_DIR/.yarn"
script:
- npx webdriver-manager update --versions.chrome="$(chromium-browser --version | cut -d ' ' -f 2)"
- mv "$CI_PROJECT_DIR/node_modules/webdriver-manager/selenium/chromedriver_$(chromium-browser --version | cut -d ' ' -f 2)" "$CI_PROJECT_DIR/node_modules/webdriver-manager/selenium/chromedriver.bak"
- ln -s "/usr/bin/chromedriver" "$CI_PROJECT_DIR/node_modules/webdriver-manager/selenium/chromedriver_$(chromium-browser --version | cut -d ' ' -f 2)"
- yarn run e2e --webdriverUpdate=false
请注意,上述代码是用于Gitlab CI配置的代码:根据您的需要,您可能必须: