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.

5
  • 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. Commented May 13, 2015 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. Commented May 13, 2015 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. Commented May 13, 2015 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 Commented May 13, 2015 at 17:55
  • possible duplicate of C# Selenium WebDriver: Get HTTP Status Code Commented May 13, 2015 at 18:04

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

-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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.