The previous post, I wrote about basic web user interface test and how Selenium components answer you question. While Selenium IDE easy to use, it have a lot of limitation. For example, you cannot test web page content against database, file system. This true for Selenium Core as well. Since these two techniques use JavaScript, and its limitation because security problem. Dealing with file system or interact to database seem far away from those of them.
To be able to have powerful, flexible testing solution. It is impossible to not write program by yourself. Some test tools, allow you to execute test command interactively, for my point, that is one kind of writing program.
Especially, when you need to test web content against data source (database, file system, external service). It usually impossible (some tool offer ability to test against database, Fitnesse has database fixture to allow you to test database content ) to do these task by command line interface. But if you write your own program, it seem like you can you whatever you want.
If you never write program before, I recommend you to play with some scripting language, for example Python or Ruby. Because of its ease of usage.
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 nullThe 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.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
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.
In the next post, I will show you how to use Python as a client driver.
Have a nice day...
Comments
# Hades Pluto Sep 26th, 2009
Hi guys:
I have a question regarding to pop-up window handling in Selenium RC for IE 7 automation testing.
I am running a test case with JUnit in IE 7 where there will be a pop-up window. However, the pop-up window does not have any windowsID assigned; there is neither title nor name for it.
I have tried several methods but I am still getting the same error message:” Error: 'pathname' is null or not an object” or “Permission Denied” when it comes to pop-up window in RC.
The partial code is shown below:
selenium.click("xpath=//td[@id='addWidgetBtncenter']"); selenium.waitForPageToLoad("30000"); //selenium.getAllWindowIds(() [1]); //selenium.selectWindow(() [1]); selenium.selectPopUp("");
//system.threading.thread.sleep(3000); for (int second = 0;; second++) { if (second >= 60) fail("timeout"); try { if (selenium.isElementPresent("xpath=//input[@id='widgetName']")) break; } catch (Exception e) {} Thread.sleep(1000); } //System.Threading.Thread.Sleep(3000);
I have used these commands with target of the button that triggers the pop-up window. (In this case, addWidgetBtncenter is the button to click on for add widget)
I have placed these function commands after the action of "click the add widget button" but before "waitforPopUp", please tell me if I am use these commands correctly in terms of their syntax or place order. (I have tried to place it after waitforpopup but before "selectopup", it still doesn't give me any information in the log) Also, I have used "windowFocus" command then "selectFrame" or "selectpopup", but none of them worked in IE I am still new to Selenium/JUnit, can anyone please help me with the correct syntax for these functions: “"storeAllWindowIds", "storeAllWindowNames" and "storeAllWindowTitles".” As well as the “System.Threading.Thread.Sleep(3000);”
I have been stuck in this for a while and I really need help with it…
Any commands and suggestions are greatly appreciated!!!
Best,
Hades
# web development company Oct 16th, 2009
Interesting,
The help with Selenium is great, and the download link, this is a great article, keep up the hard work
Thanks for writing about it
# http://www.lejeupoker.com/ Oct 24th, 2009
great work ..keep on doing this kind of good work in future.