Forum Discussion
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
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.
- tristaanogre9 years agoEsteemed 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.html
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.
- tristaanogre9 years agoEsteemed 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.