Friday 28 June 2013

Selenium RC example program


Selenium RC(Remote Control) was familiar automation framework, which is released to overcome the disadvantages of the selenium IDE. Since Selenium RC supports for

  • multiple browsers
  • multiple languages and 
  • multiple platforms

 it became the favorite automation tool of the automatians. Selenium is an open source tool, Obviously this is also one of the major reason to become popular.

Selenium RC supports for the following languages,

  • C#
  • Java
  • Python
  • Perl
  • PHP
  • Ruby
  • Java script


Components of Selenium RC:


  • Selenium RC Server
  • Client library


Selenium RC Server:


Selenium Server(selenium-server-standalone -<version number>.jar) receives Selenium commands from your test program, interprets them, and reports back to your program the results of running those tests.

The RC server bundles Selenium Core and automatically injects it into the browser. This occurs when your test program opens the browser (using a client library API function). Selenium-Core is a JavaScript program, actually a set of JavaScript functions which interprets and executes Selenese commands using the browser’s built-in JavaScript interpreter.

The Server receives the Selenese commands from your test program using simple HTTP GET/POST requests. This means you can use any programming language that can send HTTP requests to automate Selenium tests on the browser.

Client Library:


The client libraries provide the programming support that allows you to run Selenium commands from a program of your own design. There is a different client library for each supported language.

A Selenium client library provides a programming interface (API), i.e., a set of functions, which run Selenium commands from your own program. Within each interface, there is a programming function that supports each Selenese command.

The client library takes a Selenese command and passes it to the Selenium Server for processing a specific action or test against the application under test (AUT). The client library also receives the result of that command and passes it back to your program. Your program can receive the result and store it into a program variable and report it as a success or failure, or possibly take corrective action if it was an unexpected error.




Sample program


import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class TestNaukri {

public static void main(String[] args) throws InterruptedException {

String expected = "G.Elangovan";

Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.naukri.com");
selenium.start();
selenium.open("/");
selenium.windowMaximize();
Thread.sleep(5000);

selenium.type("id=username", "tester@gmail.com");
selenium.type("id=password", "password");
selenium.click("name=Login");

Thread.sleep(5000);
String actual = selenium.getText("id=nameDisplaySpan");

System.out.println("usernmae is: "+actual);

boolean condition = expected.equals(actual);
System.out.println(condition);

selenium.close();
selenium.stop();
}

}

How to start the selenium server:


Before we run this program we have to start to the selenium server as below,

  • Open the command prompt
  • Go to the path of the folder, where you keep selenium server
  • Enter the command 
  •         java -jar selenium-standalone-server<version-number>.jar
  • Hit the enter key
Now selenium server is started.

Now if we run the above sample program, it will run successfully.

5 comments:

  1. Nice article bro..

    Looking for new article.

    ReplyDelete

  2. Best place to learn Appium Android IOS Automation Testing Training in Chennai

    Go for Appium training in chennai for real time mobile automation testing training with real time project support.
    Mr. Vishwa is a best person who can teach and develop people in Appium and Selenium,Coded UI Automation Tools with real time scenarios You can contact 8122241286 for Best APPIUM and selenium Training in Chennai

    ReplyDelete
  3. Appium Training in chennai
    We provides Best Appium Training in Chennai with real time project assistance by our leading Appium mobile App Automation testing architect
    For Free Live Demo @ Call to 8122241286.
    Appium ,Selenium,Mobile Automation Testiing using Android and IOS
    www.thecreatingexperts.com
    Appium training in chennai

    ReplyDelete
  4. Hi,
    I am getting error "Could not start Selenium session "
    Waiting for your suggestion.
    Thanks

    ReplyDelete