Start with Java Selenium RC - Procedure to create first test script for the beginners

Prerequisites:
  1. Download Selenium2 jar file from http://seleniumhq.org/download/.
  2. Download TestNG jar file from http://testng.org/doc/download.html
  3. Download and Install JDK and setup java path 
  4. Download Eclipse IDE from http://www.eclipse.org/downloads/
  5. Install TestNG plugin in downloaded eclipse
  6. Firefox should be install with selenium IDE plugin.
Step by step to creating first script:

1. Project creation: 
Open eclipse IDE  and chose work space.


Click on file menu> new > java project.
Enter project name and click Finish button
Created project displayed into eclipse explorer window.
Right click on src folder of created project and click new > packages
Enter package name as I enter “com.test” and click finish button.
Created package reflect under src folder.

2. Add jar files:

Right click on project click on “build path” and then click on “Configure Build Path” screen should see as below.

Click add “Add External Jars” button, navigate and select “selenium-server-standalone-2.**.0.jar”  and “testng-*.*.jar” files 
Click on Ok button. Jar files listed in explorer window as below.

3. Create script:
Record test scripts using seleniumIDE convert them into Java/ Junit 4/  Remote Control

package com.test;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class SeleniumRCTest {
        private Selenium selenium;

        @Before
        public void setUp() throws Exception {
               selenium = new DefaultSelenium("localhost", 4444, "*chrome", "https://www.google.co.in/");
               selenium.start();
        }

        @Test
        public void testGoogle() throws Exception {
               selenium.open("/");
               selenium.type("id=gbqfq", "Testing");
               selenium.click("id=gbqfb");
        }

        @After
        public void tearDown() throws Exception {
               selenium.stop();
        }
}
4. Run selenium Server
Open command prompt go to “selenium-server-standalone-2.**.0.jar” and run below command
        Java –jar selenium-server-standalone-2.**.0.jar      
Below screen should be appear.


5. Execution and Report: Right click on class select “Run As” and click on “Junit Test”.  Test execution should be start.
After execution result generated in “test-output” folder. Click on “index.html” to see report. 


2 comments:

  1. Your information about Selenium scripts is really interesting. Also I want to know the latest new techniques which are implemented in selenium. Can you please update it in your website?
    Selenium training Chennai

    ReplyDelete
  2. This information you provided in the blog that was really unique I love it!!, Thanks for sharing such a great blog..Keep posting..

    JAVA J2EE Training in Chennai

    ReplyDelete

Leave your comments, queries, suggestion I will try to provide solution