Goal: to execute sequentially a bunch of Selenium RC tests written in junit in easy, quick, lean steps
Ingredients
Selenium RC tests written in junit
Apache Maven
Eclipse
Apache Maven
Eclipse
Recipe
The Selenium RC tests written in junit are each able to instantiate and launch the Selenium Server, beyond executing the test by interacting with the web interface. Indipendently, one test from the other ones.
I wrote the tests in Eclipse, so they are part of a java project which relies on junit and selenium libraries.
The steps to achieve the goal are:
This blog is sponsored by Italian Aurora e da Veni Vidi Vici Bici! da 0 a 139 anni. Puoi guardare il video della presentazione di Veni Vidi Vici Bici! da 0 a 139 anni
The steps to achieve the goal are:
- Install the maven plugin for Eclipse (for example m2e - Maven Integration for Eclipse 1.0.200.20111228-1245 org.eclipse.m2e.feature.feature.group)
- right click on the java project, select Configure --> Convert to Maven Project
- At this point the Eclipse project is broken: the “build path” is “blank” ( the junit and selenium libraries are not anymore part of the project). But a pom.xml is created.
- Start to work at the pom: add the selenium server and junit dependencies, in order to tell maven which libraries the code needs to be compiled and executed (selenium dependencies in maven are explained here): I've added junit 4.10 and selenium-server2.25.0 by selecting the tab dependency in the pom file, and selecting "junit "and "org.seleniumhq.selenium selenium-server" voices
- Now we need to tell Maven which test it should execute: add **/*.java as a way to state "run every test, whichever the name", because by default the maven-surefire-plugin executes the tests whose name is "*test*.java" in the test goal/phase
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
At this point we are ready:
- save the pom: you can see errors in Eclipse because the dependencies are not yet downloaded from the maven repository
- run mvn install in a shell window from the folder where the pom.xml file is created
The maven dependencies are downloaded and then:
- All the tests running in the TEST phase by the surefire:test goal
- The maven dependencies are specified in the build path, so we can keep on developing in the same eclipse project
- Any properties files the tests relied upon are read by the tests without any need for configuration
Mission accomplished!
This blog is sponsored by Italian Aurora e da Veni Vidi Vici Bici! da 0 a 139 anni. Puoi guardare il video della presentazione di Veni Vidi Vici Bici! da 0 a 139 anni
Aside: fancy a drink? Participate in one of the events (or schedule your own, if you are here it means you enjoy to act on your own initiative) run by cocktail bar hire, so you can enjoy fun and home-made cocktails, a rarity!