Mindmajix

How to Setup and Configure Selenium Webdriver with Eclipse

There are essentially two tasks:

  • Generate your script into a programming language from Selenium-IDE, optionally modifying the result.
  • Write a very simple main program that executes the generated code. Optionally, you can adopt a test engine platform like JUnit or TestNG for Java, or NUnit for .NET, if you are using one of those languages. Here, we show language-specific examples. The language-specific APIs tend to differ from one to another, so you’ll find a separate explanation for each.
  • Java
  • C#
  • Python
  • Ruby
  • Perl, PHP

JAVA

For Java, we need to use either JUnit or TestNG as the test engine. Some development environments like Eclipse have direct support for these via plug-ins. This makes it even easier. You will probably want to rename the test class from “NewTest” to something of your own choosing.

Also, you will need to change the browser-open parameters in the statement

selenium = new DefaultSelenium(“localhost”, 4444, “*iehta”, “http://www.google.com/”);

The Selenium-IDE generated code will look like this. This example has comments added manually for additional clarity.

package com.example.tests;
// We specify the package of our tests
import com.thoughtworks.selenium.*;
// This is the driver’s import. You’ll use this for instantiating a
// browser and making it do what you need.
import java.util.regex.Pattern;
// Selenium-IDE add the Pattern module because it’s sometimes used for
// regex validations. You can remove the module if it’s not used in your
// script.
public class NewTest extends SeleneseTestCase {
// We create our Selenium test case
public void setUp() throws Exception {
setUp( “http://www.google.com/” , “*firefox” );
// We instantiate and start the browser
}

public void testNew() throws Exception {
selenium.open( “/” );
selenium.type( “q” , “selenium rc” );
selenium.click( “btnG” );
selenium.waitForPageToLoad( “30000” );
assertTrue(selenium.isTextPresent( “Results * for selenium rc” ));
// These are the real test steps
}
}

Parameters

The parameters required when creating the browser instance are:

host Specifies the IP address of the computer where the server is located. Usually, this is the same machine as where the client is running, so in this case localhost is passed.

port Specifies the TCP/IP socket where the server is listening waiting for the client to establish a connection.

browser The browser in which you want to run the tests. This is a required parameter.

url The base url of the application under test. This is required by all the client libs and is integral information for starting up the browser-proxy-AUT communication.

Selenium Set up in Eclipse

This section will explain how to set up selenium in Eclipse.

Required Software

Achala Solutions will deliver the work in four phases as listed below. Each of the phases and activities are described in the following picture

  • Eclipse (Version 3.5.2) –
    http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.5.2-201002111343/eclipse-SDK-3.5.2-win32.zip
  • Jdk 1.5.0_11 or above
    http://java.sun.com/javase/downloads/index_jdk5.jsp
  • 4 Jar files (junit-4.5, jxl, selenium-java-client-driver, seleniumserver)

Procedure

1. Create an empty folder (Selenium_Scripts1) in F drive-no need to create in F drive you can create folder in any folder.
2. Create an empty folder lib in Selenium_Scripts1 folder.
3. Install jdk1.5.0_11, copy the jdk1.5.0_11 folder which is in c folder
(Generally it will be installed in “C” Drive– C:\Program Files\Java) and paste it in Selenium_Scripts1 folder.
4. Paste the 4 Jar files (junit-4.5, jxl, selenium-java-client-driver, and seleniumserver) in lib folder.
5. Open eclipse (F: \eclipse\eslipse.exe)

You will get the below window, select the path (F:\ Selenium_Scripts1) which you created a folder earlier in F drive.

Screenshot_1169

After clicking OK, you will get below screen select “work bench”.

Screenshot_1170

You will get the below screen—eclipse environment.

Screenshot_1171

Create Java Project

1. File—New—Java Project
2. Give Project name (Selenium_scripts)
3. Click Configure JREs in that screen. You will get a new window.
4. Click Add—Standard VM􀃆next.

JRE Home—we need to specify path.

Click directory—browse the path where you created the folder
(F:\Selenium_scripts1\jdk1.5.0_11\jre)

All jar files will be added.. click Finish and click OK

Click finish on the open window (New Java Project window)

You can see the new project Selenium_scripts in eclipse window.

New Java Project with all jar files.

Screenshot_1172

Now Right click on JRE System Library[Java SE-1.6]

Select Build Path- configure Build Path.

A new window will be opened. Select Libraries tab and click Add External Jars Button.

Select path F:\demo\lib and select all 4 Jar files click OK.

You can see all Jar files under Libraries Tab.

Click Ok.

You can see the Referenced Libraries…

Screenshot_1173

Everything is done.

Now need to create selenium server…

Go to RUN     External Tools     External tools configuration…

There click Program—u will get new configuration window.

Give name selenium server (any name you can give).

Location —click on Browse file systems. F:\Selenium_Scripts1\jdk1.5.0_11\bin\java.exe

Working Directory— Browse file system — F:\ Selenium_Scripts1\lib.

Arguments –     -jar selenium-server.jar

Click Apply and Run….

Your selenium server will be up and running….

Screenshot_1174

Now, you can write your scripts and Enjoy Selenium Automation….

Create Class

File – New –class

Give Name First and click the check box public static void main (String [] args) click Finish


0 Responses on How to Setup and Configure Selenium Webdriver with Eclipse"

Leave a Message

Your email address will not be published. Required fields are marked *

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.
Course Adviser

Fill your details, course adviser will reach you.