Selenium Is An Open Source Web Application Test Automation Tool
Selenium Is An Open Source Web Application Test Automation Tool
Anybody who worked on manual testing can easily learn Selenium. We will try to explore how to learn Selenium Step by Step.
Selenium has three main tools Selenium IDE, Selenium RC, and Selenium Grid.
Selenium IDE This is a Firefox Add-on (download from openqa download page). Download Selenium IDE and install. Once the IDE is installed, go to tools > click Selenium IDE. This opens up the Selenium IDE as below:
1. 2. 3. 4. 5. 6. 7. 8.
Open a new browser Navigate to www.google.com Click tools > Selenium IDE (opens up IDE) click on Advanced Search link on Google search page type selftechy in all these words: edit box Select 20 results from Results per page drop down Click Advanced Search button Click on File (on Selenium IDE) > Save Test Case As and then give it a name and save the test case
Selenium IDE has recorded around 3-4 test steps. Starting from the first step > right click on each step and then click Execute this command. Execute all the commands one by one.
Try to record some more tests with even more complexity and also record more number of tests. Then try to execute each tests as explained above. By this way you can become more comfortable with Selenium IDE. After this exercise we can go ahead and try to learn exporting the tests in different formats such as Java, JUnit, PHP, C#, etc and also setting up the Selenium RC with Eclipse.
Below are the drawbacks of using Selenium IDE for record and execute tests:
1.
If all the test steps are executed together then the chances of tests getting failed is more because of page load time / objects taking more time to appear on the web page
2. 3.
Parameterization is difficult and values should be hard coded Maintenance is much more difficult, etc.
Setting up Selenium with Eclipse by SEETARAM on MAY 31, 2011 In my earlier post I have explained how to setup Selenium with Eclipse but there I have utilized example of SugarCRM. So, in order to avoid downloading SugarCRM I thought of writing one more post on the same topic which uses Google as example.
Eclipse is an open source Integrated Development Environment which supports multiple languages. Most of the java developers use Eclipse IDE for software development as it is highly extensible with plug-in system and user friendly. We can add external libraries to build path in order to utilize any external APIs available.
In order to setup Selenium in Eclipse, Selenium-Client-driver needs to be added to the Java build path - >Libraries
1. 2. 3. 4. 5.
Download the latest Eclipse release from www.Eclipse.org Create a project. In my example -> PracticeCode. (File ->New-> Java Project ->Give name as PracticeCode) Create Package under this project ->com.selftechy.parameterization Under this package > create a new class (AdvancedSearch.java) Add Selenium-Client-Driver (this needs to be downloaded from www.seleniumhq.org)to Java Build Path of the project: Right click project (PracticeCode) Click Properties Click Java Build Path Click Libraries Click Add External Libraries Select the Selenium-Client-Driver
package com.selftechy.parameterization;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@Before
selenium.start();
@Test
selenium.open("http://www.google.com/");
selenium.click("link=Advanced search");
selenium.waitForPageToLoad("30000");
selenium.click("//input[@value='Advanced Search']");
selenium.waitForPageToLoad("30000");
@After
selenium.stop();
In the above code we can see extends SeleneseTestCase and import com.thoughtworks.selenium.*; these two phrases tell Eclipse that we are going to use Selenese commands in the subsequent methods.
In order to run this test case we need to start the Selenium Server first. Follow the steps below to run the Selenium server.
Download Selenium Server from www.seleniumhq.com Step 1: Create a new text file
Step 2: Open the file and type in following code into it (D:\Workspace-Helios should be changed to the path where selenium-server.jar file is copied)
CD D:\Workspace-Helios java -jar selenium-server.jar -multiWindow (Dont copy and paste as it sometimes adds some special characters)
Step 4: Double click the selenium-server.bat, this should start the selenium server.
Step 4: Still if you are not able to run, then execute both the commands in command prompt (Click Start -> Run ->cmd).
To run the AdvancedSearch.java > Right click the file and click Run As > JUnit Test