Guide on viewing chromedriver logs during Protractor testing

I've recently discovered that chromedriver has the ability to generate a logfile (https://sites.google.com/a/chromium.org/chromedriver/logging)

While the process of setting up this feature when running the executable directly is clear:

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

However, I'm facing difficulties figuring out how to enable this functionality in Protractor.

Here is my current protractor.conf.js:

require('babel/register');

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

After exploring suggestions from @alecxe's answer and checking out protractor's browser setup documentation, I attempted to implement the following (with and without --s) but it didn't seem to have any impact:

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

Additionally, I experimented with specifying an absolute path (log-path=/chromedriver.log) which also proved to be unsuccessful.

Answer №1

If you want more control over chromedriver, you can run it in its own process and have Protractor connect to it. For instance, by launching chromedriver with the following command:

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

You can then configure Protractor to use this custom setup by creating a configuration file like this:

   exports.config = {
     seleniumAddress: 'http://localhost:9515',
     capabilities: {
       'browserName': 'chrome'
     },
     specs: ['example_spec.js'],
   };

Answer №2

Adding chromedriver logging and other checks is done using a shell script. In order to utilize this, protractor needs to be pointed at the shell script:

Configuration for Protractor:

// Script to use when running chromedriver:
chromeDriver: path.resolve(topdir, 'bin/protractor-chromedriver.sh'),

Contents of bin/protractor-chromedriver.sh:

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

