Calling browser.SetupInterceptor() before Browser.url(), but getting Error

79 Views Asked by At

Scenario: I have a WebApp with a URL "xyz.com", As soon as this URL is loaded on the URL bar (through browser.url()), a few APIs will get triggered (say the name as /ab,/bc and /cd API's), Now I want to fetch those API's and get it validated.

Framework Setup: I have created a function say validateApi() that takes the API name at gets it validated.

Function working: It will take the API name and its trigger point as an argument, then hit the trigger point, and then wait for the API to get called, and also wait till the response is received. and once a response is received it will validate the statusCode etc.. NOTE: (calling browser.setupInterceptor() function at start of the function)

async function validateApi(apiName,triggerPoint){
  await browser.setupInterceptor()
  //some code to hit the triggerPoint(trigger point could be 
  //anything like inputiing value, or clicking and in this case 
  //navigating)so 
  await browser.url(triggerPoint)
  await getRequest()// some code to fetch the api requests
  //some further code to evaluate the api responses
}

Problem

Considering the above scenario: The trigger point for /ab,/bc and /cd APIs is navigation itself, i.e. browser.url(url), But the problem is whenever I am calling the function, browser.setupInterceptor() is called before Browser.url() which trigger's error as given below, When somehow I managed to call after setupInterceptor(), then in that case, it was unable to fetch a few APIs or all(/ab, /bc and /cd). which puts me in a deadlock situation.

Error :

Evaluation failed: DOMException: Failed to read the 'sessionStorage' property from 'Window': Access is denied for this document.
at supportsSessionStorage (eval at \<anonymous\> (:20:16), \<anonymous\>:253:23)
at setup (eval at \<anonymous\> (:20:16), \<anonymous\>:16:9)
at eval (eval at \<anonymous\> (:20:16), \<anonymous\>:322:6)
at __puppeteer_evaluation_script__:20:16
at new Promise (\<anonymous\>)
at __puppeteer_evaluation_script__:2:12
Error: Evaluation failed: DOMException: Failed to read the 'sessionStorage' property from 'Window': Access is denied for this document.
at supportsSessionStorage (eval at \<anonymous\> (:20:16), \<anonymous\>:253:23)
at setup (eval at \<anonymous\> (:20:16), \<anonymous\>:16:9)
at eval (eval at \<anonymous\> (:20:16), \<anonymous\>:322:6)
at __puppeteer_evaluation_script__:20:16
at new Promise (\<anonymous\>)
at __puppeteer_evaluation_script__:2:12
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async DevToolsDriver.executeAsyncScript (/Users/fc19215/Documents/Automation/leap-test/node_modules/devtools/build/commands/executeAsyncScript.js:31:20)
at async Browser.wrappedCommand (/Users/fc19215/Documents/Automation/leap-test/node_modules/devtools/build/devtoolsdriver.js:128:26)
0

There are 0 best solutions below