Generate Random Email Address

In test automation generate random email address is very important. For example if we want to automate a signup page every time we need to generate a unique email address to complete the signup process successfully. In this section we will show how to generate random email address using selenium IDE.

There are two ways to generate random email address in selenium IDE.
    1. Using selenium script command.
    2. Using external user extension.

Using selenium script command:
 
           ➤ Here we use “Math.round(Math.random()*1357)” function to 
                generate random email address.

  Test Case-1:
Command
Target
Value
open
https://www.xoom.com/

clickAndWait
//div[@id='homeactionbtn']/div/a/span/span

storeEval
Math.round(Math.random()*1357)
random
type
id=j_username
selenium${random}@domain.com

If we run the following test case in several times we can observe that a randomly generated unique email is inputted automatically every time in the Email address field.

Using external user extension:

           ➤ Save the following code as ‘random_email.js’ file.

Selenium.prototype.doTypeRandomEmail = function(locator) {
   /**
   * Sets the value of an input field to a random email id,
   * as though you typed it in.
   *
   * @param locator an <a href="#locators">
element locator</a>
   */

   // All locator-strategies are automatically handled by "findElement"
   var element = this.page().findElement(locator);

   /* The following block generates a random email string */
   var allowedChars = "abcdefghiklmnopqrstuvwxyz";
   var stringLength = 8;
   var randomstring = '';

   for (var i=0; i<stringLength; i++) {
       var rnum = Math.floor(Math.random() * allowedChars.length);
       randomstring += allowedChars.substring(rnum,rnum+1);
   }

   // Append a domain name
   randomstring += "@domainname.com"

   // Replace the element text with the new text
   this.browserbot.replaceText(element, randomstring);
};

        
          ➤ Now import the  ‘random_email.js’ file into selenium IDE.
                 Step-1: Open Selenium IDE.
                 Step-2: Click on Option.
                 Step-3: Select Option.
                 Step-4: Browse and open  ‘random_email.js’ file.
             
            

                    Step-5: Restart the selenium window.

        ➤ Here we showing a practical example of this user extensions.

Test Case-02:
Command
Target
Value
open
https://www.xoom.com/

clickAndWait
//div[@id='homeactionbtn']/div/a/span/span

typeRandomEmail
//*[@id='j_username']


If we run the following test case in several times we can observe that a randomly generated unique email is inputted automatically every time in the Email address field.

Date Function in selenium IDE.

In this section we will show how to manage, store and print date using selenium IDE.
First describe how to store current date in a variabe and print the date.

Test Case-01:
Command
Target
Value
storeEval
Date();
currentdate
echo
${currentdate}


Here,
 - storeEval is using for store todays date.
 - Date() is a function which specify the todays date.
 - currentdate is a variable which reserve the todays date.
 - echo is using for print the variable currentdate.




Selenium IDE commands:



First we will describe the mostly using command “open”.
There are three types of “open” commands these are:
open, openWindow and openWindowAndWait.

"open" Command

"open" command is using to open the website whatever we want to open in our browser or tab.

Here is a simple example or script  to open a website in our browser using selenium IDE “open” command:

Test case-01:
Command
Target
Value
open
http://www.xoom.com/


"openWindow" Command

openWindow” command is mostly same as “open” command but simply difference is:
When we use “open” command this open an website using a new tab of a browser on the other hand “openWindow” command open an website using a new browser window.

Here is a simple example or script  to open a website in our browser using selenium IDE “openWindow” command:

Test case-02:
Command
Target
Value
openWindow
http://www.xoom.com/



"openWindowAndWait" Command

openWindowAndWait” command is mostly same as “openWindow” command but simply difference is:
When we use “openWindowAndWait” command it will showing a error message for timed out.
If website is not loaded within 3000ms.