locked
Tests that ran successfully are failing RRS feed

  • Question

  • Hello,

    I ran the tests successfully but after sometime they are failing for space issues.  I am hand coding and the the objects are getting recognized but the asserts are failing. See the assert error below, it has lot of spaces in the actual message but when I ran the same before it was not the case.

    Assert.AreEqual failed. Expected:<Zip Code:  * Not a valid zip code>. Actual:<Zip Code:

    * Not a valid zip code

     >. 

    This is happening for almost all the fields I can fix the spaces to get the pass result but wanted to know why it happened in order to avoid future issues of this type.

    Any help on this would be appreciated.

    Thanks

    BK


    BK

    Friday, June 6, 2014 2:37 PM

Answers

  • BK,

    That was a general idea on how to solve your problem. The thing is, your actual value may contain anything other than white spaces such as new line character or combination of '\r' and '\n'... You need to cleanup it before comparing to expcted value.

    Hope you got the point.


    TejasJ.

    Tuesday, June 10, 2014 2:01 PM
  • Tejas,

    Thank you. I fixed my code by changing the properties. But you suggestion helps.


    BK

    Thursday, June 12, 2014 3:40 PM

All replies

  • Well, it depends on the type of object you are comparing through Assert.AreEqual and the ToString and/or Equals implementation of that class. Can you please provide that code here?

    TejasJ.

    Monday, June 9, 2014 5:16 AM
  • Here is the code,

    //Object

    private HtmlDiv errorMsgSSNZip;
       public HtmlDiv ErrorMsgSSNZip
       {
          get
           {
            if (errorMsgSSNZip == null)
            {
               errorMsgSSNZip = new HtmlDiv(br);
               errorMsgSSNZip.SearchProperties.Add("InnerText", "Zip Code:  * Not a valid zip code");
               errorMsgSSNZip.FilterProperties.Add("TagInstance", "148");
             }
                return errorMsgSSNZip;
            }
         }
    //Action-entering characters in a number field
    OLRAUIObject.ROZip.Text = "abcd";           
    //Verification
      try
       {
         string expectedresult67 = "Zip Code:  * Not a valid zip code";
         string actualresult67 = OLRAUIObject.ErrorMsgSSNZip.DisplayText;
         Assert.AreEqual(expectedresult67, actualresult67, "  \n 1. When characters are entered in Zip Code an error message is NOT displayed.");
         Console.WriteLine("  1. When characters are entered in Zip Code an error message is displayed.");
        }
         catch (AssertFailedException e)
       {
         Console.WriteLine("  1. When characters are entered in Zip Code an error message is NOT displayed.");
          isTestFailed = true;
          errorMessage = errorMessage + "\n\n" + e.Message;
        }


    BK

    Monday, June 9, 2014 12:49 PM
  • Okay this is the inner text value of a div control. This is likely yo happen due to changes in the application code. The actual value of text in the application's div control has multiple white spaces added. You should always trim the innertext of the div before comparing it:

    string expectedresult67 = "Zip Code:  * Not a valid zip code";
          string actualresult67 = OLRAUIObject.ErrorMsgSSNZip.InnerText.Trim();
          Assert.AreEqual(expectedresult67, actualresult67, "  \n 1. When characters are entered in Zip Code an error message is NOT displayed.");
          Console.WriteLine("  1. When characters are entered in Zip Code an error message is displayed.");
    One more thing is here, because you are sure that the error message will apper, you have used the error message text itself as the searchproperty. Ideally, you should use another property such as Id or name to search for the error message div and then assert the message text.

    TejasJ.

    Monday, June 9, 2014 1:59 PM
  • Hi Tejas,

    I tried that way but it is not working. I am using the error message it self because there is no ID.  Any other suggestion please.

    Thanks

    BK


    BK

    Tuesday, June 10, 2014 1:25 PM
  • BK,

    That was a general idea on how to solve your problem. The thing is, your actual value may contain anything other than white spaces such as new line character or combination of '\r' and '\n'... You need to cleanup it before comparing to expcted value.

    Hope you got the point.


    TejasJ.

    Tuesday, June 10, 2014 2:01 PM
  • Tejas,

    Thank you. I fixed my code by changing the properties. But you suggestion helps.


    BK

    Thursday, June 12, 2014 3:40 PM