panther icon indicating copy to clipboard operation
panther copied to clipboard

[Network] Waiting for XHR/Fetch request

Open Guikingone opened this issue 4 years ago • 3 comments

Hi everyone 👋

Small question about network spy and XHR/fetch requests, is there any way to listen and wait for a request to end before executing some code? 🤔

Example:

  • Given I am on the homepage and I need that a fetch request succeed to see some elements (think autocomplete/etc).

Can Panther listen network requests and use something like route (Cypress syntax here) which allows us to wait for a specific request, alias it and call some part of a test following the end of the request? 🤔

I've saw that ChromeOptions can use a enableNetwork option but I don't know if Panther can call this type of options 🤔

ChromeOptions doc: https://sites.google.com/a/chromium.org/chromedriver/capabilities

Guikingone avatar Dec 04 '19 07:12 Guikingone

@Guikingone

Try this if you're using jQuery:

$driver = $client->getWebDriver();

$driver->wait(30, 2000)->until(static function ($driver) {
    /** @var RemoteWebDriver $driver */
    return !$driver->executeScript('return (typeof jQuery !== "undefined" && jQuery.active);');
});

You could run any JavaScript Code inside executeScript. If it returns false (in this case), the driver will stop waiting. See also: https://github.com/facebook/php-webdriver/wiki/How-to-work-with-AJAX-(jQuery,-Prototype,-Dojo)

codegain avatar Dec 13 '19 11:12 codegain

Hi @Guikingone I would like to know if you could solve this problem? And how you do it? Thanks!

lgzsalle avatar Mar 28 '20 13:03 lgzsalle

Waiting for the solution guys :) Thanks in advance

mayanksdudakiya avatar Apr 08 '22 16:04 mayanksdudakiya