How to Deal with a Page Which Fails to Load and Continue Testing in Watir-Webdriver

How to deal with a page which fails to load and continue testing in Watir-Webdriver

I am not sure how would you test a page that did not load, but try something like this:

begin
browser.goto "http://www.mycounciltax.org.uk/results?postcode=WC1N1DF&search=Search"
rescue => e
puts "rescued #{e}"
end

watir-webdriver reload when page fails to load

I don't think there is a built in mechanism to do this, I usually do something like this.

Create a retriable block method that takes a block. Maybe something like:

require 'timeout'

def retriable(num_retries = 0, timeout = 5, &block)
Timeout.timeout(timeout) do
block.call
end
rescue Timeout::Error => e
if num_retries <= 0
raise e
else
puts "Request timed out. Trying #{num_retries} more times"
num_retries -= 1
retry
end
end

Use it like this in your code:

retries = 3
timeout_before_retry = 10 # seconds
retriable(retries, timeout_before_retry) do
browser.goto("http://google.com")
end

Ruby - Watir webdriver Timeout after browser.goto(url) even though URL is successfully loaded

this actually related to your network issue. I think this issue was caused by failed to load all your web resources . selenium will wait for all the resouces to be loaded, if they can't be completed in a certain time, like 60 seconds, it will through out timeout exception.

How can we get Watir-Webdriver to work with the IE invalid cert screen?

I've done a bit of experimenting, including using the HTML I posted to create my own page, sans any JavaScript. If I work with that page, I find it blocks JavaScript actions. In that case, when I try to do things like browser.text, or browser.link.exists?, I see an IE warning popup that tells me that IE is preventing JS from working on that page. (something I never see on the actual cert error page) And in watir-webdriver I get the same errors that I reported. If I click the choice to allow JS, then I can work with the page in watir-webdriver.

So it appears something in in the very nature of the page is preventing any JS level automation which blocks Webdriver's access to the page.

I see why MS is doing this, they don't want a bogus site to somehow use JavaScript to get around that warning. Apparently the way Watir drives things (via OLE?) isn't seen as something you could do remotely and thus is allowed access to the page.

The solution then is to either use Watir for your IE automation, or make it so the certificate is trusted and thus you do not see the warning.

If you want to use Watir-Webdriver, then you need to add the certificates used on your test servers to the Trusted Root Certification Authorities store. Note NOT the default 'personal' store! When adding the cert, you need to change where it's going to put the cert or you are basically only doing a one time for that session authorization. There will be a warning that now all certificates from that authoritiy will be trusted. I would use this with great care, only on test systems, and only for trusting certs from your own internal test servers.

It's pretty easy to do this after manually proceeding to the page, via double-clicking the red warning reminding you the cert is invalid. If you've done that right, you can close the browser, re-open, do your navigation and not get an error.

Watir wait_until_present times out instead of returning false

I think I'm going to give in and leave the sleeps.

(Ignore the random changes in the class and id names throughout my post. Also snake_case vs. camelCase. I didn't write it this way. Trust that I'm successfully getting to the HTML elements in question.)

unknown error: Element is not clickable at point (550, 565). 
Other element would receive the click: <div id="dashboard-loading-screen" class="loading-page-backdrop ng-scope"
ng-if="pageLoading || gridLoading"></div> (Selenium::WebDriver::Error::UnknownError) (Session info: chrome=41.0.2272.76)

Here's a sanitized version of the entire test that's driving me crazy. I don't have the loading issue in debug mode because of course when I'm debugging it has plenty of time to load, so I had to throw in a bunch of puts to figure out what line it was failing on.

Also note that I didn't write the original version of this test, I'm just trying to get it to assert correctly.

def dashboard_rowsPerPage_next(targetRows)
begin
dashboard_rowsPerPage_internal(targetRows) #click drop-down to choose num of rows/page
browser.scroll.to :bottom
beforeRowsText = $browser.div(:class => 'grid-rows-of-label').when_present.text.split(" ", 4).last #page 1

#I put this instead of wait_while_present
if (puts browser.html.include?("loading-page-backdrop ng-scope"))
Watir::Wait.while { browser.html.include? "loading-page-backdrop ng-scope"}
end
puts 'a'
puts browser.html.include?("loading-page-backdrop ng-scope")
puts browser.html.include?("loading-page-backdrop ng-scope")

#here's where I get the error message
browser.span(:class, "k-icon k-i-arrow-e").when_present.click
puts 'b'
puts browser.html.include?("loading-page-backdrop ng-scope")

if (puts browser.html.include?("loading-page-backdrop ng-scope"))
Watir::Wait.while { browser.html.include? "loading-page-backdrop ng-scope"}
end

puts browser.html.include?("loading-page-backdrop ng-scope")
puts 'c'
puts browser.html.include?("loading-page-backdrop ng-scope")
browser.scroll.to :bottom
puts browser.html.include?("loading-page-backdrop ng-scope")
afterRowsText = browser.div(:class => 'grid-rows-of-label').when_present.text.split(" ", 4).last #page 2
puts 'd'
Watir::Wait.while { browser.html.include? "dashboard-loading-screen"}

if (!(beforeRowsText.eql? afterRowsText)) #page 2 text should not be the same as page 1 text
screenCapture()
assertPassed()
else
screenCapture()
assertFailed()
end
# rescue
# screenCapture()
# increment_failed()
end
end

So my output is: (comments added for clarity)

true #should wait while loading image is visible before puts 'a'
a
true #this means the loading page is still visible, while isn't working
true
unknown error: Element is not clickable at point (550, 565).
Other element would receive the click: <div id="dashboard-loading-screen" class="loading-page-backdrop ng-scope"
ng-if="pageLoading || gridLoading"></div> (Selenium::WebDriver::Error::UnknownError) (Session info: chrome=41.0.2272.76)

I checked the values of beforeRowsText and afterRowsText and it's getting those values correctly.

So I'm going to do this instead, because I'm weak:

def dashboard_rowsPerPage_next(targetRows)
begin
dashboard_rowsPerPage_internal(targetRows) #click drop-down to choose num of rows/page
browser.scroll.to :bottom
beforeRowsText = $browser.div(:class => 'grid-rows-of-label').when_present.text.split(" ", 4).last #page 1
sleep 10
browser.span(:class, "k-icon k-i-arrow-e").when_present.click
sleep 10
browser.scroll.to :bottom
afterRowsText = browser.div(:class => 'grid-rows-of-label').when_present.text.split(" ", 4).last #page 2

if (!(beforeRowsText.eql? afterRowsText)) #page 2 text should not be the same as page 1 text
screenCapture()
assertPassed()
else
screenCapture()
assertFailed()
end
rescue
screenCapture()
increment_failed()
end
end

Wait no, nevermind. It works with 25 rows per page but I get the same error on 50 rows per page.



Related Topics



Leave a reply



Submit