views:

344

answers:

3

In one of my Selenium test cases, I try to ensure that certain pages can't be accessed. Instead, HTTP return code 403 should be given.

However, here Selenium terminates test execution with the following exception:

com.thoughtworks.selenium.SeleniumException: XHR ERROR: URL = http://user:[email protected]/admin Response_Code = 403 Error_Message = Forbidden

Any way to work around that?

+2  A: 

Seems like I have to answer the question myself...

I now surround the "open" call with a try...catch block. There, I parse the exception message if it contains the 403 code and XHR ERROR. Seems to me not very clean, but it works.

Sebi
+1  A: 

I don't know what language you're using, but I think you can get around this by instructing Selenium to ignore the status code when opening a page. In Ruby this would be doable with something like:

@browser.remote_control_command('open', [url, 'true'])

I believe the behavior in Selenium trunk is to now ignore the status code by default. So, you could try building that and see if it works out for you.

nirvdrum
I'm using the java client library. The current stable release doesn't have such additional parameters. Compiling from source isn't a real option at the moment (tight project plan) :-(
Sebi
A: 

I ve used the try catch stucture but it appear $this->open() method does not throw errors. The test does end and I cannot check what is in the catch because it doesnt get there. Can you explain more in detail? Thanks in advance.