Installation
Installation is rather a misnomer for Selenium. Selenium has set
of libraries available in the programming language of your choice.
Once you’ve chosen a language to work with, you simply need to:
- Install
the Selenium RC Server.
- Set
up a programming project using a language specific client driver.
Installing Selenium
Server
The Selenium RC server is simply a Java jar file
(selenium-server-standalone-<version-number>.jar), which doesn’t
require any special installation. Just downloading the zip file and extracting
the server in the desired directory is sufficient.
Running Selenium Server
Before starting any tests you must start the server. Go to the
directory where Selenium RC’s server is located and run the following from a
command-line console.
java -jar selenium-server-standalone-<version-number>.jar
This can be simplified by creating a batch or shell executable
file (.bat on Windows and .sh on Linux) containing the command above. Then make
a shortcut to that executable on your desktop and simply double-click the icon
to start the server.
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.
java -version
If you get a version number (which needs to be 1.5 or later),
you’re ready to start using Selenium RC.
Using the Java Client
Driver
- Download Selenium java client driver zip from the SeleniumHQ
- Extract
selenium-java-<version-number>.jar file
- Open
your desired Java IDE (Eclipse, NetBeans, IntelliJ, Netweaver, etc.)
- Create
a java project.
- Add
the selenium-java-<version-number>.jar files to your project as
references.
- Add
to your project classpath the file
selenium-java-<version-number>.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. You
can either use JUnit, or TestNg to run your test, or you can write your
own simple main() program. These concepts are explained later in this
section.
- Run
Selenium server from the console.
- Execute
your test from the Java IDE or from the command-line.
For details on Java test project configuration, see the Appendix
sections Configuring Selenium RC with Eclipse and Configuring selenium Rc with Installi.
Using the Python Client
Driver
- Install Selenium via PIP, instructions linked at SeleniumHQ
- Either
write your Selenium test in Python or export a script from Selenium-IDE to
a python file.
- Run
Selenium server from the console
- Execute
your test from a console or your Python IDE
For details on Python client driver configuration, see the
appendix Python Client driver Configuration
Using the .NET Client
Driver
- Download Selenium RC from the SeleniumHQ
- Extract
the folder
- Download
and install NUnit( Note: You can use NUnit as
your test engine. If you’re not familiar yet with NUnit, you can also
write a simple main() function to run your tests; however NUnit is very
useful as a test engine.)
- Open
your desired .Net IDE (Visual Studio, SharpDevelop, MonoDevelop)
- Create
a class library (.dll)
- Add
references to the following DLLs: nmock.dll, nunit.core.dll, nunit.
framework.dll, ThoughtWorks.Selenium.Core.dll,
ThoughtWorks.Selenium.IntegrationTests.dll and
ThoughtWorks.Selenium.UnitTests.dll
- Write
your Selenium test in a .Net language (C#, VB.Net), or export a script
from Selenium-IDE to a C# file and copy this code into the class file you
just created.
- Write
your own simple main() program or you can include NUnit in your project
for running your test. These concepts are explained later in this chapter.
- Run
Selenium server from console
- Run
your test either from the IDE, from the NUnit GUI or from the command line
For specific details on .NET client driver configuration with
Visual Studio, see the appendix.NET clientdriver Configuration.
Using the Ruby Client
Driver
- If
you do not already have RubyGems, install it from RubyForge
- Run gem install selenium-client
- At
the top of your test script, add require "selenium/client"
- Write
your test script using any Ruby test harness (eg Test::Unit, Mini::Test or
RSpec).
- Run
Selenium RC server from the console.
- Execute
your test in the same way you would run any other Ruby script.
For details on Ruby client driver configuration, see the Selenium client documentation.
From Selenese to a
Program
The primary task for using Selenium RC is to convert your Selenese
into a programming language. In this section, we provide several different
language-specific examples.
Sample Test Script
Let’s start with an example Selenese test script. Imagine
recording the following test with Selenium-IDE.
|
open
|
/
|
|
|
type
|
q
|
selenium
rc
|
|
clickAndWait
|
btnG
|
|
|
assertTextPresent
|
Results
* for selenium rc
|
|
Selenese as Programming
Code
Here is the test script exported (via Selenium-IDE) to each of the
supported programming languages. If you have at least basic knowledge of an
object- oriented programming language, you will understand how Selenium runs
Selenese commands by reading one of these examples. To see an example in a
specific language, select one of these buttons.
/** Add JUnit
framework to your classpath if not already there
*
for this example to work
*/
package com.example.tests;
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
public class NewTest extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://www.google.com/", "*firefox");
}
public void testNew() throws Exception {
selenium.open("/");
selenium.type("q", "selenium
rc");
selenium.click("btnG");
selenium.waitForPageToLoad("30000");
assertTrue(selenium.isTextPresent("Results * for
selenium rc"));
}
}
In the next section we’ll explain how to build a test program
using the generated code.
No comments:
Post a Comment