When using WebdriverJS, the code `driver.manage().logs().get('browser')` may result in an empty array being returned

My mocha test case includes printing the webdriver logs at the end, but I'm facing an issue where the logs are returning as an empty array. Even when passing 'browser' as an argument to the logs().get() function, I still encounter the same result. Can anyone shed some light on why the logs are coming up empty?

it('should open a url', function(done){
    var By = nemo.wd.By;
    driver.manage().logs();
    driver.get("http://www.google.com");
    driver.findElement(By.name('q')).sendKeys("webdriver");
    driver.findElement(By.name('btnG')).click()
    driver.manage().logs().get('driver').then(function(logs){
        console.log(logs);
        done();
    });
});

Answer №1

The reason for the issue was that I forgot to activate the logging feature in the list of options when initializing the driver instance. The problem has been successfully resolved after implementing these modifications.

let preferences = new webdriver.logging.Preferences();
preferences.setLevel('browser', webdriver.logging.Level.ALL); 
pref.setLevel('driver', webdriver.logging.Level.ALL); 

let driver = new webdriver.Builder()
    .withCapabilities(webdriver.Capabilities.firefox())
    .setLoggingPrefs(preferences).build();

Answer №2

The timing of log retrieval in browser drivers can vary. For example, using chromedriver >= 2.29 may result in 'late' logs - the logs().get('performance') promise initially resolves with an empty array, but eventually retrieves the data after a short delay. This issue is also present when tweaking Oscar's capabilities. To workaround this issue:

function getPerfLogs(driver) {
  let performanceLogs;

  return driver.wait(() => {
    return driver.manage().logs().get('performance')
      .then(v => {
        let nonEmpty = v.length > 0;
        if (nonEmpty) {
          performanceLogs = v;
        }
        return nonEmpty;
      })
  }, 1000)
  .then(() => {
    return performanceLogs;
  });
}

getPerfLogs(driver)
  .then(v => console.log('performance logs', v))

Answer №3

After consulting with @Artem, I confirmed the behavior I was experiencing. However, I managed to find a unique solution for my situation by utilizing Protractor. Instead of relying on the conventional method, I decided to explicitly call browser.waitForAngular() before accessing any logs:

return item.click()
    .then(function() {
        // Despite Protractor automatically executing this command before every WebDriver action,
        // browser.manage().logs() is an exception. To ensure immediate log retrieval, adding this line here proved beneficial.
        return browser.waitForAngular()
    })
    .then(function() { return browser.manage().logs().get('browser') })
    .then(function(logs) { ... });

https://www.protractortest.org/#/api?view=ProtractorBrowser.prototype.waitForAngular

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

Using Ajax to fetch and display HTML and PHP pages

After successfully implementing an ajax function to load html pages inside an ajax-container div in my index.php, I am now wondering how I can also call php pages using ajax. Here is the code snippet that I currently have: htaccess rewrite Options +Fol ...

Is there a way to generate random numbers that will create a chart with a general upward trend?

Are you looking for a solution to generate random numbers for charts that trend upwards and to the right? I am currently utilizing a JavaScript charting engine, so I will require numbers in JSON format eventually. However, I am open to alternative methods ...

Changing form validation for input fields in react

Currently, my form validates the input fields immediately upon user interaction. Here's the code snippet- index.js import React from "react"; import ReactDOM from "react-dom"; import ShowError from "./ShowError"; import "./styles.css"; class App ex ...

Having trouble accessing an AngularJS $scope variable because it is coming up as undefined

Currently, I am developing an Electron application using AngularJS for the frontend. Since node.js operates at the OS level while Angular runs at the client level, communication between the two is achieved through IPC (Inter-Process Communication) implemen ...

Recording the descending data points (excluding the dragged positions) from the bootstrap slider

I am struggling with the implementation of the BootStrap Slider from this source: I have encountered an unusual requirement. I need to capture the values of the slider only when the user stops dragging it, not during the process of sliding. In other words ...

Error: PageMethods function not recognized on ASPX page

As I review some older code, I can only assume that it worked at some point in time. MyPage.aspx: function GetCompanyList(officeId) { var companyList = document.getElementById('<%= CompanyDropDown.ClientID %>'); if (companyList.le ...

NodeJs: Error 404 on server

After successfully creating a server and connecting it with MongoDB in the index.js file, I encountered a 404 server error when trying to make an API call from another function in a separate file. Below is my index.js file: import express from "expre ...

The command Webdriver.Quit() is resulting in Firefox crashing during C# Selenium automation

After using selenium's driver.Quit() to close the Firefox browser in C# code, I am encountering an issue where it is closing the Firefox but displaying a message stating "Firefox is stopped working." If anyone has any insights on what might be causin ...

Unable to find the designated ./uploads directory while attempting to upload a file in Express JS

I'm currently working on a project with the following structure: -app -uploads -client - dropzone.js -server.js My goal is to upload a file using dropzone js, Express JS, and React JS. However, whenever I try to drop a file in ...

const queryString = 'search=' + searchId; - using jQuery

I have recently started learning about jQuery and I am currently studying a piece of code in order to implement a similar concept in my coursework. $(function(){ $(".search").keyup(function() { var searchid = $(this).val(); var dataStr ...

Error in THREE.js: Failed to retrieve object at http://192.168.8.104:8080/[object%20Object] (Error code: 404) - Module: three.module.js

During my attempt to create a text loader in THREE.js, I encountered an error instead of getting the expected text output. three.module.js:38595 GET http://192.168.8.104:8080/[object%20Object] 404 (Not Found) I made various efforts to resolve this error ...

Steps to Change the Default Value of Ant Design Date Picker upon Date or State Modification

AntD Version : 5.0 Upon loading the page, the default date is displayed, but I am passing a date stored in a state object. However, after successfully loading the page, changing the state of the date from one component does not update the default value of ...

Arrange my Firebase Angular users based on a specific value, encountering an error stating "sort is not a function

I'm working on an application using Firebase and Angular, and I have a database containing information about my users: https://i.sstatic.net/KQNSY.png My goal is to sort the users based on their "ptsTotal". In my users.service file, I have a functi ...

Switch between showing or hiding at least three divs

I'm currently using a simple script that toggles the visibility of two div elements: <script type='text/javascript'> $(window).load(function(){ function toggle_contents() { $('#page1').toggle(); ...

Having trouble with the jQuery each function's functionality

I am creating circular counters for surveys by generating a counter for each answer option. Currently, I am utilizing this "plugin": Issue: The problem lies in the plugin not fetching the text value from the <div> element and failing to draw coun ...

Display the JSON information within a text input field using React JS

Below is the code I have written in the componentDidMount function: componentDidMount: function() { var url = document.URL; var currentId = url.substring(url.lastIndexOf('?') + 4); // Extracting the current ...

The Jquery ajax code inside the .done(function()) function is not running after the $.when() function

My jquery code is causing an issue. I need the ajax to send json data to the server before submitting the form. Without the when and done clauses, the submission may happen before the ajax call, leading to problems in handling success or error responses. ...

What is the solution for untangling this complicated Javascript variable referencing issue?

Currently facing an issue that needs to be addressed: app.controller 'MainCtrl', ($scope, TestData) -> $scope.name = 'World' TestData.get(0).then (data)-> $scope.elem = data TestData.get(1).then (data)-> $scope ...

Directives for Nested Elements in AngularJS

I am currently working on creating two custom elements: <accordion> and <accordion-group-active>. .directive('accordion', function () { return { restrict: 'E', replace: true, transclude: true, ...

How can I retrieve data submitted in a POST request on my Node.js server

I'm having trouble sending form data to a node/express server using AJAX. After submitting, I keep getting redirected to a 'Cannot POST /' page. Although I can log the request object on the server side, the data from the form is missing. Wha ...