Monday, December 8, 2008

Selenium RC, The basic

Selenium RC, The basic
Selenium RC consists of three main components, see below,

The HTTP proxy server, this component, once Selenium RC server started, it will ready to receive command from client.
The command interpreter, interpret command (HTTP GET/POST requests) and send to Selenium CORE.
The Selenium CORE
Installation
Following are topic about installation and prerequisite about Selenium RC.

Java Runtime (JRE)
You need to have Java Runtime because Selenium RC Server s written in Java. You can check you Java by open command line and type,

java -version

If you have Java installed on your machine, you will see,

java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05) Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

If not, you have to download and install java. See details

Install Web Browser, If you don't have them
Before you go any further, please make sure that you have web browser you are going to use to test, for example, you will need to have Internet explorer and Mozilla Firefox installed on your machine in order to be able to test against them.

Getting Selenium up
Once have Java, web browser, next you are going to get Selenium RC. Step by step to get Selenium RC up and running,

Download Selenium RC you can save it wherever you want, for me, I saved it at D:Selenium
Extraction the zip, you will see following;
selenium-dotnet-client-driver-1.0-beta-1, .Net client driver

selenium-java-client-driver-1.0-beta-1, Java client driver

selenium-perl-client-driver-1.0-beta-1, Perl client driver

selenium-php-client-driver-1.0-beta-1, PHP client driver

selenium-python-client-driver-1.0-beta-1, Pytohn client driver

selenium-ruby-client-driver-1.0-beta-1, Ruby client driver

selenium-server-1.0-beta-1, Selenium RC server

Open command prompt and change directory to the path of Selenium RC server, For example if you save zip file uder D:\Selenuim, you path would be;
D:seleiumselenium-remote-control-1.0-beta-1selenium-server-1.0-beta-1

Under this path, you will see selenium-server.jar, this is our Selenium RC server.

Under the path, type java -jar selenium-server.jar. This will start Selenium RC server. You should see following at command line,
02:56:50.729 INFO - Java: Sun Microsystems Inc. 1.5.0_06-b05

02:56:50.729 INFO - OS: Windows XP 5.1 x86

02:56:50.729 INFO - v1.0-beta-1 [2201], with Core v1.0-beta-1 [1994]

02:56:50.807 INFO - Version Jetty/5.1.x

02:56:50.807 INFO - Started HttpContext[/,/]

02:56:50.807 INFO - Started HttpContext[/selenium-server,/selenium-server]


02:56:50.807 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]

02:56:50.823 INFO - Started SocketListener on 0.0.0.0:4444

02:56:50.823 INFO - Started org.mortbay.jetty.Server@2e7263

At this point, you have Selenium RC server up and running

Selenium RC, Interactive mode
If you want to write client driver at this point, you can start Selenium RC server with interactive mode. After server started, you can type command line by line and see how it work. To start server in interactive mode, type,

java -jar selenium-server.jar -interactive

Output should be,

03:08:03.495 INFO - Java: Sun Microsystems Inc. 1.5.0_06-b05

03:08:03.495 INFO - OS: Windows XP 5.1 x86

03:08:03.495 INFO - v1.0-beta-1 [2201], with Core v1.0-beta-1 [1994]

03:08:03.589 INFO - Version Jetty/5.1.x

03:08:03.589 INFO - Started HttpContext[/,/]

03:08:03.589 INFO - Started HttpContext[/selenium-server,/selenium-server]

03:08:03.589 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]

03:08:03.589 INFO - Started SocketListener on 0.0.0.0:4444

03:08:03.589 INFO - Started org.mortbay.jetty.Server@2e7263

Entering interactive mode... type Selenium commands here (e.g: cmd=open&1=http://www.yahoo.com)

You can try following command and observer the result,

cmd=getNewBrowserSession&1=*iexplore&2=http://www.google.com

You will see internet explorer pop up with Selenium RC page itself and lower frame. The lower frame will show the page under test. At the command line, you will see something like,

cmd=getNewBrowserSession&1=*iexplore&2=http://www.google.com

03:16:29.370 INFO - ---> Requesting

http://localhost:4444/selenium-server/driver?cmd=getNewBrowserSession&1=*iexplore&2= http://www.google.com


03:16:29.370 INFO - Command request: getNewBrowserSession[*iexplore, http://www.google.com] on session null

03:16:29.370 INFO - creating new remote session

03:16:29.370 INFO - Allocated session 3ef951a2ba6a481888cd3f8012b65194 for http://www.google.com, launching...

03:16:29.370 INFO - Modifying registry settings...

03:16:29.964 INFO - Launching Internet Explorer...

03:16:31.792 INFO - Got result: OK,3ef951a2ba6a481888cd3f8012b65194 on session 3ef951a2ba6a481888cd3f8012b65194


The last line tell you that command successfully execute with current test session (current session? yes, Selenium RC support multiple test session). Keep this in your current command line screen, you will need it to execute next command.

Let try to execute series of following command;

cmd=open&1=http://www.google.com/webhp&sessionId=3ef951a2ba6a481888cd3f8012b65194

cmd=type&1=q&2=helloworld&sessionId=3ef951a2ba6a481888cd3f8012b65194

cmd=click&1=btnG&sessionId=3ef951a2ba6a481888cd3f8012b65194

cmd=getTitle&sessionId=3ef951a2ba6a481888cd3f8012b65194

cmd=testComplete&sessionId=3ef951a2ba6a481888cd3f8012b65194

As you can see, with this command, you can automate internet explorer easily. But in real world, you will face complex testing. For example, will will need to verify correctness of processing of AUT. This will lead you to write programming language instead of typing command line-by-line.

1 comment:

pritish said...

thank you for the info on selenium interactive!