Forum Discussion

mikej411's avatar
mikej411
Occasional Contributor
9 years ago
Solved

How to represent End Line in a String for TestComplete using Javascript

I need to verify a warning message in TestComplete that has multiple lines for it's innerText property. The innerText looks like this:

 

First Line


Second Line

To do that, I thought using \n would be able to represent the end lines

 

  if(warningMessage.innerText == "First Line\n\n\n\nSecond Line")
    Log.Checkpoint("Pass");
  else
    Log.Error("Fail"); 

 But it failed. How can I verify this warning message?

  • So I found 2 solutions:

    1. I used contentText property as suggested above. This passes only when I include one "\n". My warning label has 3 line-breaks when visually verifying, so this method doesnt accurately verify the message. See below:

     

     if(warningMessage.contentText== "First Line\nSecond Line")
        Log.Checkpoint("Pass");
      else
        Log.Error("Fail"); 

     

    2. The next solution is using the innerText property, but instead of "\n", I have to use "\r\n". I'm not sure why this works, as it was just a suggestion in another forum

     

     if(warningMessage.innerText== "First Line\r\n\r\n\r\nSecond Line")
        Log.Checkpoint("Pass");
      else
        Log.Error("Fail"); 

5 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

    what is the value of  

    warningMessage.innerText

     ............?

    most probably TC may be reading it as a single line of string (is it?)

    if so it's easy as 

    warningMessage.innerText == " entire text Line"

    if you need to read part of text, can do with aqString.Find

     https://support.smartbear.com/viewarticle/71913/

    • mikej411's avatar
      mikej411
      Occasional Contributor

      The value of innerText is exactly what I pasted in the original post. When I paste it in notepad, It shows text on the first line, then it has a couple end lines and shows the next set of text. Could that be an Array inside innerText? I never saw that before.

       

      Anyway, the warning message label in question is a web element with the following attribute:

      <SPAN id=warningMessageLabelID>First Line<BR><BR> <CENTER>Second Line</CENTER></SPAN>

       

      If I cant find a solution to verifying End Lines with text, then I can use the aqString.Find workaround. Thanks

      • UnveN's avatar
        UnveN
        Staff

        Hello!

         

        Try contentText property. It is similar to the innerText but normalizes white spacing ensuring /n as the line-break character (in JScript).