Visualizzazione post con etichetta Selenium. Mostra tutti i post
Visualizzazione post con etichetta Selenium. 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!

martedì 14 agosto 2012

Selenium RC: overcome HTTPS not trusted certificate issue in testing firefox

When you get "This connection is untrusted" here is what you can do:

Create a firefox profile and make the Selenium RC to use it



Instead of
// Starting Selenium Server
try 
{
      sesrv = new SeleniumServer();
      sesrv.start();
} catch (Exception e) 
{
      e.printStackTrace();
}

we start the Selenium Server by imposing a firefox custom profile (solution suggested here remote configuration )

// Starting Selenium Server
try 
{
      RemoteControlConfiguration configuration = new RemoteControlConfiguration();
      File newFirefoxProfileTemplate = new File("C:/Users/andrea.ferraresi/AppData/Roaming/Mozilla/Firefox/Profiles/7phs191j.selenium");
      //To get the firefox profile and force Selenium to dump it temporarily into the file system and then use that path to set the firefox profile template via

      configuration.setFirefoxProfileTemplate(newFirefoxProfileTemplate);

      sesrv = new SeleniumServer(configuration);
      sesrv.start();
} catch (Exception e) 
{
      e.printStackTrace();
}

We create the custom profile by using firefox.exe -P
as explained here Creating_a_new_Firefox_profile_on_Windows

and then we have to
- browse with the custom profile just created to the https page where "This connection is untrusted" appears
- accept the certificate so the next time this profile will be used then the connection would be trusted
- by creating the custom profile, a new folder is created in the default location (for example
C:/Users/andrea.ferraresi/AppData/Roaming/Mozilla/Firefox/Profiles/) where the profiles are store. It is necessary to specify
new File("<folder where cert8.db and extensions.ini files are> ");

Be careful to specify the folder name: I've used 7phs191j.selenium in my case because that's the name of the folder created when I  created the custom profile by running firefox.exe -P :
I specified selenium as a profile name, while 7phs191j was added automatically.

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