Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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'],
   };

Solution 2:

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 reasonableecho >&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}""$@"

Solution 3:

According to the protractor's source code, chromedriver service is started without any arguments and there is no direct way to configure the arguments. Even though the chromedriver's Service Builder that protractor uses actually has an ability to specify the verbosity and the log path:

var service = new chrome.ServiceBuilder()
    .loggingTo('/my/log/file.txt')
    .enableVerboseLogging()
    .build();

Old (incorrect) answer:

You need to set the chrome arguments:

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

See also:

Solution 4:

Since, the previous answer by @P.T. didn't work for me on Windows 7, I started with his suggestions and got it working on Windows. Here is a working solution for Windows 7 users.

STEP 1: Install BASH and JQ and confirm they are working on your Windows box

  1. Download bash (for Windows 10 https://itsfoss.com/install-bash-on-windows/ ; for Windows 7 download latest here: https://sourceforge.net/projects/win-bash/files/shell-complete/latest/ ; for Windows Server 2012 or any Windows OS that already has Git installed on it, you already have a bash.exe and sh.exe installed at C:\Program Files\Git\usr\bin or C:\Program Files (x86)\Git\usr\bin already )
  2. Install bash - For Windows 7/ download it and extract the zip files to a directory.
  3. Download jq (https://stedolan.github.io/jq/) and install it in the same directory location as bash
  4. Make SURE that you add your above directory (for Windows 7- where you extracted the bash zip files to; for other applicable OSes that have git, the path it is installed at) to your PATH system environment variable.
  5. Once the above is installed and added to your PATH, close ALL and reopen Webstorm and any CMD windows you wish to run your work in.
  6. Test that bash is actually installed by simply typing it on a windows command prompt C:\git\> bash . Doing so should produce a bash cmd prompt like this bash$

STEP 2: Add Custom Files for Redirecting Chromedriver to user Debug Logging

Add the following files to the top level of the project (wherever your protractor-conf.js is located). These files allow us to add custom debug switches to the chromedriver.exe execution.

Note that this is necessary because these switches are not exposed through protractor and cannot be done directly in the protractor.conf.js file via the chromeOptions/args flags as you would normally expect

chromedriver.cmd -- exact source shown below:

bash protractor-chromedriver.sh %*

protractor-chromedriver.sh -- exact source shown below:

TMPDIR="$(dirname $0)/tmp"
NODE_MODULES="$(dirname $0)/node_modules"
SELENIUM="${NODE_MODULES}/protractor/node_modules/webdriver-manager/selenium"
UPDATECONFIG="${SELENIUM}/update-config.json"
EXEFILENAME="$(cat ${UPDATECONFIG} | jq .chrome.last | tr -d '""')"
CHROMEDRIVER="${SELENIUM}/${EXEFILENAME##*'\\'}"
LOG="${TMPDIR}/chromedriver.$$.log"fatal() {
    # Dump to stderr because that seems reasonableecho >&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}""$@"

/tmp -- create this directory at the top level of your project (same as the location of the protractor.conf.js file.

STEP 3: Update protractor.conf.js file.

In the protractor.conf.js file, add the following line as a property in the exports.config object. As in:

exports.config = {
.. ..
        chromeDriver: 'chromedriver.cmd',
.. ..

STEP 4: Launch your tests

your test should now run and if the chrome driver outputs any log information it will appear in a file called chromedriver.???.log in the tmp directory under your project.

Important caveats

This script set up assumes you install and run protractor (and the chrome driver under it) within the local node_modules directory inside your project. That is how I run my code, because I want it complete self-contained and re-generated in the build process/cycle. If you have protractor/chromedriver installed globally you should change the CHROMEDRIVER variable within the protractor-chromedriver.sh file to match your installation of protractor/chrome driver.

hope that helps.

Solution 5:

If you're using the seleniumServerJar, in protractor.conf.js set the logfile path to wherever you want it to write the file:

seleniumArgs: [
    '-Dwebdriver.chrome.logfile=/home/myUsername/tmp/chromedriver.log',
]

If you're using webdriver-manager start to run a local selenium server, you'll need to edit the webdriver-manager file:

// insert this line
args.push('-Dwebdriver.chrome.logfile=/home/myUsername/tmp/chromedriver.log');

// this line already exists in webdriver-manager, add the push to args before this linevar seleniumProcess = spawnCommand('java', args);

Post a Comment for "How To Access Chromedriver Logs For Protractor Test"