Thursday 9 April 2015

Setting up Selenium WebDriver Environment for first Automated Script

Lesson 4- How to set environment and how to automate Web Applications with Selenium WebDriver.
To write automated scripts with Selenium Web Driver we must have coding knowledge of any programming language like java,C#,python so on.
Before writing scripts we must know these questions.What is difference between Selenium IDE and Selenium WebDriver? What are the requirements to automate any web application? What are the advantages of the Selenium WebDriver? Which language is best with automation? Come back to our topic supposing that you know answers of the asked questions.Let's start setting environment and Web application automation with Selenium Driver.

Here I will prefer Selenium WebDriver Integration with Java language and following requirements are necessary for Automation.

  • JDK (java development Kit)
  • Eclipse IDE
  • Selenium WebDriver library
  • Selenium IDE
  1. How to download and install Jdk?
Go to here to download latest version of the Jdk w.r.t your Operating System.After successful downloading of jdk run the .exe file to install the java development kit(Jdk).

  •  How to set Java_Home path variable on Windows?

Go to the Properties of My Computer>Advance System Settings>Environment variables> then click on the New for adding Environment variable.


Setting Java_Home
 Type Java_Home in the Variable Name and insert your jdk installed path in the variable value like 'C:\Program Files\Java\jdk1.7.0_71\bin;' then edit the Path variable similar to given below screenshot.

 
Editing path variable

 Now to verify the jdk/java installation follow the instructions here.

2-How to download and install the Eclipse IDE?

Go to here to download latest version of the eclipse IDE after successful download extract the zipped file at any location and open the eclipse.exe for accessing the IDE environment,first time you also need to set the workspace.

Selenium WebDriver with java

Now on eclipse click on the File and create new java project.


Create New Java Project



Now open your Selenium IDE Exported script in the notepad (As we have discussed earlier about the Selenium IDE installation,recording scripts and exporting scripts).


Exported script opened in NotePad
Right click on the eclipse project and create a package with name 'com.automation.first'.


Creating New Package
Right click on the package 'com.automation.first' then select New >Class with name "Google Automation".


Created Automation Google class

Now Copy the exported script and paste in the 'Google_Automation' class.


Google_Automation class with exported script
Notice that lot of errors are displaying because no supported library/Jar file has been added in the project, for downloading Selenium WebDriver libraries click here  then Scroll to the Selenium Client and WebDriver language Bindings section.Press on the download link to start downloading w.r.t your language, here I am going to download Selenium Webdriver for java because i am binding Selenium with java if you wish to bind with the C# then download Selenium WebDriver for C#.


Downloading Selenium WebDriver Libraries

After successful downloading of the Selenium WebDriver libraries, extract the selenium-java zip file at any location,then go to your eclipse IDE Right click on the project >Build Path>Configure build Path>Add external jars.



Add External Jar Files
Select both of the Selenium WebDriver jar files from folder 'Selenium-java-2.45.0' and also all jar files of the lib folder and press on the OK button.



Selenium WebDriver lib added


after adding selenium web-driver jar files no more errors are displaying and we are ready to execute script.Right click on the 'Google_Automation.java' class then  Run as Junit Test during script execution make notice of  Firefox Driver initialization then opening Google site after that closing the site.

Running Selenium WebDriver Script



Driver initialization

Note:This simple tutorial covers how to utilize selenium IDE Exported script in Selenium WebDriver.How to run the Selenium WebDriver scripts,How to set the Selenium WebDriver Environment, In the future posts we will discuss Selenium WebDriver with deeper concepts.








No comments:

Post a Comment