fatal() {
    # Print error message to stderr
    echo >&2 "$0: ERROR: $*"
    # Log error message to a file since 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}" "$@"

Answer №3

The source code of protractor reveals that the chromedriver service is initiated without any arguments, making it difficult to configure the arguments directly. However, the chromedriver's Service Builder utilized by protractor does offer the possibility to set verbosity and log path:

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

The previous (incorrect) answer suggested setting the chrome arguments:

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

For more information, refer to:

  • Viewing outstanding requests

Answer №4

After encountering issues with the previous solution provided by @P.T. on Windows 7, I decided to experiment with his recommendations and eventually found a fix that worked for Windows users. Here is the modified approach tailored specifically for Windows 7.

STEP 1: Setup BASH and JQ and Verify Functionality on Your Windows Machine

  1. To start, you'll need to download bash: For Windows 10 ; For Windows 7, download the latest version here: https://sourceforge.net/projects/win-bash/files/shell-complete/latest/; For Windows Server 2012 or any OS with Git already installed, locate bash.exe and sh.exe in either C:\Program Files\Git\usr\bin or
    C:\Program Files (x86)\Git\usr\bin
  2. Install bash - Extract the zip files to a directory for Windows 7
  3. Download jq () and install it in the same directory as bash
  4. Ensure to add your directory path (where bash zip files were extracted for Windows 7; for other OSes with Git, use the installation path) to the PATH system environment variable.
  5. Once both installations are completed and added to PATH, close all Webstorm and CMD windows before reopening them to proceed with your work.
  6. To verify the installation of bash, type C:\git\> bash in a command prompt window. It should display a bash cmd prompt like this: bash$

STEP 2: Implement Custom Files for Directing Chromedriver Debug Logs

Add the following files at the project's top level (where the protractor-conf.js file is located). These files allow custom debug switches for executing chromedriver.exe

This step is crucial as these switches are not directly accessible through protractor.conf.js via chromeOptions/args flags

chromedriver.cmd -- Source:

bash protractor-chromedriver.sh %*

protractor-chromedriver.sh -- Source:

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() {
    echo >&2 "$0: ERROR: $*"
    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 project's top level (same location as the protractor.conf.js file)

STEP 3: Update protractor.conf.js File

In the protractor.conf.js, add the following line within the exports.config object:

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

STEP 4: Run Your Tests

Your tests should now execute successfully, with any chrome driver log outputs stored in a file named chromedriver.???.log under the tmp directory within your project.

Important Notes

This script setup assumes Protractor (and its chrome driver) is installed and operated within the local node_modules directory of your project. If running Protractor/chromedriver globally, adjust the CHROMEDRIVER variable inside protractor-chromedriver.sh accordingly.

I hope this resolves your challenges.

Answer №5

To specify the logfile path when using seleniumServerJar in your protractor.conf.js file, simply set it to your preferred location:

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

If you are running a local selenium server with webdriver-manager start, make sure to update the following in the webdriver-manager file:

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

// ensure this line is present and add the new push before it
var seleniumProcess = spawnCommand('java', args);

Answer №6

If you are utilizing webdriver-manager, be aware that it includes a feature called chrome_logs. This option can be located in the source code (specifically in opts.ts or opts.js in the compiled code). You can implement it by running the following command:

webdriver-manager start --chrome_logs /path/to/logfile.txt

Answer №7

Although this question is old, I received assistance from the response provided. Shoutout to @PT and @Kim Gentes for their helpful advice.

You do not have to worry about installing bash on Windows. Simply use the command "start /B /W ..."

For chromedriver.cmd, you can include something similar to the following:

start /B /W .\node_modules\protractor\node_modules\webdriver-manager\selenium\chromedriver.exe --verbose --log-path=./chromeriver.log %*

Answer №8

Here is how I have implemented a global afterEach hook with mocha:

afterEach(() => {
    browser.manage().logs().get('browser').then(function(browserLog) {
        if(browserLog && browserLog.length) {
            console.log('\nlog: ' + util.inspect(browserLog) + '\n');
        }
    });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Choosing KineticJS path based on its identification number

I've been working on creating an interactive map using some prebuilt templates. Each country in the map highlights when the mouse hovers over it. My question is, how can I make another country, like Brazil, highlight when any country is hovered over? ...

Utilize AngularJS to integrate a service into the router functionality

What is the best way to inject a service into my router so that its JSON result will be accessible throughout the entire application? Router: export default ['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterP ...

Troubleshooting problem with input fields in Protractor due to sendKeys malfunction

My current task involves automating end-to-end tests using Protractor on an Angular application. However, I've encountered an issue with sending keys to input fields. The sendKeys function consistently misses a few characters each time it is used, so ...

Evaluation of Library (VueJS) - Displaying various components in an individual test case

Just starting out with testing and have a simple question: I am working on testing a checkbox component. I understand the basics, but how can I render multiple components within one it block? Here is my current code. I am stuck on the second test where I ...

Creating a custom loading spinner featuring your logo

Hello, I am looking to create a custom loading spinner using CSS, JS or any other method with my logo. I have the logo in PNG, GIF, and SVG formats and would like to use it for long site loads, image loads, or any other loading processes within my Vue3 pro ...

The checkbox filter in Angular 6 has the ability to replace the previously selected

I've been working on creating a filter system using checkboxes. Below is a snippet of the code I'm currently using: filter.pipe.ts import { Pipe, PipeTransform, Injectable } from '@angular/core'; @Pipe({ name: 'filter2' }) ...

Identifying the specific button within an Angular table that is part of a collection of buttons all sharing the same ID

I am currently working on writing a Selenium test using C# for the specific scenario outlined below. The task at hand involves clicking the undo button on selected records within the table based on their transfer type. https://i.stack.imgur.com/CwNMb.jpg ...

Executing a method in an applet using JavaScript

I am trying to print some information using an applet. The applet is located in the signed qds-client.jar file and has the following code: public class PrintText extends Applet implements Printable { private ClientAccount clientAccount; public Client ...

The getAttribute("value") method is not functioning properly for text input fields

Recently, I started using selenium and encountered an issue while trying to retrieve the value of a textbox. Here's the snippet of my code: WebElement e = driver.findElement(By.id("id")); e.sendKeys("text"); String str = e.getAttribute("v ...

How to position an absolute element beneath a fixed element

My website is experiencing a problem where the fixed header is overlapping an absolute paragraph on this page. Does anyone know how to resolve this issue? ...

How to extract values from multiple children with the same parent and child names in Selenium with Python

I am attempting to retrieve the value specifically for "Publisher" since both parent elements have the same class name and I am unable to determine how to do so. <div class="block-record-info"> <div class="title3">Publisher</div> ...

Displaying all Sunday events in a jQuery FullCalendar

Is there a way to automatically add events for all the Sundays on my calendar using FullCalendar? day = 'Sunday'; <------ I want to specify this day to create an event var date = new Date(); var event = {id: result.id, title: from_time + &ap ...

Guide to looping through a list of elements in an array and executing specific tasks for each element

I need assistance with iterating through an array of elements in a table grid, each linking to a record. My goal is to list the elements and then execute an instruction block that selects i+0 and continues until the end of the array. Despite successfully ...

Develop a custom time input mask in AngularJS controller

In my AngularJS controller, I have the following code snippet: $scope.detailConfig = [{ title: $filter('translate')('bundle.app.HORA_MINUTO_INICIAL_DESCONSIDERAR'), property: 'faixaHorariaInicial', type: ' ...

The handler for errors in DRW consistently generates the message "Error" instead of providing specific information about the issue at hand

FiltersManager.getAllServices({ callback : updateServiceFilter, errorHandler : function(message) { alert(message); } }); Although I throw an exception when an error occurs in th ...

Using a checkbox to enlarge a table

<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.2.js'></script> <script type='text/javascript'> $(window).load(function () { $('.varx').click(function () { ...

Selenium-WebDriver UnhandledPromiseRejectionWarning Issue

I'm a newcomer to the world of Selenium web driver and I've encountered an issue while trying to 'get' a web address. Here's the snippet of code causing trouble: const {Builder, By, Key, until} = require('selenium-webdriver&a ...

Swapping out the entire vue.js container

I have a custom vue.js widget that I initialize like so: var myWidget = new Vue({ el: '#widget-container', methods: { loadData:function() { // custom functionality here } }, }); The HTML structure is as f ...

Ways to show alternative data from a database in Laravel 8

I am working on a project where I need to display additional data based on the option selected from a dropdown menu populated from a database. Can anyone guide me on how to achieve this using javascript or jquery? https://i.stack.imgur.com/k3WLl.png Belo ...

Error in AngularJS - filterProvider not recognized

When the two script statements below are combined, they cause an error: "Error: [$injector:unpr] Unknown provider: searchNameFilterProvider <- searchNameFilter." Can someone explain why this happens? 1st segment Find Person: <input type="text" ng-m ...