Log errors with Selenium Webdrive in C#

Asked

Viewed 830 times

1

Good night!

I’m organizing my test suite and looking for the best ways to create a bug report when a test fails. I’ve already implemented a log in. txt with the test name that runs (using Testcontext), the test run time, its status (passed, error, timeout...), and saving prints in case the test fails.

However, if the test fails, I would also like to save the reason for the error, as well as Visual Studio points out when debugging, or appears the reason for the failure in the test suite itself. The point is, I’ll run a service test at dawn, and I won’t have access to the written reasons for the failure.

I thought of some possible solutions, but I didn’t implement them because I believe there are better ways. For example, one of the possibilities I imagined was to treat all the tests with Try/catch, and save the error inside the catchs.

I am using the latest stable version of Selenium Webdriver in a C#project, with structure based on Microsoft.VisualStudio.Testtools.UnitTesting. Thanks in advance!

  • And what is your question? What have you done? Where are you facing trouble?

    1. The best way to record the error when the test fails. 2) I put Try/catchs in some testscases to register Exception. 3) I believe there is another way to capture the error thrown when a test fails, so that the code is more organized and easy to maintain. I’m looking for this medium
  • There are different ways to log Selenium errors: 1) take a screenshot of the screen at the time of error. 2) save the error information from the browser log. 3) save the error information from Selenium itself, as mentioned.

  • Dherik, I’m trying to do exactly what you said at the end, save the error information from Lenium itself, but without using Try/catch in all testcases. The other cases I’ve implemented in the suite

  • Since Selenium in C# can use Nunit, the Nunit Addins API should be what you need because it logs Nunit errors into a file. Is this what you’re looking for? If it is, I’ll put it in answer.

  • Coming home, I’ll check it out. Is it possible to use it together with Microsoft’s Unittesting? Otherwise I’ll have to make a giant change in the test project

  • @Dherik , I will use your advice, you can put as a response

Show 2 more comments

1 answer

1


I believe that your problem would not be to log the Selenium errors themselves, but how to log the errors of your unit tests.

If you are using Nunit, an option for what you want to do is the Nunit Addins API, in which you can save the exceptions of a test to a separate file for later consultation.

Depending on the version of Nunit, there are other alternatives still. If you are using Nunit 3.x it is possible to do in a way and with Nunit 2.x it is possible make another. Unfortunately, the documentation for these cases seemed to me very precarious, but it is worth checking.

  • 1

    I pulled a link from the answer because it no longer works and was redirecting to a seemingly malicious site. Anything, anyone who wants to search for the original link or suggest a new link, can look in the editing history.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.