Exception handing in Coded UI Testing

In this post, we will start working with Error/Exception handing in Coded UI Testing. In the last post, we discussed about Assertions in coded UI testing. In Assertions we saw how coded UI testing stops its execution without moving forward to the next operation if the Assertion fails. Even though the behavior is expected, in some situation we would like our test to move forward if there happens any failure due to Validation

Thus in this topic, we will discuss how to handle Error/Exception in code, if there happens any failure only during Validation process but not during

  • Finding of Element
  • Performing operation in Element like enter text, click etc
  • Setting a property for the element

Please don’t try to add exception handling which perform certain operations in the UI, since if that operation exception itself is handled, then that may result in unexpected behavior of test.

Error/Exception handling

We are going to handle Error/Exception in Coded UI testing using try .. catch block of C#.

Here is the complete video of the above explanation

Here is the code snippet of the same code which we discussed in previous post on Assertion in coded UI testing

Code Snippet to Wrapper the Assert.AreEqual method

Thanks for watching the video and reading the post !!!

Please leave your comments and let me know if there is anything need to be improved in this post.

Karthik KK


  1. suruthi says:

    how to resolve the below error:
    The web page could not be accessed ,if the page is refreshing ,please wait until the page refresh and perform action on it

  2. shaifali kashyap says:

    Hi karthik,

    I need to validate in a wintreeitem whether the rroot node is bold or unbold.
    Is this possible in coded ui testing ?

  3. nef says:

    I don’t think the exception handing on Assert is necessary. The assert throws an exception of its own when not true and thats what codedui uses to abort the test.

Leave a Reply

Your email address will not be published. Required fields are marked *