Google+

14. Record and Playback using Selenium IDE







Prerequisite - Install Selenium IDE as shown in the Post#11 Install Selenium IDE

Recording Process:

1. Launch Firefox and open Selenium IDE from Tools Menu as shown below:



2. Ensure that the Selenium IDE is launched as shown below:



3. After the Selenium IDE is launched, ensure that the Recording Button is turned on by default. (i.e. Selenium IDE is in recording mode by default on launching) as shown below:


4. While the recording button is enabled, open any website say www.google.com in the Firefox browser as shown below:


5. In the 'Google' page, click on 'I am feeling lucky' button as shown below:

6. Turnoff the 'Recording' button on the Selenium IDE to stop recording as shown below:


7. Ensure that the recorded commands are displayed under the table tab as shown below:


Playback Process:


8. Open any other site say www.yahoo.com in the Firefox browser and Click on the 'Play current test case' button on the Selenium IDE as shown below:


Click  this image to view Full Screen

9. On clicking the 'Play current test case' button, observe that the recorded commands are executed automatically in the Firefox Browser (i.e. User is taken to the www.google.com in the Firefox browser and 'I am Feeling Lucky' button is clicked automatically as shown in the below video




Note - Though 'Record and Playback' feature is helpful in some cases to the Tester, but it cant be used for automating all the tests as it has many disadvantages. If you don't know much about the disadvantages of the Record and Playback feature, you can go through the Page Record & Playback else you can continue reading the next post.





Please comment below to feedback or ask questions.

How to validate elements using Selenium IDE will be explained in the next post.





13. What is Selenium IDE ?





The following are the four Selenium Automation tools -

1) Selenium IDE
2) Selenium RC
3) Selenium WebDriver
4) Selenium Grid

Selenium IDE is a firefox extension which is used to record the tests like recording a video and playback the recorded tests like playing a video.

Using Selenium IDE we can create Selenium Automation Code without writing the code instead the code gets generated automatically when we record the tests using Selenium IDE. Where as with Selenium RC and Selenium WebDriver tools we need to write the code ourselves.

We use Selenium RC and Selenium WebDriver to write automation scripts for complex projects where as Selenium IDE can only be used to automate simple projects.

Can we ignore Selenium IDE as we can automate all our tests using Selenium 1 and Selenium 2 ?

No, you cannot ignore Selenium IDE. It is the only selenium tool which has record and playback feature.Selenium 1 and Selenium 2 don't have this feature. We can use Selenium IDE to automate simple project.

Why to record and playback ?

There are two reasons to record and playback.
Reason#1 - In order to automate simple scripts, the tester may not require Selenium 1 and Selenium 2 tools, hence tester will just record and playback using Selenium IDE.
Reason#2 - While automating tests using Selenium 1 or Selenium 2, the tester may face problems while writing the automation scripts. In this case the tester will record and playback the test using the Selenium IDE tool and view the automation code generated by the tool. He/She will compare his Selenium 1 or Selenium 2 self written code with Selenium IDE's auto generated code, and make necessary changes to his Selenium 1 or Selenium 2 code in order to make it work.

Advantages of Selenium IDE:
  • Easy for beginners i.e. Requires less or no software development
  • Takes very less time to automate
  • An excellent way of learning Selenium Script Syntax in your desired programming language.
