Wednesday, 10 September 2014

Selenium - Environment Setup


In order to develop Selenium RC or Webdriver scripts, users has to ensure that they have the initial configuration done. There are lot of steps involved in setting up the environment. Let us go through one of the areas in detail.
  • Download and Install Java
  • Download and Configure Eclipse
  • Configure FireBug and FirePath
  • Configure Selenium RC
  • Configure Selenium Webdriver

Download and Install Java

We need to have JDK (Java Development Kit) installed inorder to work with Selenium Webdriver/Selenium. Let us look at how to download and Install Java.
Step : 1 Navigate to the URL : http://www.oracle.com/technetwork/java/javase/downloads/index.html
Step : 2 Goto "Downloads" Section and Select "JDK Download".
Selenium IDE 30
Step : 3 Select "Accept License Agreement" radio button.
Selenium IDE 31
Step : 4 Select the appropriate installation. In this case it is 'Windows 7-64' bit. Click the appropriate link and Save the .exe file to your disk.
Selenium IDE 32
Step : 5 Run the downloaded exe file and the Installer wizard is launched. Click 'Next' to continue.
Selenium IDE 33
Step : 6 Select the Features and click 'Next'.
Selenium IDE 34
Step : 7 The installer is extracted and the progress of the same is shown in the wizard.
Selenium IDE 35
Step : 8 The user can choose the install location and click 'Next'.
Selenium IDE 36
Step : 9 The installer installs the JDK and new files are copied across.
Selenium IDE 37
Step : 10 The Installer installs successfully and displays the same to the user.
Selenium IDE 38
Step : 11 To verify if the installation is successful, goto command prompt and just type 'java' as a command. The output of the command is shown below. If the Java Installation is unsuccessful or if it had NOT been installed it would throw, "unknown command" error.
Selenium IDE 48

Download and Configure Eclipse

Step : 1 Navigate to the URL : http://www.eclipse.org/downloads/ and download according to your OS architecture.
Selenium IDE 39
Step : 2 Click 'Download' button.
Selenium IDE 40
Step : 3 The download would be in a Zipped format. Unzip the contents.
Selenium IDE 41
Step : 4 Locate the Eclipse.exe and double click on the file.
Selenium IDE 42
Step : 5 To Configure the workspace select the location where the development has to happen.
Selenium IDE 43
Step : 6 The Eclipse window opens as shown below.
Selenium IDE 44

Configure FireBug and FirePath

To work with Selenium RC or Webdriver, we need to locate element based on their xpath or ID or name etc. Inorder to locate an element we need tools/plugins. Various ways of locating an element is dealt in detail in locators chapter.
Step : 1 Navigate to the URL : https://addons.mozilla.org/en-US/firefox/addon/firebug/ and download plugin.
Selenium IDE 62
Step : 2 The addon installer is shown to the user and it is installed upon clicking 'Install' button.
Selenium IDE 63
Step : 3 After Installing, we can launch the plugin by navigating to "Web Developer" >> "Firebug".
Selenium IDE 64
Step : 4 Firepath, a plugin which works within Firebug helps user to grab 'Xpath' of an element. Install Firepath by navigating to "https://addons.mozilla.org/en-US/firefox/addon/firepath/"
Selenium IDE 65
Step : 5 The addon installer is shown to the user and it is installed upon clicking 'Install' button.
Selenium IDE 66
Step : 6 Now launch "Firebug" by navigating to "Tools" >> "Webdeveloper" >> "Firebug"
Selenium IDE 67

EXAMPLE

Now let us understand how to use firebug and firepath with an example. For demo purposes, we will make use of www.google.com and capture the properties of the text box of "google.com".
Step : 1 First Click on the arrow icon as highlighted in the below screenshot and drag it to the object for which we would like to capture the properties. The HTML/DOM of the object would be displayed as shown below. We are able to capture the 'ID' of the input text box with which we can interact.
Selenium IDE 68
Step : 2 To fetch the xpath of the object, go to 'firepath' tab and perform the following steps.
  • Click on the Spy icon.
  • Select the Control for which we would like to capture the xpath
  • Xpath of the the selected control would be generated
Selenium IDE 69

Configure Selenium RC

Now let us look at how to configure Selenium Remote control. We will understand how to develop scripts with Selenium RC in upcoming chapters, however for now we will understand just the configuration part of it.
Step : 1 Navigate to the selenium downloads section http://www.seleniumhq.org/download/ and download Selenium Server by clicking on its version number as shown below.
Selenium IDE 45
Step : 2 After Downloading we need to start the Selenium Server. To do the same, open command prompt and navigate to the folder where the downloaded JAR file is kept as shown below.
Selenium IDE 46
Step : 3 To Start the server, use the command 'java -jar <<downloaded jar name >> and if java JDK is installed properly you would get a success message as shown below. Now we will be able to start writing Selenium RC scripts which will be dealt in the next chapter.
Selenium IDE 47

Configure Selenium WebDriver

Now let us look at how to configure Selenium Webdriver. We will understand how to develop scripts with Selenium Webdriver in upcoming chapters, however for now we will understand just the configuration part of it.
Step : 1 Navigate to the selenium downloads section http://www.seleniumhq.org/download/ and download Selenium Webdriver by clicking on its version number as shown below.
Selenium IDE 49
Step : 2 The downloaded file is in Zipped format and one has to unzip the contents to map it to the project folder.
Selenium IDE 49
Step : 3 The Unzipped contents would be displayed as shown below. How to map it to the project folder and how to start scripting would be dealt in webdriver chapter.
Selenium IDE 51

No comments:

Post a Comment