1

I am testing a login functionality on a 3rd party website. I have this url example.com/login . When I copy and paste this into the browser (chrome), page sometimes load, but sometime does not (empty blank white page). The problem is that I have to run a script on this page to click one of the elements (all the elements are embedded inside #shadow-root). If the page loads, no problem, script is evaluated successfully. But page sometimes does not load and it returns a 404 in response to an XHR request, and as a result, my * eval(scrip("script") step returns "js eval failed...".

So I found the solution to refresh the page, and to do that, I am considering to capture the xhr request response. If the status code is 404, then refresh the page. If not, continue with the following steps.

enter image description here

Now, I think this may work, but I do not know how to implement karate's Intercepting HTTP Requests. And firstly, is that something doable?

I have looked into documentation here, but could not understand the examples. https://github.com/karatelabs/karate/tree/master/karate-netty

Meanwhile, if there is another way of refreshing the page conditionally, I will be more than happy to hear about it. Thanks anyone in advance.

1 Answers1

0

First, using JavaScript you should be able to handle shadow roots: https://stackoverflow.com/a/60618233/143475

And the above answer links to advanced examples of executing JS in the context of the current page. I suggest you do some research into that, try to take the help of someone who knows JS, the DOM and HTML well - and you should be find a way to know if the XHR has been made successfully or not - for e.g. based on whether some element on the page has changed etc.

Finally here is how you can do interception: https://stackoverflow.com/a/61372471/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Thanks Peter, I have in fact figured out the query to run in the dom once the page has successfully loaded, but the problem is when the page does not load. I am looking for a way to link 'refresh()' method to a condition, e.g. xhr failure or something else. Can I then add another question here? Does script() method return a json response as karate.match() returns { pass:true, message: '#ignore' } ? That may also work as a condition here. Thanks again for your prompt answer. Either way I will look into XHR response as well. – karateTester Oct 27 '21 at 19:50
  • @karateTester read the docs and if you still can't - ask a new question: https://github.com/karatelabs/karate/tree/master/karate-core#waituntil – Peter Thomas Oct 28 '21 at 01:49