-1

I am using https://webdriver.io/ for automation.

Using this lib, I am opening a page https://webdriver.io/docs/gettingstarted/ however I need to get the list XHR calls that page is making

class PricingPage extends Page {
 open() {
  return browser.url(
   "https://webdriver.io/docs/gettingstarted/"
 );
 }
 // tried to do so however this is throwing error
 async captureNetworkRequest() {
  var capture_network_request = [];
  var capture_resource = performance.getEntriesByType("resource");
  for (var i = 0; i < capture_resource.length; i++) {
    if (capture_resource[i].initiatorType == "xmlhttprequest" || capture_resource[i].initiatorType == "script" || capture_resource[i].initiatorType == "img") {
        if (capture_resource[i].name.indexOf('https://webdriver.io/docs/gettingstarted/') > -1) {
            capture_network_request.push(capture_resource[i].name)
        }
    }
}
return capture_network_request;
}}

module.exports = new PricingPage();

site.e2e.js

const PricingPage = require("../pageobjects/pricing.page");

describe("Crawler", () => {
 it("should get data", async () => {
 await PricingPage.open();
 await PricingPage.captureNetworkRequest()
 });});

However this is throwing the error

performance.getEntriesByType is not a function

How can I get the XHR that this page is making?

Thanks!

Kgn-web
  • 7,047
  • 24
  • 95
  • 161

1 Answers1

1

You could use a library like XHook that intercepts XHR requests. Pretty sure there are other libraries (even better than this one).

There's an existing Question already here in StackOverflow about this. See this thread.

Alex Pappas
  • 2,377
  • 3
  • 24
  • 48