Search code examples
automated-testskarateweb-api-testing

Karate : headless chromedriver not working ,giving error as "chrome server returned empty list"


detailed Error i am getting is as below :

`   [2.1:58] test.feature:58 - evaluation of 'karate-config.js' failed: javascript function call failed: com.intuit.karate.exception.KarateException: 
    Create.feature:21 - driver config / start failed: chrome server returned empty list from http://localhost:59435, options: {type=chrome, headless=true, showDriverLog=true, addOptions=["--no-sandbox","--windows-size=1080,1920","--disable-web-security","--credentials_enable_service=false","--profile.password_manager_enabled=false"], pollInterval=1000, pollAttempts=60, port=59435, target=null}
    src.smoke.java.com..test: [1.1:30] test.feature:30 - evaluation of 'karate-config.js' failed: javascript function call failed: com.intuit.karate.exception.KarateException: 

` Below is chrome driver options setup, interestingly scripts get executed successfully when headless:false

function configureChromeForUITests(){
    var chromePort = parseInt( Math.floor(50000 + Math.random() * Math.floor(15534)),10);
    var IntegerType = Java.type('java.lang.Integer');
    var chromePortIntObj = new IntegerType(chromePort);
    var chromeDriverObject =  {
        type: 'chrome',
        //executable: '/opt/homebrew/bin/chromedriver',
        headless:true,
        showDriverLog: true,
        addOptions: [
            '--no-sandbox',
            '--windows-size=1080,1920',
            '--disable-web-security',
            '--credentials_enable_service=false',
            '--profile.password_manager_enabled=false'
        ],
        // webDriverSession: chromeSession,
        pollInterval:1000,
        pollAttempts: 60,
        port: chromePortIntObj,
      
    };

Tried giving executable path as executable: '/opt/homebrew/bin/chromedriver'


Solution

  • Chrome has been updating their headless mode. I had the same issue with the update to Chrome 110, until I added the option '--headless=new'. My abbreviated connection string looks like:

    "* configure driver = {type: 'chrome', headless: true, addOptions: ['--headless=new', '--enable-automation']}"

    Check out this article for some explanation: https://www.selenium.dev/blog/2023/headless-is-going-away/