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
Interested in mastering Selenium? Enroll now for FREE demo on Selenium Training.

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”, “https://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( “https://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
}
}

Checkout Selenium Interview Questions

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.

Checkout Selenium Tutorial

Selenium Set up in Eclipse

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

MindMajix Youtube Channel

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) –

https://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

https://java.sun.com/javase/downloads/index_jdk5.jsp

  • 4 Jar files (junit-4.5, jxl, selenium-java-client-driver, seleniumserver)

Related Page: How To Create Test Suites In Selenium

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 FilesJava) 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: eclipseeslipse.exe)
You will get the below window, select the path (F: Selenium_Scripts1) which you created a folder earlier in F drive.

Workspace Launcher

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

You will get the below screen—eclipse environment.

Eclipse environment

Explore Selenium Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!

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_scripts1jdk1.5.0_11jre)
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.

Java-Eclipse SDK

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:demolib 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…

Text view & Edit view

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_Scripts1jdk1.5.0_11binjava.exe
Working Directory— Browse file system — F: Selenium_Scripts1lib.
Arguments –     -jar selenium-server.jar
Click Apply and Run….

Related Page: Automation Selenium RC Using TestNG - Selenium

Your selenium server will be up and running….

Selenium server will be up and running

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.

 

 

Course Schedule
NameDates
Selenium Training Nov 02 to Nov 17View Details
Selenium Training Nov 05 to Nov 20View Details
Selenium Training Nov 09 to Nov 24View Details
Selenium Training Nov 12 to Nov 27View Details
Last updated: 07 Oct 2024
About Author

 

Madhuri is a Senior Content Creator at MindMajix. She has written about a range of different topics on various technologies, which include, Splunk, Tensorflow, Selenium, and CEH. She spends most of her time researching on technology, and startups. Connect with her via LinkedIn and Twitter .

read less
  1. Share:
Selenium Articles