Selenium – Setting up Selenium & Eclipse

Now its time to learn how to configure Selenium RC client driver with Eclipse IDE and how to run Selenium RC server instance.  We will try to understand this step by step.

Note: Download JDK ( from the Oracle / Sun website and install prior to installing Eclipse)

Download Eclipse

  1. Go to URL – http://www.eclipse.org/downloads/
  2. Select Eclipse IDE for Java Developers (Click on Windows 32 bit platform)
  3. Click on OK button and save to a local drive (i.e. C: or D:, etc)
  4. Unzip the downloaded zip file and rename that to Eclipse
  5. Create one more folder “Eclipse-Workspace” (i.e. C:Eclipse-Workspace)in the same drive where Eclipse is unzipped and renamed.
  6. Create Eclipse desktop shortcut (go to C:Eclipse folder –> right click Eclipse.exe and then click on “desktop create shortcut”) as demonstrated in the below pictures.

Eclipse - download

create Eclipse shortcut

  1. Now we need to create a workspace folder –> C:Eclipse-WorkspaceSeleniumTests
  2. Double click on “Eclipse shortcut on Desktop”
  3. This opens the Eclipse
  4. Close Eclipse welcome screen
  5. Click File menu –> Switch Worspace –> other
  6. Now Select the C:Eclipse-WorkspaceSeleniumTests folder (These steps are demonstrated in the following figure)

Eclipse-settingupWorkspace

We have finished setting up the eclipse.  Now, we need to download Selenium RC server / client driver and configure that to Eclipse

  1. Download Selenium server:  http://seleniumhq.org/download/ 
  2. Download Selenium Client driver for Java (from Selenium Client Drivers section)
  3. Create “Selenium” folder in C: drive and copy the Selenium-server.jar as well as unzip the Selenium Client driver (C:Selenium)

Downloading and unzipping the files into a folder is done.  We need to configure the appropriate Selenium Client driver Jar file to the Eclipse.

  1. Go to Eclipse –> Click  File –> New –> Project (from various options need to select just “project”)
  2. In Select Wizard –> Click Java –> “Java Project” (demonstrated in the below figure)
  3. SelectJavaProject
  4. Give the project name (e.g. SugarCRMTests)
  5. Click Finish – Click Yes
  6. Now we are done with creation of project and need to configure the Selenium Client driver to this Project
  7. Right Click “SugarCRMTests” project
  8. settingExternalLibrary 
  9. Click “Java Build Path”
  10. Click Libraries tab
  11. Click “Add External JARs” button
  12. Select “Selenium Client Drivers” unzipped in C:Selenium folder (Selenium Server JAR file should not be added)
  13. Click OK
  14. Referenced libraries –> contains both the Selenium Client driver jar files as shown in the below picture.
  15. ReferencedLibraries

So far we have learnt the following:

  1. Download latest JDK and install
  2. Download Selenium Server as well as Client drivers and unzip into a folder
  3. Download Eclipse and configure

In the next post we will learn how to execute selenium tests using Eclipse

