11 - Selenium Plugin


The Selenium plugin is part of the base package shipped with Squash-TA (It is automatically installed if you choose the default project configuration for your test project), however it is packaged as a separate plugin you can exclude it from the test project (and so avoid downloading and installing its dependencies).

This plugin provides all the elements needed to execute selenium tests in Squash-TA.


Overview

The Selenium plugin for Squash TA currently allows the integration of the following types of java Selenium Tests into Squash-TA:
  • Selenium 1
    • jUnit 3-based tests
    • jUnit 4-based tests
  • Selenium 2
    • jUnit 3-based tests
    • jUnit 4-based tests

Selenium Tests must be included in the test project as java sources, and their non-selenium dependencies (if any) packaged as maven2 dependencies and declared in the squash-ta-mavin-plugin dependencies. The source code and resources are compiled each time before the test is executed (see the converters section for details).

For Selenium 1 tests, you may at your convenience use the included selenium server management system (see managing your selenium server in ecosystem environment scripts), or use a selenium server already available in your testing environment.

If you are looking for information on how to import your existing selenium tests, see the importing legacy tests section.

NB: a running installation of the browser used by your test is of course required on the machine your selenium RC server runs on. For Selenium 2 a working installation of the target browser is required on the machine where the tests are run.


Managing your selenium server in ecosystem environment scripts

To launch and kill your selenium server as part of the ecosystem environment management, proceed as follows:
  • In your ecosystem setup.ta script, insert the following code: 
LOAD seleniumConf.properties AS seleniumConf.file
CONVERT seleniumConf.file TO configuration.selenium AS seleniumConf
EXECUTE launch WITH seleniumConf AS seleniumServer
  • In your ecosystem teardown.ta script, insert the following code:
EXECUTE cleanup WITH seleniumServer AS ignoredResource
NB: Remember, resources defined in the ecosystem setup and teardown scripts can only be seen in these scripts, not in test scripts. However, a resource defined in the ecosystem setup script will be seen in the corresponding ecosystem teardown script, as the seleniumServer resource above.
  • Create the seleniumConf.properties file in your test resources. The minimal content is as follows:
squashtest.ta.selenium=yes

NB: Any value is accepted as long as this key exists. See the configuration.selenium resource type documentation for useful parameters.


Organizing selenium-related files in your Squash-TA project

'file to script.java.selenium1' or 'file to script.java.selenium2' converters both work from a file resource that is in fact a bundle (a group of files). This group of files may contain java sources and various resources. All sources and resources used by the test must be included in the file bundle. This means that they must be all grouped in a directory that will be loaded as a file resource, and then converted to a 'script.java.selenium1' or 'script.java.selenium2 resource'. As in usual java code and resources, the directory structure defines packages in which the classes and resources are located. As in the maven convention, source files will be searched for in the <base>/java directory, and any directory under <base>/java will define a package level. Resources will be searched for in the same way under <base>/resources.

Regarding binary dependencies (as opposed to helper source source code, which must be included in the selenium test resource directory), they must be provided as maven jars included in the plugin dependencies like so:

Extract from test project pom.xml file

...
<plugin>
<groupId>org.squashtest.ta</groupId>
<artifactId>squash-ta-maven-plugin</artifactId>
<version>1.1.0</version>

<dependencies>
...
<!-- example of a Selenium test dependency -->
<dependency>
<groupId>net.sourceforge.javacsv</groupId>
<artifactId>javacsv</artifactId>
<version>2.0</version>
</dependency>
...
</dependencies>
...
</plugin>
...



Importing legacy Selenium tests

To import your Selenium tests into your Squash-TA test projects, just copy your test source tree (with code AND resources) under a single subdirectory in the squashTA/resources directory. For example, if your test source code and resources where under src/test/java and src/test/resources, respectively, you just have to copy the java and test directories in the squashTA/resources/seleniumTests subdirectory:



Now, you just have to load seleniumTests as a resource to use it in your test.