Tuesday, December 30, 2014

CodedUI Test manually add assertion method, log messages using TestContext.WriteLine, and using UIMap named UIMap1.uptest instead of UIMap.uitest

I am creating this post about manually updating CodedUI Tests as part of a training exercise for another QA Engineer.

I used as an example, but it 's the same idea with any web application.

Here are the requirements of the CodedUI Test Project:

  1. We don't want to use the CodedUI Test Builder to generate the methods and assertions - we will use the builder to update the UIMap and then hand code the methods and assertions; hand coding of assertions and methods is a good idea because we can avoid extra code that gets generated like hover, mouse over, ect.
  2. Create a UIMap named UIMap1.uitest instead of UIMap.uitest - this is because we are going to hand code the assertions and methods; potentially we could make a separate UIMap for each section of the web application
  3. Generate logging messages using TestContext.WriteLine("message"); -- we could also use Console.WriteLine("message);
  4. Browse and load site using TestInitialize section of the CodedUITest.cs file
  5. Add multiple [Test Method] statements to one CodedUITest.cs file instead of one [TestMethod] for each CodedUITest.cs file
  6. When the test is run the test method is selected from the Test Explorer - this is a good idea because we have a better idea where the failure occurs if we name our Test Methods with meaningful names

STEP #1: Create New CodedUITest Project and manually add UIMap named UIMap1.uitest instead of UIMap.uitest

STEP #2: Rename the default CodedUITest1.cs file and dependencies

STEP #3: Add Controls to UIMap1.uitest - this is a partial class so the generated code will be added to UIMap1.Designer.cs and we'll add custom code to UIMap1.cs

STEP #4: Add the Using directive and Constructor to the CodedUITestAmazon.cs file

STEP #5; Add code to TestInitialize section of the CodedUITest.cs file that loads IE, browse to URL, and log message

STEP #6: Add Custom Assertion to CodedUITest.cs file that verifies properties of an HtmlHyperlink and logs messages using TestContext.WriteLine