Wednesday, February 23, 2011

Incremental Variables in Selenium

I needed to create 50 names that were similiar and incremental (ex: Tracey1, Tracey2, Tracey3, etc.). I used javascript to increment the numbers.

<!--Here I store the alpha-text part of my name as variable 'a'. This allows me to change this later to something else.-->

<tr>

<td>store</td>

<td>Tracey</td>

<td>a</td>

</tr>

<!--This increments the number ('y'), starting at 1-->

<tr>

<td>store</td>

<td>1</td>

<td>x</td>

</tr>

<tr>

<td>storeEval</td>

<td>storedVars['x'] = ${x}+1</td>

<td>y</td>

</tr>

<!--Here I type the name-->

<tr>

<td>type</td>

<td>fieldname</td>

<td>${a}${y}</td>

</tr>

<!--And the next time I need to type the name, I just increment 'y' by one-->

<tr>

<td>storeEval</td>

<td>storedVars['y'] = ${y}+1</td>

<td>y</td>

</tr>

<tr>

<td>type</td>

<td>fieldname</td>

<td>${a}${y}</td>