Installing Selenium Server
The Selenium-RC server is simply a Java jar file (selenium-server.jar), which doesn’t require any special installation. Just downloading the zip file and extracting the server in the desired directory is sufficient.
Create a directory on your computer called selenium. For windows you can put it under the c:\ drive.
Extract the selenium*.zip file downloaded into that folder just created. Windows extract tool may not work, try using winzip.
Now the folder will contain what looks like this:
Running Selenium Server
Before starting any tests you must start the server. Go to the directory called where Selenium-RC’s server is located. In the example above Selenium RC is in c:\selenium\selenium-server-1.0.3 and run the following from a command-line console.
java -jar selenium-server.jar
For the server to run you’ll need Java installed and the PATH environment variable correctly configured to run it from the console. You can check that you have Java correctly installed by running the following on a console:
If you get a version number (which needs to be 1.5 or later), you’re ready to start using Selenium-RC. If not you need to install Java from Oracle.
Using the Java Client Driver
- Watch this video on how to set up Eclipse for Selenium RC. Click on it twice and view as a pop out or full screen or use this link.
- The Java client driver is in c:\selenium\selenium-java-client-driver-1.0.1.
- The file is selenium-java-client-driver.jar.
- Open your desired Java IDE (Eclipse, NetBeans, IntelliJ, Netweaver, etc.) For this example we will use Eclipse.
- Create a new project.
- Add jUnit 3 as a library.
- Add the selenium-java-client-driver.jar files to your project as references.
- Add to your project classpath the file selenium-java-client-driver.jar.
- From Selenium-IDE, export a script to a Java file and include it in your Java project, or write your Selenium test in Java using the selenium-java-client API. The API is presented later in this chapter. Video
- Create a package called com.example.tests and put the file in it. This would be different for each project you work on.
- There is a bug in Selenium RC when testing SSL applications in Internet Explorer. You must modify the test with the setUp code below.
public void setUp() throws Exception { //setUp("https://brad-pc.lmnsolutions.com:8443/", "*chrome");
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "https://brad-pc.lmnsolutions.com:8443/") {
public void open(String url) {
commandProcessor.doCommand("open", new String[] {url,"true"});
}
};
selenium.start();
}
- Execute your test from the Java IDE by selecting Run As junit.
For details on Java test project configuration, see the Appendix sections Configuring Selenium-RC With Eclipse and Configuring Selenium-RC With Intellij.
One method of running on https or SSL is to use a saved profile.
Specifying the Firefox Profile
Firefox will not run two instances simultaneously unless you specify a separate profile for each instance. Selenium-RC 1.0 and later runs in a separate profile automatically, so if you are using Selenium 1.0, you can probably skip this section. However, if you’re using an older version of Selenium or if you need to use a specific profile for your tests (such as adding an https certificate or having some addons installed), you will need to explicitly specify the profile.
First navigate to the application you are testing and accept any certificates and security exceptions. This will add that information to your profile.
First, to create a separate Firefox profile, follow this procedure. Find the Application Data for Firefox and then a profile file that ends with .default. ie. xxxxxxx.default Video
| Windows XP / 2000 | %AppData%\Mozilla\Firefox\Profiles\xxxxxxxx.default\ |
| Windows 95 / 98 / ME | C:\WINDOWS\Application Data\Mozilla\Firefox\Profiles\xxxxxxxx.default\ |
| Linux | ~/.mozilla/firefox/xxxxxxxx.default/ |
| Mac OS X | ~/Library/Application Support/Firefox/Profiles/xxxxxxxx.default/ |
Create the new profile using the dialog. Then when you run Selenium Server, tell it to use this new Firefox profile with the server command-line option -firefoxProfileTemplate and specify the path to the profile using it’s filename and directory path.
-firefoxProfileTemplate "path to the profile"
Warning
Be sure to put your profile in a new folder separate from the default!!! The Firefox profile manager tool will delete all files in a folder if you delete a profile, regardless of whether they are profile files or not.