0

There are possibilities of some 3rd party APIs that keep hanging sometimes, letting the actual tests to fail with the timeout error.

Is there some hack to specifically skip such pending API responses?

enter image description here

Anand
  • 1,899
  • 1
  • 13
  • 23
Ruby Tester
  • 113
  • 10
  • When do you want to skip? During initial page loading? – undetected Selenium Jan 16 '18 at 08:29
  • @DebanjanB yea on initial page load I want to skip this specific api – Ruby Tester Jan 16 '18 at 08:30
  • Possible duplicate of [How to make Selenium not wait till full page load, which has a slow script?](https://stackoverflow.com/questions/44770796/how-to-make-selenium-not-wait-till-full-page-load-which-has-a-slow-script) – undetected Selenium Jan 16 '18 at 08:31
  • Can you give us more context about it? What does this API call do in your UI? If it's irrelevant, you can just "rescue" the exception, log it somewhere and go on. You could retry to call it (if triggered by the UI). Now, if the request to this API is mandatory to make your UI work, then I would find a logic to identify that it has hung and retry the whole test for a number of times (i.e. 3 times). – Tom Jan 16 '18 at 08:33
  • @DebanjanB Do we have pageLoadStrategy for Chrome? if so, can you post the answer – Ruby Tester Jan 16 '18 at 09:07
  • Check this QA - [**Page load strategy for Chrome driver**](https://stackoverflow.com/questions/43734797/page-load-strategy-for-chrome-driver/43737358#43737358) Upvote both the Answers if they were useful to you. – undetected Selenium Jan 16 '18 at 09:11
  • @Tom I am already using retry in my tests, the API call in my application is about google analytics that we cannot purge it from the application and I believe the GA server is slow today that makes my tests to fail. Hope you know we cannot rescue the API responses by default since Selenium wait for the entire page to load along with the API responses. – Ruby Tester Jan 16 '18 at 09:12
  • @DebanjanB It looks like a possible fix but do you know how to implement it in Ruby? – Ruby Tester Jan 16 '18 at 09:33
  • well, you have to use the `DesiredCapabilities` and pass it while you initiate the WebBrowser. – undetected Selenium Jan 16 '18 at 09:50
  • yea but the syntax seems different for Ruby; can you please me on that – Ruby Tester Jan 16 '18 at 10:44
  • @DebanjanB setting the pageLoadStrategy to 'eager' throws error for me; however, normal and none works but it's of no use in my scenario ``` caps = Selenium::WebDriver::Remote::Capabilities.chrome caps["pageLoadStrategy"] = "none" @driver = Selenium::WebDriver.for :chrome, desired_capabilities: caps ``` – Ruby Tester Jan 16 '18 at 11:33

1 Answers1

0

This option helped me:

$this->driver->manage()->timeouts()->pageLoadTimeout(1);
try {
    $this->driver->get($pageUrl);
} catch (\Exception $e) {
    error_log($e->getMessage());
}
$this->pageHtml = $this->driver->getPageSource();