4

I've searched around for the answer to this and found lots of much more complicated questions, but none that gave me insight enough to figure this one out.
What I'm doing:
1- open a page with a number that will probably be large
2- get the X Path to where that number is and store it to a variable
3- do a javascript to compare the above stored variable to see if it is bigger than 10, if so, set a new variable to true; else false (because that is the default value)
4- verify the variable in #3 is true

Sounds simple enough, no?

Where it goes wrong:
At step 3, comparing the variable from step #2 to 10 isn't allowed, at least not the way I'm writing it.

Why?

Details:

<tr>
   <td>open</td>
   <td>http://www.google.com/search?hl=en&q=selenium+verifyEval</td>
   <td></td>
</tr>
<tr>
   <td>store</td>
   <td>/html/body/div[5]/div/p/b[3]</td>
   <td>resultCount</td>
</tr>
<tr>
   <td>storeEval</td>
   <td>var isMoreThan10 = new Boolean(); isMoreThan10 = (resultCount &gt; 10);</td>
   <td>isMoreThan10</td>
</tr>
<tr>
   <td>verifyExpression</td>
   <td>${isMoreThan10}</td>
   <td>true</td>
</tr>

I just thought of one possible workaround: Expand the javascript code to get the value there & assign it to a variable there so I'll be more likely to be able to use that variable in the javascript. Not sure exactly how that would be done- anyone wanna help with that?

But surely there is be a better way, isn't there? I must be able to assign a value to a variable in Selenium, then in the next line use that variable in a javascript, right?

3 Answers 3

6

Found the solution. Not only was I doing the storeEval wrong with the way I was setting isMoreThan10; I was setting resultCount wrong with the wrong store call (instead of storeText) and calling resultCount wrong in the storeEval.

Here is the correct way to do it:

<tr>
<td>open</td>
<td>http://www.google.com/search?hl=en&amp;q=selenium+verifyEval</td>
<td></td>
</tr>
<tr>
<td>storeText</td>
<td>//p[@id='resultStats']/b[3]</td>
<td>resultCount</td>
</tr>
<tr>
<td>storeEval</td>
<td>(storedVars['resultCount'] &gt; 10) ? true : false</td>
<td>isMoreThan10</td>
</tr>
<tr>
<td>verifyExpression</td>
<td>${isMoreThan10}</td>
<td>true</td>
</tr>

Thanks to AutomatedTester for suggesting a ternary assignment in storeEval

Sign up to request clarification or add additional context in comments.

Comments

1

This is a simple thing to solve

<tr>
   <td>storeEval</td>
   <td>var isMoreThan10 = new Boolean(); isMoreThan10 = (resultCount &gt; 10);isMoreThan10 ;</td>
   <td>isMoreThan10</td>
</tr>

It requires that you have the result that you want at the end. If you were to use a ternary it would be better since its not storing the result in a variable in the javascript you are passing through.

e.g.

  <tr>
       <td>storeEval</td>
       <td>(resultCount > 10) ? true : false</td>
       <td>isMoreThan10</td>
    </tr>

2 Comments

Did you try your solution in my code? It doesn't work for me, but I think I'm getting closer to the solution. It's still failing at step 3 for the same reason mentioned above, but I may have found a way around that using another way to store and call the variable, as I'll demonstrate momentarily. Thanks for the hint!
Sorry, I didn't see that resultCode was a variable.
0

This type of thing is really using TestPlan (which can run with both Selenium and HTMLUnit as a backend)

GotoURL http://www.google.com/search?hl=en&q=selenium+verifyEval
set %Count% (response //html/body/div[5]/div/p/b[3])
Notice Got Value %Count%
Checkpoint numComp %Count% > 10

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.