I'm using Selenium, C#, NUnit to write automated tests.
Is it possible to get the HTTP status code with WebDriver so that tests that fail due to HTTP requests can be alerted to the user?
I'm using Selenium, C#, NUnit to write automated tests.
Is it possible to get the HTTP status code with WebDriver so that tests that fail due to HTTP requests can be alerted to the user?
Not without an external tool no.
You see, this has been brought up a number of times in the past and is one of the largest "issues" within Selenium's official issue tracker. The particular issue has been bounced around and essentially decided that it's outside the scope of Selenium.
This however, does not mean that it is not possible. Thankfully, you are using C#, so it's a little easier than you may think.
Recently, one of the Selenium developers wrote a blog post outlining exactly how to do this in C#. It is a three part blog post to help explain each step and uses an external tool, called Fiddler (which, by the way, is one awesome tool).
Fiddler is a proxy and has a C# API that allows you to intercept requests. It therefore means you can simply "point" Selenium to use that proxy, and then hook into Fiddler's API to check exactly what status code the request has.
I am merely linking to the blog post rather than giving you code to this since it's pretty thoroughly explained in those posts.
Perhaps try it, and then come back if you get any issues implementing his design. Incidentally the guy is also a member here at StackOverflow, so may also see your post.
It's not ideal but I compare the page text against following regex since on my setup that text accompanies web page errors:
(?:(access is denied)|(access is forbidden)|(server error)|(not found))