Ask a Question

I'm trying to use CheckProperty with RegExpressions.

SOLVED
cauline
Contributor

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.

7 REPLIES 7
Marsha_R
Champion Level 2

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.

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

tristaanogre
Esteemed Contributor

First, change cmpEqual to cmpMatches.  

 

I can't attest to the validity of the regular expression... I honestly have never gotten the hang of writing those... something I need to get better at.  But, if you're going to use a regular expression, you need to use cmpMatches.  See https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqobject/checkproperty.htm...


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

I am trying to do this with multiple browsers, which causes the cmpMatches to fail.  It looks like different browsers render the HTML with more or less control characters (\n \t) which causes the cmpMatches to fail.

tristaanogre
Esteemed Contributor

You may need to create some sort of Switch statement to set your regular expression.  Define a regular expression for each browser type, set it on a case of the browser, and then call it in your check Property.

An alternative is that, if you don't need to compare the ENTIRE string but only check a certain part of the string, you could us cmpContains and just enter the relevant portion into the Value parameter.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
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.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

Thanks, I'll give it a whirl!

cancel
Showing results for 
Search instead for 
Did you mean: