Wednesday

Configure Selenium 2 / Webdriver and TestNG for Eclipse


This is the most common thing that newbie's to selenium struggle with, so here are easy steps  to do the same:


Download Selenium WebDriver jar file from http://seleniumhq.org/download

Download Eclipse (any version should do)

Open Eclipse and create a new Java project
  • Right Click on Left hand side in Eclipse under Package Explorer
  • Select NEW JAVA PROJECT
  • Enter the name of Project and Click on Finish button
Create a New Package
  • Right Click on the New Java Project created → New→ Package
  • Type In a New Package Name and Click on Finish button
Creating a New Java Class file.
  • Right Click on the Newly created Package → New → Class
  • Mark the check box for “public static void main (String args[])”
  • Type In a Class Name and Click on Finish button
Add the Selenium Library files to our project

  • Open Eclipse and Configure Build Path.
Right Click on the package → Build Path → Configure Build Path
  • Click on Libraries tab → Add External Jar’s
  • Add all the jars from the Selenium folder downloaded earlier
  • Expand the Referenced Libraries in the Project Explorer to verify if the jar files are added.
Now initialize the Web Driver object as WebDriver driver=new FirefoxDriver()
  • Mouse over the WebDriver line you will see an Auto complete Option, you will find Import WebDriver.
  • Click on Import WebDriver to see import org.openqa.selenium.firefox.FirefoxDriver;
Also Configure TestNG in Eclipse
  • In Eclipse go to Help → Install New Software
  • Enter http://beust.com/eclipse in the required
  • Check TestNg and then click on Next to follow the Instructions and finally click on Finish
Check if TestNg has been configured in Eclipse
  • Go to Window → Show View → Other
  • Now Select Java and you should see TestNG under that folder.
You are all set to start scripting using Selenium webDriver and TestNG.

Tip: Go to javadocs and copy the link address.

Add this in eclipse by going to configure libraries, select the main selenium jar file, expand and select javadoc, edit the location paste the link and remove index.html

Now everytime you mouseover objects you will have the documentation for the same.




2 comments: