In my previous post, I talked about launching Selenium RC from the command line. I’d mentioned navigating to http://localhost:4444/ after starting the Selenium Server but removed it since it wasn’t directly pertinent to a getting started post. Here’s the removed content:
You can launch selenium-server in “interactive” mode and enter commands directly from the command interface.
C:\selenium-remote-control-1.0.1\selenium-server-1.0.1>java -jar selenium-server.jar -interactive
11:54:06.143 INFO - Java: Sun Microsystems Inc. 1.5.0_13-b05
11:54:06.145 INFO - OS: Windows Vista 6.0 x86
11:54:06.161 INFO - v1.0.1 , with Core v@VERSION@ [@REVISION@]
11:54:06.300 INFO - Version Jetty/5.1.x
11:54:06.302 INFO - Started HttpContext[/,/]
11:54:06.306 INFO - Started HttpContext[/selenium-server,/selenium-server]
11:54:06.308 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
11:54:06.338 INFO - Started SocketListener on 0.0.0.0:4444
11:54:06.340 INFO - Started org.mortbay.jetty.Server@863399
Entering interactive mode... type Selenium commands here (e.g: cmd=open&1=http://www.yahoo.com)
The format for the query string is the same as for a HTML table in Selenese:
- What comes after “cmd=” is the first column.
- What comes after “&1=” is the second column.
- What comes after “&2=” is the third column (sometimes optional).
All normal commands including “open”, “type”, “click”, “verifyTextPresent”, etc. are supported, as well as special commands such getNewBrowserSession and shutDownSeleniumServer.
The first thing you need to do is start a browser session. You can either type in the command window (when in interactive mode):
12:14:20.698 INFO - ---> Requesting http://localhost:4444/selenium-server/driver?cmd=getNewBrowserSession&1=*chrome&2=ht
12:14:20.706 INFO - Command request: getNewBrowserSession[*chrome, http://one-shore.com] on session null
12:14:20.708 INFO - creating new remote session
12:14:20.710 INFO - Allocated session e4c0bda97077462aa916c61111a7f806 for http://one-shore.com, launching...
12:14:20.842 INFO - Preparing Firefox profile...
12:14:24.647 INFO - Launching Firefox...
or you can enter the url in a browser:
You’ll notice that when you ran the command getNewBrowserSession, it opened two new browser windows.
The first windows is a controller window. You can interact with this much as you would with the command line. The second window is a blank window, that will eventually be the window where your commands get executed.
The first window is the “chrome” driver. It is the controlling interface for selenium RC. (Chrome refers to the base version of Firefox, which has elevated privileges (and thus can avoid cross-site scripting limitations. The equivalent for Internet Explorer is “iehta”.)
There are three frames. The first is the control frame, the second shows a command history, and the third is blank. Depending on your configuration, the commands are executed in either the third frame, or in the second window (which is the default for newer versions of Selenium RC.)
A sessionID is returned, and will be needed to be passed as an argument to interact with selenium-server from the URL. The command line interface is tied to the sessionID automatically.
12:36:18.783 INFO - ---> Requesting http://localhost:4444/selenium-server/driver?cmd=open&1=/contact&sessionId=bb5439b87
12:36:18.803 INFO - Command request: open[/contact, ] on session bb5439b87fec422282d2ec42a2611171
12:36:19.379 INFO - Got result: OK on session bb5439b87fec422282d2ec42a2611171
12:37:30.973 INFO - Command request: open[/about, ] on session bb5439b87fec422282d2ec42a2611171
12:37:31.192 INFO - Got result: OK on session bb5439b87fec422282d2ec42a2611171
12:39:25.267 INFO - Got result: ERROR: Command timed out on session 79eaade6ab7249a1ac05ac71eab60e33
or enter the following URL into any browser window.
Note that you have to pass the sessionID as well. This is the only difference.
This is the way your selenium driver interacts with the selenium server at a low level. But you can forget all about that, because the APIs abstract all that and you can enter commands in Java (or Ruby or PHP, etc.) that are similar to the familiar HTML commands.
For instance, the above session could be executed with the following Java commands
Selenium selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://one-shore.com/");
Some commands, however, are not supported directly, or are an aggregate of multiple commands, such as verifyText which in java would look more like