Disadvantages of Selenium IDE:
  • Not suitable for complex applications - Reason -  If something say Application URL gets changed, we need to record all the tests from the beginning. Where as in Selenium RC and Selenium WebDriver, we can change it from a single location such that the URL gets updated in all the test automation scripts. So we cannot maintain the scripts generated using Selenium IDE.
  • Repetition of the code - Reason - Lets say there are two tests. Test1 -> Login to Gmail, View Unread Emails and Logout. Test2 -> Login to Gmail, Send Email and Logout. When we use Selenium IDE to record these tests it will generate automation code for separate Login and Logout actions. So code is repeated. Where as in Selenium RC and Selenium WebDriver we can write automation code for Login & Logout actions and move them to Methods/Functions.  So Test1 will call Login and Logout functions and also Test2 will call the same Login and Logout functions. Hence code is not repeated.
  • Code is not readable as it contains Hard coded values - Reason - Selenium IDE records what ever the actions the User performs while recording a test, hence the code contains Hard coded values. Lets say the User has recorded the Test -> Login to Gmail with User Name - arunmotoori and Password - selenium143 using Selenium IDE. When you read the code that is automatically generated by the Selenium IDE, it will contain the Hard coded values arunmotoori and selenium143. By reading the code we dont know what arunmotoori and selenium143 are. Were as in Selenium RC and Selenium WebDriver we can Parameterise these Hard coded values by replacing them with a valid variable names like Username and Password. Hence the code becomes readable. 
  • Cannot create constants - There are few constants like Application URL, Usernames etc. Since the recorded code contains Hard Coded values, whenever some functionality gets changed say Application URL, we need to read all the recorded tests and make changes to all the tests containing Hard coded Application URL. But where as in Selenium RC and Selenium WebDriver we can parameterise the hard coded values with readable variable names say Applicaition_URL in this case. These variables will be saved as constants in a different place. If the application URL changes in this case, we just update the saved constant with new URL only once, hence no need to reading the code of all the tests.
  • Data Driven tests are not possible - Suppose if you want to run the same Test say -> Login to Gmail with say 100 different Users. Using Selenium IDE you have to record 100 tests (each test for each User). Instead if you use Selenium RC or Selenium WebDriver you can create single test by parenthesizing the User details in the test. Hence you can pass 100 Usernames to the same variable and run the same test 100 times.
  • Hence Framework implementation is not possible - Automation Framework is a set of guidelines like 'Code Re-usability, 'Parametrization' etc. Hence Framework implementation is not possible with Selenium IDE. It is possible with Selenium RC and Selenium WebDriver.





Please comment below to feedback or ask questions.

How to record and playback using the Selenium IDE tool will be explained in the Next Post




12. Install Selenium IDE






Selenium IDE - is a Firefox extension. It is generally used to record and playback the tests. We can simply record the tests like recording a video and play the tests like playing the recorded video.

So lets first install the Selenium IDE before understanding it in depth by following the below steps:

1. Launch Firefox Browser
2. Open http://seleniumhq.org/download/
3. Download the latest version of Selenium IDE by clicking the link as shown below:



4. Click on 'Add to Firefox' button in the displayed 'Mozilla Add-ons' page as shown below:



5. Click on 'Install Now' button on the 'Software Installation' dialog as shown below:



6. Click on the 'Restart Now' button when asked by the Firefox browser as shown below:



7. After Restarting the Firefox Browser, click on the Firefox ->'Tools' menu and ensure that 'Selenium IDE' option is displayed as shown below:


8. Click on the 'Selenium IDE' option under the Tools Menu and ensure that the 'Selenium IDE' is launched as shown below






Please comment below to feedback or ask questions.

How to use Selenium IDE in Selenium Automation will be explained in the Next Post




11. Whats Next ?






Till now we have gone through some introductory posts on Selenium. Going forward we will be learning the following items step by step:

Step1  -> Selenium IDE
Step2  -> Core Java
Step3 -> Xpath Locators
Step4 -> CSS Selector Locators
Step5  -> Selenium RC
Step6  -> Selenium WebDriver

So our next posts will be on Selenium IDE. As its not required to learn Selenium IDE in depth . I have only provided the posts that are required to learn Selenium IDE to the required extent. Learning Selenium IDE in depth will be a waste of time. So only go through the posts that are provided in this blog. Again additional learning of Selenium IDE is a waste of time.




Please comment below to feedback or ask questions.

How to install Selenium IDE will be explained in the next post.




7. Install Java JDK and Configure






Eclipse IDE is required to develop Selenium Automation Scripts in Java programming language. But we cant run Eclipse IDE without having Java Development kit (JDK) installed in our machines. So we have to install Java JDK first as explained in the below steps:

1. Open http://www.oracle.com/technetwork/java/javase/downloads/index.html in any browser
2. Select 'Java Platform (JDK) category' to download Java JDK as shown below -



3. Select the 'License Agreement' as shown below:



4. Download the 32 bit version of Java JDK (i.e. Windows x86 in the below screen) if you have 32 bit machine else if you have 64 bit machine install 64 bit version of Java JDK  (i.e. Windows x64 in the below screen) -



5. Install the downloaded JDK file and ensure that JDK and JRE folders got created at the C:\Program Files (x86)\Java folder path for 32 bit machine (But for 64 bit machine they will get created at the C:\Program Files\Java folder)



Configuring the Java JDK:

Follow the below steps to configure the Java JDK:

We have to configure the Java by configuring the build path.

