0

I am using Selenium with C# and I was wondering if there is anyway in the test to handle the response status code. I need to check for Status Code 500 Internal Server Error.

I CAN match the displayed text but I do not want to do that as it can break in the future.

john doe
  • 8,162
  • 20
  • 71
  • 141
  • The purpose of a selenium test is to check for far more than 200. If you just want to check for 500, 404 or 200, there are much simpler solutions such as cURL or the like. Just my two pennies worth of thoughts. The purpose of Selenium is to check for specific elements (generalizing but at its core). How do you handle changing text or elements, that's a test design decision... One, I'm still working through myself. – Frank V May 13 '15 at 17:47
  • Thanks! Can you explain a little more detail. I am testing user interface. If by cURL you mean current URL that does not help in my scenario. – john doe May 13 '15 at 17:47
  • It's fair to expect that for every sprint (I.E. a group of relevant changes), you are going to need to modify the selenium tests. Just as an actual QA tester would need to modify their written plans over the course of development. Our plan here is to have our QA write our selenium tests using JS and some abstractions that we'll (the engineers) provide. We're still working through this though. – Frank V May 13 '15 at 17:51
  • cURL is a tool - it requests a page and gives you the status code (it also gives you the HTML but that isn't relevant for that use). Selenium: Look at testing a basic log in. You'd have three main tests. (1) submitting w/o entering anything, (2) submitting with correct login/pwd and (3) submitting with bad credentials. In the case of (1,3), we look for our error div to be displayed. It's not perfect or complete but that is the main output we expect in this case; position or exact message doesn't matter. In (2), we look for the div ID that contains our welcome message. 404/500 is auto failure – Frank V May 13 '15 at 17:55
  • possible duplicate of [C# Selenium WebDriver: Get HTTP Status Code](http://stackoverflow.com/questions/18483223/c-sharp-selenium-webdriver-get-http-status-code) – Frank V May 13 '15 at 18:04

2 Answers2

0

Selenium does not have native support for getting HTTP status code. That feature request is out there for a long time. You need to find third party library or something else.

And, since you are using C#, you can use fiddler application along with Selenium proxy as suggested by JimEvans here. Note he is one of the core contributors of Selenium C# bindings. He also has a public github to show the example here

Saifur
  • 15,084
  • 6
  • 43
  • 68
-2

I would suggest that you drop Selenium. Just use HttpStatusCode Enumeration to check status (or get status). You will find more info at https://msdn.microsoft.com/en-us/library/system.net.httpstatuscode.aspx

Eldlabs
  • 462
  • 5
  • 18
  • That there is more efficient way for him get solution on his problem. Selenium is wrong choice if he only want to get response code and act on it. I would say. – Eldlabs May 14 '15 at 05:07