Site Loader
Auckland, New Zealand
In the last couple of posts we discussed about Coded UI Record and playback as well as UIMap in detail. In this post we will discuss about Assertions in Coded UI Test Builder. Using Assertion we can compare for the controls property for
  • AreEqual
  • AreNotEqual
  • Contains
  • DoesNotMatch
  • EndsWith
  • IsNotNull
  • IsNull
  • Matches
  • StartsWith
Using the above comparator property we can compare for the controls using their compare value.

How to Add Assertion from Coded UI Test Builder

Adding assertion from Coded UI Test builder can be done simply by dragging the Cross hair and pointing to the intended control whose property needs to be asserted. The Coded UI Test Builder screen looks something like this So, using the Add Assertion button highlighted above, we can add assertion for the control. In our case, it’s Button 6. Let’s add an assertion and verify if the control’s Friendly Name has Value “6” in it. To do that, just click the Friendly name property and click “Add Assertion” button, this will show you the assertion window as shown Give some assertion failure message for the control, which will be displayed in the Test Explorer report if the test fails to find the specified control with the friendly name property. Click “OK” and Generate the code to add the “AssertMethod1” in your Coded UI Test class of test method. This will bring up an all new method in the Coded UI Test class as shown. Here is the code for Assert method As you can see from the above code, the message which we entered in the Add Assertion of Coded UI Test builder is displayed in the code. Let’s see them in more detail in the video. That’s all guys, thanks for reading and watching the post, please leave your comments in post and video. Thanks, Karthik KK

Post Author: Karthik kk

11 Replies to “Working with Assertions in Coded UI Test Builder”

  1. Awesome!!!!!
    Can i use this easy methods while coding from scratch !! Like as an example:

    //***Validation for the User is IN New Row Number 2 ***

    HtmlEdit ValidateLine2 = new HtmlEdit(oLandingPg);
    ValidateLine2.SearchProperties.Add(“Id”, “mbc8df0a9-tb”);
    Assert.IsTrue(ValidateLine2.Text.Contains(“2”));
    this.TestContext.WriteLine(“We are in New Row Number 2”);

    if (ValidateLine2.Exists)
    {
    this.TestContext.WriteLine(“We are in the New Row 2”);
    }

    else
    {
    this.TestContext.WriteLine(“We are NOT in the New Row 2”);
    }

  2. Sorry . i mean, instead of writing long lines of code like i mentioned before. Can i use assertion method by using cross hair while i am writing the code from scratch.

  3. Hi Kartik,
    I have to assert one Textbox which has calendar control in it but in disable mode. So how I can assert disabled mode calendar control.
    Thanks

  4. Great job Karthik, I am giving a presentation on coded Ui in my company. This is really helpful..

    Kudos to your efforts.

Leave a Reply

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