If you want to save the created java files outside the bin folder then you have to set path of JDK. Path is required for using Javac and Java tools. Javac tool compiles the Java code and Java tool will run the code.

How to set path of JDK will be explained below:

1. Click on 'My Computer' icon on your desktop as shown below - 



2. When your drives are displayed in your My Computer window, right click any where inside the window and select 'Properties' option as shown below -



3. Click on 'Advanced System Settings' option as shown below:



4. Click on 'Environment Variables Button as shown below:



5. Click on 'New' button under the User variables as shown below:



6. Type 'path' into the 'Variable Name' as shown below:



7.  In 32 bit machines -> Go to C:\Program Files (x86)\Java\jdk[Version]\bin folder and copy the path of the bin folder as shown below (But in 64 bit machines -> You need to go to C:\Program Files\Java\jdk[Version]\bin folder )




8. Paste path of the bin folder in Variable Value field as shown below and click on 'OK' button



9. Ensure that the path is added under the User variables and Click on 'OK' button as shown below to finish the process




Check whether the Installed and configured Java works:

1. Open Windows Command line as shown below:



2. Type the command java -version in the Command line window as shown below and press 'Enter' key on your keyboard as shown below:


3. Ensure that the Java version we've installed and configured is displayed on executing the command specified in step 2 as shown below:




If you see the version of Java that is installed as shown in the above screenshot, it means that your Java is working.

Now you are ready to compile and run any java program.


Notes - 

1. You can also install JRE (Java Run Time Environment) instead of JDK (Java Development Kit). You can use Eclipse IDE and develop automation scripts when you install JRE instead of JDK prior to installing Eclipse IDE as Eclipse IDE contains its own features for developing and compiling Java.

2. If you want to Run Java Programs using any other editors instead of Eclipse IDE, then installation of Java JDK is must as the editors wont have  features to develop and compile Java programs. So installing JRE prior to running Java programs on any other editors instead of Eclipse IDE wont work. JDK is must in this case.

3. When you are running your automation scripts developed using Java programming language on Eclipse IDE, you can simply install JRE instead of JDK if you want to save your computers memory. JRE installation take less time and less memory to store.





Please comment below to feedback or ask questions.

How to install Eclipse IDE will be explained in the next post.



10. How to create projects in Eclipse IDE ?







Prerequisites: Launch the Eclipse IDE as explained in the previous post #9 (How to Launch Eclipse IDE)

1. Close the 'Welcome' screen if you are launching the application for the first time as shown below:



2. Ensure the panes shown in the below image are displayed:


3. Click on 'File' Menu and select New -> Project option as shown below



4. Ensure that 'New Project' dialog with 'Select a wizard' text is displayed as shown below:



5. Scroll down in the 'Select a wizard' dialog and double click on  'Java Project' under the 'Java' folder as shown below:



6. Ensure that 'New Java Project' dialog is displayed as shown below:



7. In 'New Java Project' dialog, provide a Project Name (for example say 'First Project') as shown below:



8. In 'New Java Project' dialog -> under 'JRE' column, select 'Use a project specific jre' radio  as shown below: (So every time you create a project you have to select the java version that you want to use with the project)



9. We have to select the version of the JRE from the dropdown list beside to the above selected radio option. In order to select we have to know the version of the JRE we have installed in our system by following the next steps

10. Ensure that you have installed 32 bit or 64 bit version of Java JDK as explained in the previous post Post # 7 Install Java JDK and Configure  and if 32 bit -> Go to the Folder path C:\Program Files (x86)\Java as shown below (if 64 bit -> Go to the Folder path C:\Program Files\Java )


11. Note down the version of JRE installed along with the installed Java JDK as shown below:


12. From the above screenshot, its very clear that we have jre7 version installed in our system. Now lets select the same version in the 'Eclipse IDE' -> 'Use a project specific JRE' as shown below:



13. Click on 'Finish' button on the 'New Java Project' dialog
14. Ensure that 'Open Associated Perspective?' dialog with text 'This kind of project is associated with Java perspective' is displayed as shown below ( Click on 'Yes' button this dialog)


11. Ensure that a 'New Project' is created under the Package explorer pane as shown below: (In this example it is named as 'First Project' )



Now we know how to create java projects in Eclipse IDE. How to use the created Java Projects for writing Selenium Automation scripts will be explained later.




Please comment below to feedback or ask questions.

Whats Next?  in the next post