Comments 23

  • awesome…can’t wait for the follow up to show how to run a test in eclipse. can you please do an example with Selenum IDE -> Format -> JUnit4 to Eclipse. I am having the hardest time trying to make it work.

    thanks,
    William

  • Hi ..Thanks for the information…can you please tell me how to create own framework using selenium ….i mean what are the thing that i need to do so …..

    • I actually wrote a post on “Designing a Test Automation Framework with Selenium”. All the features that a framework needs are explained across different posts in this blog. But only thing you need to do is to go through the above post (“Designing a Test Automation Framework with Selenium”) and then use different posts to gather information on designing features. Thats it!!!

  • Good post.. I was able to set up Eclipse and Selenium easily.. Thanks..

  • Hi ,

    I get this error after setting up and running it as a Java application.

    Exception in thread “main” java.lang.NoClassDefFoundError: com/google/common/base/Charsets
    at com.thoughtworks.selenium.HttpCommandProcessor.getOutputStreamWriter(HttpCommandProcessor.java:149)
    at com.thoughtworks.selenium.HttpCommandProcessor.getCommandResponseAsString(HttpCommandProcessor.java:176)
    at com.thoughtworks.selenium.HttpCommandProcessor.executeCommandOnServlet(HttpCommandProcessor.java:118)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:101)
    at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:275)
    at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:237)
    at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:98)
    at SugarCRMTests.SugarCRM.main(SugarCRM.java:12)
    Caused by: java.lang.ClassNotFoundException: com.google.common.base.Charsets
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    … 8 more
    Can you please help me with this?
    Thanks,
    Mohan

  • Hi, I have setup Eclipse with Selenium Server but I am getting error when I run as Junit Test

    selenium-server-standalone-2.6.0
    selenium-java-2.6.0
    Junit 4

    I am posting code with error please help.

    Many thanks in advance.

    Ash

    package com.selenium.test;

    import com.thoughtworks.selenium.*;
    import java.util.regex.Pattern;

    public class SeleniumTest extends SeleneseTestCase {
    public void setUp() throws Exception {
    setUp(“http://www.google.com/”, “*firefox”);
    }
    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”));
    }
    }

    java.lang.NoClassDefFoundError: com/google/common/base/Charsets
    at com.thoughtworks.selenium.HttpCommandProcessor.getOutputStreamWriter(HttpCommandProcessor.java:149)
    at com.thoughtworks.selenium.HttpCommandProcessor.getCommandResponseAsString(HttpCommandProcessor.java:176)
    at com.thoughtworks.selenium.HttpCommandProcessor.executeCommandOnServlet(HttpCommandProcessor.java:118)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:101)
    at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:275)
    at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:237)
    at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:98)
    at com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:134)
    at com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:103)
    at com.thoughtworks.selenium.SeleneseTestCase.setUp(SeleneseTestCase.java:91)
    at com.selenium.test.SeleniumTest.setUp(SeleniumTest.java:8)
    at junit.framework.TestCase.runBare(TestCase.java:132)
    at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:246)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:232)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    Caused by: java.lang.ClassNotFoundException: com.google.common.base.Charsets
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    … 26 more

    • Hi,

      In a JUnit test, there should be SetUp and TearDown methods and also use @Test, @BeforeClass, and @AfterClass annotations

      Refer the post related to JUnit
      thanks,
      Seetaram

  • Hello Sitaram,

    Good Work.
    Please do let me correct if i am wrong, First
    1. I installed Selenium IDE
    2. Should i need to installed Selenium RC server or Need to to install only client drivers?

    Please let me know your input?

  • Hello Seetaram,

    It would be helpful if you post a Junit test case for opening Google and search text.
    I found your Junit post it is brilliant but i am newbee so want to see simple Google test case

    Mahesh

  • Hi Seetaram,

    I am a newbie for selenium. and your post is excellent.
    If possible for you, could you please post a test case for google.

    Thanks
    Garvita

  • HI Seetaram,

    I am new to selenium. I just copied the code available in your portal and try to run JUnit Test gives the below error. Please advise how to resolve this issue.

    java.lang.NoClassDefFoundError: com/google/common/base/Charsets
    at com.thoughtworks.selenium.HttpCommandProcessor.getOutputStreamWriter(HttpCommandProcessor.java:149)
    at com.thoughtworks.selenium.HttpCommandProcessor.getCommandResponseAsString(HttpCommandProcessor.java:176)
    at com.thoughtworks.selenium.HttpCommandProcessor.executeCommandOnServlet(HttpCommandProcessor.java:118)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:101)
    at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:275)
    at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:237)
    at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:98)
    at com.selftechy.assertions.SeleniumAssertions.setUp(SeleniumAssertions.java:16)
    at junit.framework.TestCase.runBare(TestCase.java:132)
    at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:230)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:232)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    Caused by: java.lang.ClassNotFoundException: com.google.common.base.Charsets
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    … 23 more

  • Hi,can you please explain how to configure and run the selenium rc in eclipse server.

  • Hi,
    I have used above instructions to configure selenium but i got one warning.

    Description
    Build path specifies execution environment JavaSE-1.6. There are no JREs installed in the workspace that are strictly compatible with this environment.
    build path JRE System Library Problem

    please let me know how i will able to resolve it.
    Please replay!!

  • Hi
    I have created script using IDE add-on on fire fox when I am loading it onto Eclipse it is not considering selenium as command. I have added Library files in ‘Configure Build Path Also’

    Kindly Find Code:
    package registration;

    import com.thoughtworks.selenium.*;

    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import java.util.regex.Pattern;

    public class regist {
    @Before
    public void setUp() throws Exception {
    selenium = new DefaultSelenium(“localhost”, 4444, “*chrome”, “http://s-www.mynelson.com/mynelson”);
    selenium.start();
    }

    @Test
    public void testRegis() throws Exception {
    selenium.open(“http://s-www.mynelson.com/mynelson/webapp/staticcontent/html/PublicLogin.html”);
    assertEquals(“myNelson – Your digital resources. Anytime, anywhere.”, selenium.getTitle());
    selenium.click(“id=lnkClickHereToRegister”);
    selenium.waitForPageToLoad(“30000”);
    assertEquals(“Registration”, selenium.getTitle());
    verifyEquals(“”, selenium.getValue(“id=btnContinue”));
    verifyEquals(“”, selenium.getValue(“id=btnCancelStepFirst”));
    verifyEquals(“Skip this step”, selenium.getText(“css=u”));
    verifyTrue(selenium.isElementPresent(“css=u”));
    verifyEquals(“Step 1:\nAccess Code”, selenium.getText(“id=step1Identifier”));
    selenium.click(“id=btnContinue”);
    verifyTrue(selenium.isElementPresent(“css=label.error”));
    selenium.doubleClick(“id=txtAccessCode”);
    selenium.type(“id=txtAccessCode”, “1234”);
    selenium.click(“id=btnContinue”);
    verifyTrue(selenium.isElementPresent(“id=lblErrorMessage”));
    selenium.click(“css=u”);
    verifyTrue(selenium.isElementPresent(“id=btnBackStepSecond”));
    verifyTrue(selenium.isElementPresent(“id=lnkStudent”));
    verifyTrue(selenium.isElementPresent(“id=lnkTeacher”));
    verifyTrue(selenium.isElementPresent(“id

    Please suggest me what to do>
    Thanks in advance

  • Excellent.
    Thank u sooo much.

  • Thanks a lot! It was very helpful for me who does not come from a development background. After a big struggle, I could install Eclipse and Selenium and configure them correctly. Thanks a lot! 🙂 Keep up the good work..

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.