Ubuntu下运行Protractor测试时Chrome异常退出的问题求助
Hey there, let's work through this Chrome startup issue you're hitting when running Protractor tests on Ubuntu. That "exited abnormally" error is super common, and we've got a few solid fixes to try out:
1. Verify Chrome & Chromedriver Version Compatibility
First up, mismatched versions between Chrome and Chromedriver are the #1 cause of this problem. Your error shows you're using Chromedriver 2.37, which only works with Chrome versions 64-66. If your Chrome is newer (which it probably is), that's the root issue.
- Check your current Chrome version:
google-chrome --version - Install a Chromedriver version that matches your Chrome release. Look up the compatible version for your Chrome build, then install it via npm:
For example, if you have Chrome 114.x, install Chromedriver 114.x.npm install chromedriver@<your-matching-version> --save-dev
2. Add Headless Mode & Critical Chrome Flags
If you're running Ubuntu without a desktop environment (like a server), Chrome can't launch in normal GUI mode. You need to enable headless mode in your Protractor config, plus a few flags to bypass common Linux-specific issues.
Update your config.js with these Chrome options:
exports.config = { // Your existing config (selenium address, specs, etc.) capabilities: { browserName: 'chrome', chromeOptions: { args: [ '--headless', // Run Chrome without a graphical interface '--disable-gpu', // Disable GPU acceleration to avoid Linux bugs '--no-sandbox', // Bypass sandbox restrictions (critical for root/CI users) '--disable-dev-shm-usage' // Fixes issues with limited shared memory space ] } } };
3. Install Missing Chrome System Dependencies
Ubuntu often lacks some libraries Chrome needs to run properly. Install these core required packages first:
sudo apt-get update && sudo apt-get install -y libxss1 libappindicator1 libindicator7
If that doesn't resolve the issue, install the full set of Chrome dependencies:
sudo apt-get install -y fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils
4. Fix Chromedriver Execution Permissions
Sometimes the Chromedriver binary doesn't have the necessary execution rights. Fix that with this command:
chmod +x node_modules/chromedriver/lib/chromedriver/chromedriver
If you've tried all these steps and still run into issues, feel free to share your exact Chrome version, whether you're running a desktop or server Ubuntu, and any additional error logs—we can dig deeper to get this sorted!
内容的提问来源于stack exchange,提问作者Maciek

