Saturday, 10 August 2013

How To Configure Selenium Webdriver With Java(Eclipse)




Configure Selenium Webdriver  With Java(Eclipse)

Step1:Download Java IDE  from  http://www.eclipse.org/downloads/


Step 2: Download JDK according to System Type (32-bit or 64-bit) from http://download.cnet.com/Java-Development-Kit-32-bit/3000-2218_4-12091.html


Step 3: Download Selenium Webdriver for JAVA from https://code.google.com/p/selenium/downloads/list


Step 4 : Install JDK

Step 5 : Set Environment Variables (Windows 7 )

1.Right Click On Computer
2.Click on Properties 
3.Click On ‘Advance Settings’
4.On  ‘System Properties ‘  Click On tab ‘Advance’
5.Click on ‘Environment Variables ‘



 6.Copy  following path where JDK  is installed .
C:\Program Files\Java\jdk1.6.0\bin



7.On Environment Variable Window  Click ‘New’ Under System Variable  and Set  Path: C:\Program Files\Java\jdk1.6.0\bin
-If Path Variable already Exist Then Edit it .


8.Set  CLASSPATH :
Copy  following Path Where JDK is installed :



On Environment Variable Window Click ‘New’ under  User Variables and Set  CLASSPATH :


Enviornment is set up now  start JAVA IDE

Step 6 : Extract Downloaded JAVA IDE  and Click on ‘Eclipse’
Set Workspace and Check Option “Use this as Default browser”



Step 7: Open File -> New-> Other

Click On ‘Next’
Click on ‘Finish’

Step 8 : Right Click on ‘Src’ and  Select New-> Package 


Give Name as Com.Project1 and Click on ‘Finish’

Step 10: Configure Build Path:
-Right Click on Src, Select Build Path->Configure Build Path

-Click on Tab ‘Library’ and Click on ‘Add External Jars’
Select  Selenium  Webdriver  Jar files .





Step 11 : Now Start Coding in Main() J
Paste below  code in Class
package com.project1;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.*;

public class Class1 {
        public static void main(String[] args) {
//Initiate Driver   
 WebDriver driver = new FirefoxDriver();
driver.get("http://bing.com");
//Get Element By Id
driver.findElement(By.id("sb_form_q")).sendKeys("Test Automation");
driver.findElement(By.id("sb_form_go")).click();
System.out.println("Test Completed");

}
}

Step 12 : Run Test

1.Right Click on Class1
2.Select Run As ->Run Java Application


To Run  Selenium script in IE or Chrome Following changes may Require

       1. Download Driver from http://docs.seleniumhq.org/download/ according to
 System Type (32 –bit or 64-bit)


2. Add  import org.openqa.selenium.ie.* and import org.openqa.selenium.chrome.*;
For iE and Chrome respectively
3. Add following statements to give path of respective drivers .
For ie :
System.setProperty("webdriver.ie.driver", "C:\\Users\\IE Driver\\IEDriverServer_Win32_2.33.0\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();

For Chrome :
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Chrome Driver\\chromedriver_win32_2.1\\chromedriver.exe");
WebDriver driver = new ChromeDriver();









6 comments:

  1. Great Work!!

    Step by Step info..Thanks alot..you got me started :)

    Thanks
    Simit

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Thanks !! It is really a nice one .. easy step by step information !!

    ReplyDelete
  4. great blog.......Is there any tool ,which will give xpath ?My app only supports IE.

    ReplyDelete
    Replies
    1. Hi Anjali,

      I know It is a big problem with applications which only works with IE ,In My knowledge there is not any tool which can help you with IE and Xpath,But using developer tool in IE ,you can develop practice of creating xpath using class names and other properties,Also you can use CSS and Id rather than Xpath.

      Delete
  5. https://seleniumbycharan.wordpress.com/2015/06/09/how-to-customize-xpath-in-ie-browser/

    ReplyDelete