Visualizzazione post con etichetta Selenium tests. Mostra tutti i post
Visualizzazione post con etichetta Selenium tests. Mostra tutti i post

domenica 4 novembre 2012

Get Maven to execute Selenium tests written in junit: how to for dummies

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

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:


  1. Install the maven plugin for Eclipse (for example m2e - Maven Integration for Eclipse 1.0.200.20111228-1245 org.eclipse.m2e.feature.feature.group)
  2. right click on the java project, select  Configure --> Convert to Maven Project
  3. 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.
  4. 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
  5. 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:
  1. save the pom: you can see errors in Eclipse because the dependencies are not yet downloaded from the maven repository
  2. 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!

venerdì 21 settembre 2012

Hudson Cluster set up


Goal


We have an Hudson server (to be the master) in a Linux (centOs) environment
We want to have Hudson slaves in a separated Windows virtual machines in order to run Selenium tests
We want to set up a Selenium Cluster
We want the master to launch the slaves automatically

How to set up an Hudson Cluster automatically


Ingredients

- an Hudson server up and running (mine was launch by running java -jar hudson-2.2.1.war --ajp13Port=8010 --httpPort=8011 on VM http://192.168.1.157)
- an Hudson slave configured such that "Launch slave agents via JNLP" (instructions here) (in this example the name of the slave is "MyWindowsMachine")
- slave.jar (you can find it in the folder /root/.hudson/war/WEB-INF: use this because it needs to be of the same version as the hudson-x.x.x.war)
- a separated Windows VM (the ip address in the example is 192.168.1.79)
- winexe (source here)

Recipe

1. place slave.jar in a folder in the slave Windows VM (in this example, C:\Users\andrea.ferraresi\Downloads\hudsonSlave)
2. create a batch file with the following 2 instructions and place it in the same folder as above (in this example, C:\Users\andrea.ferraresi\Downloads\hudsonSlave)
cd C:\Users\andrea.ferraresi\Downloads\hudsonSlave\
java -jar slave.jar -jnlpUrl http://192.168.1.157:8011//computer/MyWindowsMachine/slave-agent.jnlp
Notes: cd + folder where the batch file is placed. The jnlpUrl url is http://<remote ip address on the linux server><port where you can access hudson>//computer/<name of the hudson slave node set in the ingredients>/slave-agent.jnlp

3. place winexe in a folder of the linux VM (I place the uncompressed file winexe-static-081123 in
/home/andrea.ferraresi/winexe/winexe3/withoutSource) and make it executable (I've used chmod 777 *)
4. Create an Hudson job on the Hudson master: just choose "Add build step" -> execute shell -> and add the following instructions:
cd /home/andrea.ferraresi/winexe/winexe3/withoutSource
./winexe-static-081123 -U andrea.ferraresi%password -W POLESTAR //192.168.1.79
"C:\Users\andrea.ferraresi\Downloads\hudsonSlave\cdJjnlp.bat"

Notes: cd <folder where winexe was placed>. Then the command line according to the winexe syntax: ./<winexe program name> -U <username>%<password> -W <pc domain> //<ip address of the slave Windows VM> "<launch the batch file on the slave Windows VM>"


5. Build the Hudson job and the Hudson slave on Windows VM will be connected to the Hudson Master, so now we can configure Hudson job in the master to be run by the Hudson slave


Conclusions


An Hudson job on the Hudson server is able to kick off the connection with the Hudson slave automatically.

Following this procedure we can encounter an issue:
no matter if we stop the winexe program execution, somehow (I didn't discover how) the hudson master is able to connect to the hudson slave in a matter of seconds (when we configured the slave we have chosen the option "Keep this slave online as much as possible". This doesn't seem a great issue, until the moment we decide to modify the master-slave connection: we need to devise ways to shut it down completely and definitely, what about deleting the slave node configured in the Hudson master?





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