# Thread: comparing text and validating

1. ## comparing text and validating

Hi,

I am trying to test webpage , where I need to capture sentence from on portlet and validate same text is displayed in other page/tab. I tried with standard check point . But in other page text and cost is together. I need to separete the cost and match.

For example, First page I captured "Mercury quickTest Pro"
, other page I captured "Quality QuickTest Pro \$199.99".

I need to compare two and validate.

Can any one help me?

Thanks,

2. ## Re: comparing text and validating

Comparing two strings that different is always a bit of a challenge.

If you can predict these differences in advancei it helps. Why does "Mercury" turn into "Quality"?

How much of the string needs to match?

One way you could find out is to use the Split function to break the first string into an array. Then search for each part of the array in the second string using the InStr function.

Something like this:
x = "Mercury quickTest Pro"
y = "Quality QuickTest Pro \$199.99"
a = split(x, " ")
intNumTries = 0
intNumMatches = 0
For i = 0 to ubound(a) -1
intNumTries = intNumTries +1
If instr(1, lcase(y), lcase(a(i))) Then
intNumMatches = intNumMatches +1
End If
Next
varMatchRate = intNumMatches / intNumTries

In the above example, varMatchRate is 0.6666666667 indicating that 2 of the three words in "Mercury quickTest Pro" matched something in the "Quality QuickTest Pro \$199.99" text.

In case you're wondering, use GetROPRoperty to get the initial values that you are comparing (in my example, this would be x and y).

3. ## Re: comparing text and validating

What do you want to compare? Is it that If "Mercury quickTest Pro" = "Quality QuickTest Pro \$199.99" then your test should pass? If yes, then use Instr() function for string comparison.

4. ## Re: comparing text and validating

Typo in my question, sorry for confusion

Text I am comparing "Mercury quickTest Pro"
and "Mercury quickTest Pro \$199.99".

I will try your logic and let you know.

5. ## Re: comparing text and validating

You should prefer using vbscript's string functions like Instr()

Search forum or the QTP Help file

6. ## Re: comparing text and validating

Yeah, with the correction to your question, it becomes a simple matter of using Instr() to see if the short version (without the price) is contained within the long version (with the price).

All that stuff I wrote about splitting and looping and matchrate, you won't need any of it now that your strings almost match to begin with.

7. ## Re: comparing text and validating

I used below logic

x = "Mercury quickTest Pro"
y = "Mercury QuickTest Pro \$199.99"
a = split(y, " ")
val-strcomp(x,a,1).
It worked fine.

Now I want to enhance my code.
caturing text will be depending on the login user id.

Now I want to change the code , depening on the login Id , capture the text and compare .

can any one help me.

8. ## Re: comparing text and validating

why are you complicating the logic. As suggested earlier you can use the Instr do the job for you. Also your line

val-strcomp(x,a,1)
doesn`t make sense. what are you trying to achieve in this piece of code.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.