Friday, 27 September 2013

How to create set by step report of a test case while running a validation test case ?

Hi Guys

Below sample shows how you can create a detailed report while running a validation test case thru coded-UI. Lets take a an example: You have to validate 4-5 elements on a page and what will happen if your 2nd element doesn't exist have some visibility issue.

TEST CASE GET FAILED AND IN THIS CASE WHAT WILL HAPPEN TO THE VALIDATION CHECK FOR OTHER ELEMENT WHICH ARE LEFT BECAUSE BECAUSE 2ND ELEMENT DOESN'T EXIST.

HOW ABOUT THIS: If your 2nd doesn't exist but your script will throw an error for that and also continue on validating other element too.

By using below you can successfully do that:

public void TC_Bing_VerifyingTheHomepageBing(string testCaseID, string inputFile)

Code:

        {
            #region Test Steps

            try
            {
                //Declaring array to store exceptions and string should number of elements you are validating your test case
                string[] exceptionMessage = new string[50];
                int count = 0;
               
                //fetch test data  from csv file
                string[] testdata = common.ReadCSV(testCaseID, separator, inputFile);

                if (uIBingHomePage.Title == testdata[1])
                {
                    if (!uIWebHyperlink.Exists)
                    {
                        exceptionMessage[count] = "Web link is not available";
                        count++;
                    }

                    if (!uIImagesHyperlink.Exists)
                    {
                        exceptionMessage[count] = "Image link is not available";
                        count++;
                    }

                    if (!uINewsHyperlink.Exists)
                    {
                        exceptionMessage[count] = "News link is not available";
                        count++;
                    }

                    if (!uIMoreHyperlink.Exists)
                    {
                        exceptionMessage[count] = "More link is not available";
                        count++;
                    }

                }
                else
                {
                    Assert.Fail("HomePage of Bing is not opened as expected");
                }
               
                //Collecting all the assertion message and failing the test case
                if (exceptionMessage != null && exceptionMessage[0] != null)
                {
                    string errorMessage = string.Empty;
                    foreach (string x in exceptionMessage)
                        errorMessage += x + AppConstants.comma;
                    errorMessage.Substring(0, errorMessage.Length - 1);
                    errorMessage = errorMessage.Replace(",,", "");
                    errorMessage = errorMessage.Replace(",", " , ");
                    Assert.Fail(errorMessage);
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }

            #endregion
        }
        #endregion

Thanks
Team


If this post help you. Please share it and give your comments on it :)

No comments:

Post a Comment