1

I'm coding Selenium scripts for automatically testing a signup process.

I have two variables that need to be incremented and stored to be used in future sessions so the scripts can be used again and again without these unique key items being re-used, which would generate an error.

Where I'm getting tripped up is that the primary variable I need to increment is on the front of a text string, not the back, so suffix++ won't work.

For various reasons I cannot explain logically, the emails MUST be formatted like this:

XXXXtest@email.com

So, let's say I'm starting with 1000test@email.com, I'd want to increment to 1001test@email.com the next time the script is run.

I'm a relative newbie to Selenium (but not to automated testing) and -completely- without Javascript knowledge.

4

1 回答 1

0

如果您使用的是 Selenium IDE,请查看此链接How to add random to variable

Selenium IDE 的示例:

<tr>
    <td>store</td>
    <td>javascript{var today = new Date(); var dd = today.getDate(); var mm = today.getMonth()+1; var yyyy = today.getFullYear(); var hour = today.getHours(); var min = today.getMinutes(); if(dd&lt;10){dd='0'+dd} if(mm&lt;10){mm='0'+mm} today = mm+'-'+dd+'-'+yyyy+ '-'+hour+'-'+min+'-' + Math.floor((Math.random()*10)+1);}</td>
    <td>number</td>
</tr>

<tr>
    <td>echo</td>
    <td>${number}</td>
    <td></td>
</tr>

number = "11-08-2013-10-10-10" 今天日期 + 随机数

于 2013-11-08T08:11:29.973 回答