Selenium extracts network information by utilizing the HAR Export xpi plugin

Currently, I am using HAR Export XPI to capture the network traffic data of the pages being accessed via Selenium. To achieve this, I have added the XPI extension to Firefox version 46 since it is not compatible with newer versions. The profile settings I have configured are as follows -

profile.setPreference("app.update.enabled", false);
profile.setPreference("extensions.netmonitor.har.enableAutomation", true);
profile.setPreference("extensions.netmonitor.har.contentAPIToken", "true");
profile.setPreference("extensions.netmonitor.har.autoConnect", true);
profile.setPreference("devtools.netmonitor.enabled", true);
profile.setPreference("devtools.netmonitor.har.pageLoadedTimeout", "50000");
profile.setPreference("devtools.netmonitor.har.defaultLogDir", "FOLDER_ON_SYSTEM");
profile.setPreference("devtools.netmonitor.har.enableAutoExportToFile", false);

To extract the HAR file, I am injecting the following JavaScript code.

function triggerExport() {

  var options = {
    token: "true",
    getData: true,
    fileName: "Export_%y%m%d_%H%M%S"
  };
  HAR.triggerExport(options).then(result => {
      console.log(result);
  });
};

if (typeof HAR === 'undefined') 
{
    console.log("Calling Undefined");
    addEventListener('har-api-ready', event => {
        console.log("har api ready");
        console.log(event);
        triggerExport();
    }, false);
} 
else 
{
    console.log("Calling defined");
    triggerExport();
}

However, I am encountering an issue where the HAR file is not being generated. I also noticed that typing 'HAR' in the Firefox console returns 'undefined', causing the function to fail.

I'm seeking guidance on any additional settings or steps that may be required to resolve this problem.

Thank you for your assistance!

Answer №1

After trying various suggested solutions without success (such as using browsermob proxy and XPI, which seemed outdated), I decided to take matters into my own hands. I created a small npm package that allows for capturing selenium tests as HAR files - check it out at this link

To achieve this, I utilized the Chrome Dev Tools Protocol to capture Fetch events. The details of my implementation can be found here

If you're interested, I also wrote a comprehensive guide on how to transform selenium tests into API tests.

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

res.json responding with altered input unexpectedly

When I use my res.json function, it seems to be altering my data. The data appears correct when logged in the function, but changes inside res.json and I can't figure out why. For example, instead of returning {"unix":"1484600306","naturalFormat":"20 ...

ES6 does not work with React hello world

Can anyone help me with troubleshooting my code? I've checked the console on jsbin and can't find any errors. http://jsbin.com/susumidode/edit?js,console,output Class secondComponenent extends React.Component { render(){ return ( &l ...

Tips for selecting a button within an Alert popup

I am currently tasked with automating this particular page using Java and Selenium. The objective is to locate and click on the link labeled terms and conditions, which triggers a pop-up box. Subsequently, I need to scroll down within the box and click on ...

Exploring the functionalities of ng-value and ng-model in text input form fields

As I create a form to update information in a database, everything seems to be functioning properly. The selected data is being retrieved correctly; however, it is not displaying in the text inputs on the webpage. Although the information appears correct ...

Issue with Context Menu Not Triggering on Dynamically Added Elements in JQuery

Check out the JSFiddle Demo Within my email sidebar, I implemented a custom right-click feature that allows users to add new sub-folders. The code snippet below demonstrates how this functionality works: if ($(this).hasClass('NewSubFolder')) { ...

Searching for an item in an array within MongoDB: Tips and techniques

I am attempting to locate the object containing a specific element within an array: Here is my query: router.get('/', function(req, res) { var userSubscribed = req.user.email; db.posts.find({ "SubscriberList": { $elemMatch: userSubscrib ...

When using Vuejs, it's important to note that the DOM.getBoundingClientRect event does not trigger on window scroll events, but instead

Situation: I am currently developing an infinite scroll feature on a website. The goal is to load more rows in a table when the bottom of the table reaches the bottom of the viewport from outside of it. Implementation: To achieve this, I first declared a ...

Do we need to use the "new" keyword when using ObjectID in a MongoDB query

Recently, I was immersed in a Typescript web project that involved the use of MongoDB and ExpressJS. One particular task required me to utilize a MongoDB query to locate and delete a document using the HTTP DELETE method. However, during the process of exe ...

What is the process of encoding JSON in PHP using jQuery Ajax to send post data?

I created an HTML form to submit data to a PHP file upon hitting the submit button. $.ajax({ url: "text.php", type: "POST", data: { amount: amount, firstName: firstName, lastName: lastName, email: email }, ...

Looking for a simple method to convert JSON object properties into an array?

Is there a simple method for extracting only the values of the properties within the results object in the given JSON data? let jsonData = {"success":true, "msg":["Clutch successfully updated."], "results":{"count_id":2, ...

Using Java code, WebDriver fails to open Firefox and remains inactive on a Windows XP operating system

I've been having some issues trying to run Selenium2 (also known as WebDriver) with Java in Firefox. For some reason, the browser doesn't even open and no errors are thrown in the console. It just stays idle and doesn't do anything. My setu ...

What is the best way to dynamically insert columns into HTML code?

This is an example of my HTML code: <div class="row text-center"> <div class="col h4">We Collaborate With:</div> <div class="col">company1</div> <div class="col">company2</div> ...

React SVG not displaying on page

I am facing an issue with displaying an SVG in my React application. Below is the code snippet: <svg className="svg-arrow"> <use xlinkHref="#svg-arrow" /> </svg> //styling .user-quickview .svg-arrow { fill: #fff; position: ...

How can I utilize a CDN for JavaScript libraries in Gulp?

As a newcomer to AngularJS and Gulp, I recently encountered an example where certain libraries are copied by Gulp from the 'node_modules' folder into a 'js/lib/angular2' directory: gulp.task('libs', function() { return gulp. ...

Error encountered in referencing a web service (ASP/VB.NET)

I am attempting to utilize a web service within my web application developed in Visual Studio 2012. Below is the code for my web service: Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel ' To allow thi ...

Nodemon may have failed to install correctly

When trying to install nodemon globally, I encountered an error. How can I resolve this issue? C:\Users\nipuna\Desktop\nodejs>npm install -g nodemon npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules\ ...

What is the reason behind getComputedStyle having visibility set to visible?

What is the reason behind getComputedStyle always returning element visibility as visible even when no explicit visibility has been set? For instance: getComputedStyle($('#block1')[0],null).visibility; --- "visible" Meanwhile: $('#block1&a ...

Setting the default tab in easyTabs to be all-powerful

My ajax content is being loaded into a div-container through various navigation links, and I am using the script below to establish the defaultTab: $(document).ready( function() { $("#tab-container").easytabs({updateHash: true, defaultTab: "li:eq(3)"}); ...

Setting up gulp-typescript for Angular 2: A comprehensive guide

Right now I am utilizing the tsc compiler with the watch flag in the command prompt. It functions correctly, loading all definition files and successfully compiling each angular2 file. However, it is quite cumbersome to use via the shell window. My object ...

Utilizing ThemeProvider in a Different Component in React

In my App.js file, I have a function that toggles between light and dark mode themes: import { createTheme, ThemeProvider } from '@mui/material/styles' import Button from '@mui/material/Button' import Header from './components/Head ...