Best practices for exception handling with Selenium

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Best practices for exception handling with Selenium

el.gato.negro.v

I've been searching on google for best practices regarding exception handling, however I did not have much success besides using try-catch.


My framework is set with a EventFiringWebDriverwhich, according to Selenium documentation has a ExceptionThrown event.


I was thinking in implementing it so we can quickly debug the method that threw the exception, as some colleagues are not programmers and don't know a lot about coding.

The other idea I had is adding try-catch to each method but this seems like a really tedious and worthless endeavour as I would've to keep adding try-catchs to each new method.

So my question is, do you have any best practices regarding exception handling?


Thank you very much.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/310d433b-0984-4459-a165-9d594dffe09b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Best practices for exception handling with Selenium

Jonathan Herbaut
I'm interested about this discussion.
On my side, I wrote my tests like that :

[Test]
public void NavigateToQueueStatus()
{
using (var pageTest = new PageTest<TConfig, Queue, TScreenSize>())
{
pageTest.ExecuteTest(
(page) =>
{
page.NavigateToTab(Queue.QueueView.Status, "ET0021B7BAA4CA");
});
}
}

The PageTest is my main class with common methods to all my app. The object page returned is an instance of the class of my PageTest Queue (for the example).
Here is the content of my ExecuteTest method :

public void ExecuteTest(Action<TPage> handler)
{
try
{
//Exécution de la méthode donnée en paramètre
handler((TPage) Activator.CreateInstance(typeof(TPage), this));
}
catch (Exception e)
{
ManageError(e);
throw;
}
finally
{
CleanPageTest();
}
}

This is my ExecuteTest that takes care of my exceptions. ManageError makes a screenshot of my page with a problem, write the exception and stacktrace in a log file.

With that, I never use again a try/catch structure to get my errors. All I have to do is to call once the ExecuteTest method in my NUnit test with all the process inside the Action parameter.

2018-05-04 9:21 GMT+02:00 <[hidden email]>:

I've been searching on google for best practices regarding exception handling, however I did not have much success besides using try-catch.


My framework is set with a EventFiringWebDriverwhich, according to Selenium documentation has a ExceptionThrown event.


I was thinking in implementing it so we can quickly debug the method that threw the exception, as some colleagues are not programmers and don't know a lot about coding.

The other idea I had is adding try-catch to each method but this seems like a really tedious and worthless endeavour as I would've to keep adding try-catchs to each new method.

So my question is, do you have any best practices regarding exception handling?


Thank you very much.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/310d433b-0984-4459-a165-9d594dffe09b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAH1BzpVo2o%3D4bSJqmDjnDceyurykNLW4O%2B7OEofQ%2BSy%2B-HPqXg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.