Wednesday, 3 July 2013

WebDriver Tutorial Part 3 :Writing first script using Webdriver


If you have missed the previous post then you can have a look at here .

Now we are ready to start our first script in Webdriver using Eclipse .Open your Eclipse and follow the below steps

1.Create new Java Project
2.Add the Webdriver Jar files to the created Project
3.Create a new Package under Java Project
4.Create a Java class file under the Package
5.Write the code in the Java class file and run it.

1. Create a new Java project

Goto File >> New >>Java Project
We will get a popup which will prompt us to provide the project name.
Give the project name say "ExploreWebDriver" then click on Finish button.

Vamshi Kurra - New java project creation popup in Eclipse

2.Add the Webdriver Jar files to the created Project

Right click on created project then goto
Build Path>>Configure Build Path >>Select Libraries tab>>Add External jars
Which will open a folder search prompt , goto the locations where you have downloaded WebDriver jar files and add them .Then click on "Ok" button
You need to add below jar files.If you don't have these files downloaded on your computer then you can download them from the below pages :
http://seleniumhq.org/download/
http://code.google.com/p/selenium/downloads/list
You can also download all jars from my shared location
https://docs.google.com/folder/d/0B00rtzEfza2uZnRBZnNVWHFVNjA/edit
  • a.selenium-java-2.32.0-srcs.jar
  • b.selenium-java-2.32.0.jar
  • c.selenium-server-standalone-2.32.0.jar

Vamshi Kurra- Adding External jar files in Eclipse

3.Create a new Package under Java Project

 Goto creatd project  i.e. "ExploreWebDriver" and expand it.Now we will see a separate folder named "src". Right Click on it and then Goto
New>>Package>>Give the name of package in the "package creation" popup. Say "learning" is the name of the Package.Now click on finish button.

Vamshi Kurra - New Java Package popup

4.Create a Java class file under the Package

Right click on the created package i.e "Learing" and then goto
New>>Class>>we will get "New Java Class" popup. Enter the name of the class say "GoogleSearch" and click on Finish.

Vamshi Kurra- Adding new Java Class in Eclipse

5.Write the code in the Java class file and run it.

Copy the below code and paste it in the created Java class file.

  1. package learning;  
  2.   
  3. import org.openqa.selenium.WebDriver;  
  4. import org.openqa.selenium.firefox.FirefoxDriver;  
  5.   
  6. public class GoogleSearch {  
  7.    
  8.  public static void main(String args[]){  
  9.   WebDriver driver=new FirefoxDriver();  
  10.   System.out.println("Loading Google search page");  
  11.   driver.get("http://google.com");  
  12.   System.out.println("Google search page loaded fine");   
  13.  }  
  14.   
  15. }  

Here is how your Eclipse project hierarchy looks like :

Vamshi Kurra- Eclipse project hierarchy

Now Click run .
Script will run successfully and a new firefox window will be opened with the Google.com .

No comments:

Post a Comment

Angular JS Protractor Installation process - Tutorial Part 1

                     Protractor, formally known as E2E testing framework, is an open source functional automation framework designed spe...