Forum Discussion

cauline's avatar
cauline
Contributor
8 years ago

I'm trying to use CheckProperty with RegExpressions.

Has anyone used RegExp with aqObject.CheckProperty?  I am trying to locate string(s) within a 'innerText' property, while ignoring white spaces (\n \t\ and spaces).  I am using JavaScript.


  • cauline wrote:

    I am trying to verify property text of a Web Page table, but it has a bunch of control chars (\n \t) that I want to ignore:


    You could process the textContent value to remove extra whitespace and replace the control characters with usual spaces:

    var str = browser.___.textContent;
    str = str.replace(/\s+/g, ' ');  // replace consecutive \r \n \t etc. with a single space
    str = aqString.Trim(str); // remove leading and trailing whitespace
    
    aqObject.CompareProperty(str, cmpEqual, "expected value", false);

    Note the usage of CompareProperty instead of CheckProperty, because we check the variable value (str) rather than the textContent property directly. Also make sure the expected value has the same normalized format as the value being checked.

  • Please give us more specifics so we can give you a better answer.

     

    It helps a lot if you show us exactly what you tried, what results you got, and what results you wanted instead.

    • cauline's avatar
      cauline
      Contributor

      I am trying to verify property text of a Web Page table, but it has a bunch of control chars (\n \t) that I want to ignore:

       

      aqObject.CheckProperty(browser.pageUatUlineComProductDetailH101.form.panelDvchart.table.table, "textContent", cmpEqual, "\n\nMODELNO.\nPRICE EACH\nADD TOCART\n\n\n1\n2\n6+\n\n\nH-101\n$17\n$15\n$13\n\nADD\n\n", false);

       

      When I run the CheckProperty with the cmpEqual test, I simply want to ignore the newline and tab characters.

       

      Thanks,

      C

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        cauline wrote:

        I am trying to verify property text of a Web Page table, but it has a bunch of control chars (\n \t) that I want to ignore:


        You could process the textContent value to remove extra whitespace and replace the control characters with usual spaces:

        var str = browser.___.textContent;
        str = str.replace(/\s+/g, ' ');  // replace consecutive \r \n \t etc. with a single space
        str = aqString.Trim(str); // remove leading and trailing whitespace
        
        aqObject.CompareProperty(str, cmpEqual, "expected value", false);

        Note the usage of CompareProperty instead of CheckProperty, because we check the variable value (str) rather than the textContent property directly. Also make sure the expected value has the same normalized format as the value being checked.