June 29, 2011

How to run Selenium RC with Eclipse




I am a new user to use selenium with eclipse.
Had lots of doubt and lots of stuff to run a single program at last I found the way to run the application.

1- Download Selenium-RC from the Selenium HQ download file option and save this some directory (E:/seleniumrc) where you want.
2- Launch eclipse
3- Create a new java project which you can get by configuring selenium with Eclipse.

I follow the following scenario to configure Rc and with eclipse with the help of link http://seleniumhq.org/docs/appendix_installing_java_driver_client.html#configuring-selenium-rc-eclipse-reference
Steps:
a)   Select File>> New>>Java Project
b)   Enter the “Project Name”.
c)   Select “jdk 1.5.0._05” under JRE. Issue I faced in this step is “jdk” is not configured properly hence it’s not displayed. So I select “Configure path link.
Select “Search” option under installed JREs. And I select the location where the JDK is installed in my system.
I select “JDK” checkbox and select “OK” option and then its make easier for me to configure “JDK” and select “Next” button in “New Java Project” window.
d)   Select “Libraries” tab and select “External Jar” button.
e)   Browse and upload the jar files which are available in “selenium server” downloaded file. [Add external jar files. (from the location where you have already saved downloaded selenium rc)]
f)    Select “Finish” option.

4- Right click on “src” folder and select “new folder” option and enter folder name as core. Core is displayed like a package.
Similarly select “new folder” and add “core” and “testscripts”. Both were folder names.
5- Right click on “src” and add a new “class”
6- Add your saved java file in the new “class” and save the file.(which you have saved after recording in IDE) to this project.
7- Now run this code as Junit test

This is the java code which i have recorded using IDE to test the Login in Word press demo tool.

import com.thoughtworks.selenium.SeleneseTestCase;

public class se extends SeleneseTestCase {
      public void setUp() throws Exception {
            setUp("http://demo.opensourcecms.com/", "*chrome");
      }
      public void testJunit() throws Exception {
            selenium.open("/wordpress/wp-login.php");
            selenium.type("user_login", "admin");
            selenium.type("user_pass", "demo123");
            selenium.click("wp-submit");
            selenium.waitForPageToLoad("30000");
            verifyTrue(selenium.isTextPresent("Howdy, admin"));
            selenium.click("link=Posts");
            selenium.waitForPageToLoad("30000");

                  }
}
Running the same in various browsers:
You can now run this test in different browse by initializing the desired browser info like firefox, iexplorer, chrome..
setUp("http://www.google.co.in/", "*firefox") ;

I hope this will help you to get started with you very first test using selenium RC.





http://knorrium.info/2010/05/19/a-java-approach-to-selenium/ this blog is really more helpful for me to run selenium RC thanks too... 

2 comments:

  1. Helo,

    I just started using selenium with eclipse but it doesn't seem to work in any other browser except Firefox.

    Do you know if there is some plugin that I must install in Chrome, IE, Opera etc?

    ReplyDelete
    Replies
    1. Hey, Whether u tried changing the default browser option to
      Selenium selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.com");
      try with different browser command.
      *firefoxchrome
      => While using Selenium my friend got an distinct issue;
      Chrome root directory is not mentioned properly.

      Check it once...

      Delete