Forum Discussion

grant_volker_2's avatar
grant_volker_2
Contributor
13 years ago

How to handle whitespace changes within text with contentText and Excel data driver

Hi,



I have experienced some test failures where double white space in between text and at the end of sentences exists.



An Excel data driver is being used with text copied from the contentText within the Object Spy (Please refer to the

example screen shot). The text originally had no double white space. However, double whitespace was introduced

between text and at the end of the sentences during a sprint, which caused the test to fail.





I refer to contentText Property (Web Objects)



"Replaces subsequent whitespace characters (spaces, tabs, non-breaking spaces, line breaks and so on) with a single space.

Trims whitespace at the beginning and the end of the value."





I tried making use of an asterisk at the end of each line of text in the data driver text, but this did not resolve the

issue. It was necessary to re-copy the text from the Object Spy for the test to pass, but then the text was again altered

during a sprint to remove the double whitespaces, causing the test to fail yet again.



Does anyone have suggestions on how to handle whitespaces, to avoid constantly updating the data driver please?



Thank you

  • I'm having a similar issue... IE, Chrome, and FF don't all report the same characters from innerText. Some will have two spaces, others have one space, and sometimes I see <LF>s in the text (which is indistinguishable from whitespace in the log viewer. I really don't want to have to process the text that I get from the page or have an expected result from each browser but I'm at a loss what to do now. Anyone have any ideas?
  • Ravik's avatar
    Ravik
    Super Contributor
    Hi,



    We can used "Trim" function, It will be removed white space if it is in object. we also be use RTrim and LTrim to remove (RTrim for - Remove right side space and LTrim for - Remove left site Space)
  • Thanks for the response... I'm already using trim(). The problem I'm having is that the extra characters are in the middle of the string. It's probably not random but I haven't figured out the pattern yet.

  • Hi Jeff,


     


    You can use a regular expression to remove extra characters. For example:




      var str = "This is    a test   ";


      var newStr = str.replace("\\s+", " ");


      Log.Message(newStr);