I'd like to know how you can automate the registration process for a site that requires a unique email address or username each time, using Selenium IDE. My only thought would be to insert an appropriately formatted random string into the username or email field; this could be done easily with the Python or Java version of the test case code, but what about in the initial Selenium Core syntax?
3 Answers
I normally just record all the steps then prefeace with some JS where i need it.. like...
<tr>
<td>storeEval</td>
<td>Math.round (Math.random() * 1357)</td>
<td>random</td>
</tr>
<tr>
<td>type</td>
<td>email</td>
<td>selenium${random}@domain.com</td>
</tr>
Works best if you have a catch-all address configured for testing @domain.com..
Quick and dirty but does the job, and points dev's in the right direction for when they compile more re-usable test cases or add it to a framework..
-
This is a good approach to things like loadtests where you will be creating a lot of accounts over the course of the test and don't want to be deleting stuff or doing any cleanup mid test (and perhaps don't care about stuff like having the email going to a real address). otherwise I'd prefer my tests cleanup after themselves and leave the system in the state they found it to start with. Commented Jun 23, 2011 at 4:05
-
1Yeah, I made no comment of clean-up but would do the same. We have 'Test Harnesses' with clean data deployed for specific tests.. so in my case "Clean-up" is blow it away and start again... Commented Jun 23, 2011 at 10:29
-
@Chuck I'd prefer they can do that too, but even if it passed my checks of "same state" I wouldn't consider it a viable test environment anymore. I'd insist on a clean slate for each test to ensure reproducibility. @Disco yay for clean slate test environments!– corsiKa ♦Commented Jun 23, 2011 at 17:21
-
@glow : exactly.. "How do you know you're testing the right thing?" ...erm, because my environment says so.. BAM! ;) Commented Jul 6, 2011 at 14:48
our other option is to have some code that removes the user you created (perhaps by talking directly to the database) after the test scenario itself is complete. In a lot of frameworks it's possible to define code to run before or after each test. So for the set of tests that don't cover the 'email already in system' cases, you could have them either being sure that there is no user already in the system that uses that email, before the test runs, or removing it after.
Either one should work.
Generally I'd prefer my tests to always clean up after themselves, but sometimes it's hard to have that happen reliably.
If there's a lot of issues getting a cleanup step to run after tests that fail or something, then go for it at the start of the test.
If you want to actually receive an email (and you have a gmail account) with each test run, you can use something like this:
<tr>
<td>runScript</td>
<td>emailRandom=document.getElementById('email');console.log(emailRandom.value);emailRandom.value="myEmail+" + Math.floor(Math.random()*11111)+ "@gmail.com";</td>
<td></td>
</tr>
This is a variation of one of the answers for Stackoverflow Question.