Transitioning from Selenium IDE to Remote Control

I recently wrote a blog post about writing higher level test cases using Selenium RC

https://fijiaaron.wordpress.com/2009/09/02/selenium-page-objects-site-objects-data-objects-high-level-navigation/

If you are just transitioning from using Selenium IDE, it might be a bit abstract for you.

To start with, you need to decide which platform you are targeting:

  • What programming language you plan on using?
    (Selenium supports Java, Ruby, PHP, Perl, Python, C#, and Groovy)
  • What testing framework you plan on using ?
    (dependent on the language, e.g. junit, nunit, phpUnit, testng, rspec, etc.)
  • How you want to execute your tests?
    (this can be left as a step for later, once you have a working test framework)

    • in Selenium IDE (you probably don’t need this tutorial, then)
    • via the command line (e.g. with the junit textrunner)
    • in your IDE (e.g. with a plugin for Eclipse, Netbeans, IDEA, Visual Studio, Emacs)
    • with an automated build script (ant, rake, etc.)
    • from continuous integration (cruisecontrol, hudson, etc.)

I’m going to assume Java, JUnit, and Ant.  But you could just as easily use Ruby, Rspec, and Rake, or whatever you prefer.

You can use Selenium IDE to record some example tests and then convert them to Junit test cases.  This will help you get familiar with the basic format and syntax of Selenium tests written inJava with JUnit.

selenium_ide_format_junit

Here is the output of that script from Selenium IDE:

package com.example.tests;

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
public class OneshoreContactFormTest extends SeleneseTestCase {

   public void setUp() throws Exception {
      setUp("http://www.one-shore.com/", "*chrome");
   }

   public void testOneshoreContactForm() throws Exception {
      selenium.open("/");
      selenium.click("link=contact");
      selenium.waitForPageToLoad("30000");
      selenium.select("dept", "label=Other");
      selenium.type("name", "Aaron Evans");
      selenium.type("email", "aarone@one-shore.com");
      selenium.type("subject", "online training in selenium junit");
   }
}

Note that the test extends SeleneseTestCase, which extends the base JUnit TestCase.  There are other options, including extending TestCase yourself and handling setUp (which launches the browser), or writing your own base class.

The next step is to run your tests with Selenium Remote Control:

http://seleniumhq.org/projects/remote-control/

Selenium Remote Control  can be downloaded from:

http://release.seleniumhq.org/selenium-remote-control/1.0.1/selenium-remote-control-1.0.1-dist.zip

You can start Selenium server by executing the following command (additional lines are the output):

C:\selenium-remote-control-1.0.1\selenium-server-1.0.1>java -jar selenium-server.jar
10:21:43.631 INFO - Java: Sun Microsystems Inc. 1.5.0_13-b05
10:21:43.633 INFO - OS: Windows Vista 6.0 x86
10:21:43.648 INFO - v1.0.1 [2696], with Core v@VERSION@ [@REVISION@]
10:21:43.820 INFO - Version Jetty/5.1.x
10:21:43.823 INFO - Started HttpContext[/,/]
10:21:43.826 INFO - Started HttpContext[/selenium-server,/selenium-server]
10:21:43.828 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
10:21:43.860 INFO - Started SocketListener on 0.0.0.0:4444
10:21:43.861 INFO - Started org.mortbay.jetty.Server@863399

There are additional parameters that can be passed, including specifying a different port (the default is 4444):

java –jar selenium-server.jar –port 4445

To see all options include the –help flag:

java –jar selenium-server.jar – help

Your test can be run by executing junit from the command line, in your IDE, or via an ant script. I’ll go over that in my next post, with additional posts covering:

  • accessing  external resources in your tests (like querying a database)
  • test abstraction and organization (like page based testing)
  • using different testing frameworks (such as Rspec, JBehave, and Cucumber)
  • testing multiple browsers with Selenium Grid
  • executing your tests as part of a continuous integration process.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s