Wednesday, 26 March 2014

Configure Selenium WebDriver, Java and Eclipse

Java:

Download and Install latest Java SE Development Kit 7 (JDK) from Oracle



Setup environment variables for Java:

Windows 7:
  1. Select Computer from the Start menu > Properties
  2.  Click Advanced system settings > Advanced tab
  3. Click on Environment Variables, under System Variables, find PATH, and click on it.
  4.  In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
  5. Click Ok.


For other platforms, please refer http://www.java.com/en/download/help/path.xml

Eclipse

  • Download Eclipse (Eclipse IDE for Java Developers) from http://www.eclipse.org/downloads/
    Note: Make sure to choose correct version as per your OS (Windows 32 Bit and 64 Bit).


  • Unzip the ‘eclipse’ folder from the zip to some directory.

Download Selenium Client & WebDriver Language Bindings

Download latest WebDriver bindings from official website http://docs.seleniumhq.org/download/
and unzip the selenium-java-2.x.x.zip folder to some directory.



Setup a Project in Eclipse:

Launch eclipse: Launch eclipse and provide workspace location.


Select Workbench:



Create a new project: Click on File menu –> New –> Java Project -> Enter project name as “Selenium_Automation” and click finish.



Configure Build Path:  

Right click on Project Name > Properties > select Java Build Path… > select Libraries tab > click Add External JARs... > add WebDriver JARs (by providing the location of extracted WebDriver language bindings/JARs)
OR
Right click on Project Name > Build Path > click Configure Build path… > select Libraries tab > click Add External JARs... > add WebDriver JARs (by providing the location of extracted WebDriver language bindings/JARs )


 Now your environment is ready to run selenium scripts



TestLink API integration with Selenium (WebDriver) script


Summary: By the end of this article you will be able to integrate WebDriver with TestLink. This integration will update the results in TestLink.This article will cover the following:
  •         TestLink: Download necessary JAR files
  •          TestLink: How to enable Test Automation API’s
  •          TestLink: Generate Personal API access key
  •          WebDriver: Creating and implementing script
  •      Testlink reports before and after executing the script

TestLink:

Pre-requisites: You should have TestLink setup up and running with a PROJECT that should have a TEST PLAN, BUILD/RELEASE and some TEST CASES assigned to it.

Note: We will use Project Name, Test Plan Name, Build /Release Name and Test cases ID later while writing selenium script.

Download JAR files: Download testlink-api-client-2.0.zip from Google Code and add the following jar files in your WebDriver java project class path.
‘testlink-api-client-2.0.jar’, ‘xmlrpc-common-3.1.jar’, ’xmlrpc-client-3.1.jar’, ‘ws-commons-util-1.0.2.jar’

How to enable Test Automation (API keys):
  •          Log In to TestLink using admin user
  •          Navigate to Desktop > under ‘Test Project’ > select ‘Test Project Management’
  •          Open appropriate Project > click on check box “Enable Test Automation (API keys)” > click on ‘Save’ button.

Generate Personal API access key:
  •          Click on link ‘My Settings’ > opens Account Settings
  •          API Interface section: Click on ‘Generate a new key’ button > you will get an access key.


      Creating and Implementing Script: Use the below mentioned code but make sure that you make the necessary changes to the file:

Example: Just change Test case ID's as per your test cases.

TestLinkUtils: replace TestLink Server URL, Access key, Project Name, Test Plan Name, Build Name as per your TestLink setup.

TestLink Report before and after executing the script

Before:

After: