Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access chromedriver logs for Protractor test

I have seen that chromedriver can output a logfile (https://sites.google.com/a/chromium.org/chromedriver/logging)

This page shows how to set this up when executing the exe directly:

chromedriver.exe --verbose --log-path=chromedriver.log

I cannot figure out how to set this up in Protractor however

My current protractor.conf.js

require('babel/register');

exports.config = {
    framework: 'jasmine2',
    seleniumServerJar: './node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar'
};

From @alecxe's answer below and protractor's browser setup docs I tried adding the following (with and without --s) but with no apparent effect:

    capabilities: {
        browserName: "chrome",
        chromeOptions: {
            args: [
                "--verbose",
                "--log-path=chromedriver.log"
            ]
        }
    }

I also tried specifying an absolute path (log-path=/chromedriver.log) which also didn't work.

like image 961
Zach Lysobey Avatar asked Jul 27 '15 20:07

Zach Lysobey


2 Answers

You can always start up your own instance of chromedriver in a separate process and tell Protractor to connect to that. For example, if you start chromedriver with:

chromedriver --port=9515 --verbose --log-path=chromedriver.log

Then you could use a configuration file for Protractor like so:

   exports.config = {
     seleniumAddress: 'http://localhost:9515',
     capabilities: {
       'browserName': 'chrome'
     },
     specs: ['example_spec.js'],
   };
like image 131
Jmr Avatar answered Oct 27 '22 16:10

Jmr


We use a shell script to add chromedriver logging, among other checks. You can then point protractor at the shell script:

protractor config:

// When running chromedriver, use this script:
chromeDriver: path.resolve(topdir, 'bin/protractor-chromedriver.sh'),

bin/protractor-chromedriver.sh

TMPDIR="/tmp"
NODE_MODULES="$(dirname $0)/../node_modules"
CHROMEDRIVER="${NODE_MODULES}/protractor/selenium/chromedriver"
LOG="${TMPDIR}/chromedriver.$$.log"

fatal() {
    # Dump to stderr because that seems reasonable
    echo >&2 "$0: ERROR: $*"
    # Dump to a logfile because webdriver redirects stderr to /dev/null (?!)
    echo >"${LOG}" "$0: ERROR: $*"
    exit 11
}


[ ! -x "$CHROMEDRIVER" ] && fatal "Cannot find chromedriver: $CHROMEDRIVER"

exec "${CHROMEDRIVER}" --verbose --log-path="${LOG}" "$@"
like image 30
P.T. Avatar answered Oct 27 '22 14:10

P.T.