尝试使用 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
一些调查细节
假设 Protractor 使用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
随机数
- 作为Alpine Linux moved to musl libc是否有必要重建 chromeDriver 来使用它?
最佳答案
需要使用 musl libc 重建 chromedriver 或使用 alpine repos 中的 chromedriver 包,您可以使用 apk add --no-cache chromedriver
安装它。
您还需要告诉 Protractor 使用正确的二进制文件
chromeDriver: '/usr/bin/chromedriver'
在你的 Protractor 配置中。
关于linux - 如何在 Alpine Linux 上运行 Angular6 E2E 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50763289/