Integrating Selenium Tests into CruiseControl.Net via NUnit

Getting Selenium and CruiseControl.Net to talk to each other requires some work and behind-the-scenes configuration. Before incorporating Selenium tests into CruiseControl.Net, make sure you:

To successfully get Selenium, NUnit and CruiseControl.Net talking to each other, you will have to accomplish the following:

  1. Configure Selenium RC to run as a service
  2. Edit your CruiseControl.Net config file to include a NUnit task
  3. Point NUnit to your Selenium Unit Test Library

The details of this article help to get you started in accomplishing the tasks above.

Running Selenium RC as a service

By default, Selenium RC runs as a stand-alone application capable of managing Selenium unit tests and directing traffic for different browser requests. If you want to incorporate your Selenium tests into CruiseControl.Net, you have to get Selenium RC running as a service.

I found a great resource that details how to do this. To summarize the article, follow these simple steps:

  1. Download a copy of the Windows Resource Kit.
  2. Register the new service “SeleniumRC”

    "C:\Program Files\Windows Resource Kits\Tools\instsrv.exe" SeleniumRC
    "C:\Program Files\Windows Resource Kits\Tools\srvany.exe" -a [myuser] -p [mypass]
    
  3. Edit your registry to include the path of your Selenium RC installation and executable:

    Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SeleniumRC\Parameters]
    "Application"="java.exe"
    "AppDirectory"="C:\\Program Files\\selenium-server-1.0.1"
    "AppParameters"="-Xrs -jar selenium-server.jar"
    
  4. Now that you have the Selenium RC service created, go to Administrative Tools > Services and start the service. Check the system event logs for errors to ensure everything is working properly.

    Wire-Up Selenium to CruiseControl.Net using NUnit

    With the Selenium RC service running, edit your CruseControl.Net config file to incorporate NUnit:

    
    

        <tasks>

          <exec>

            <executable>C:\Program Files (x86)\NUnit 2.5.5\bin\net-2.0\nunit-console.exe</executable>

            <buildArgs>"C:\Users\Dave\Documents\Visual Studio 2008\Projects\SeleniumTest\SeleniumTest\bin\Debug\SeleniumTest.dll"</buildArgs>

          </exec>

        </tasks>

    After a successful execution of your test plan using Selenium RC in CruiseControl.Net, you should see a response from NUnit in your CruiseControl.Net build log like the following:

    <buildresults>
      <message>NUnit version 2.5.5.10112</message>
      <message>Copyright (C) 2002-2009 Charlie Poole.</message>
      <message>Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.</message>
      <message>Copyright (C) 2000-2002 Philip Craig.</message>
      <message>All Rights Reserved.</message>
      <message>Runtime Environment - </message>
      <message>   OS Version: Microsoft Windows NT 6.1.7600.0</message>
      <message>  CLR Version: 2.0.50727.4927 ( Net 2.0 )</message>
      <message>ProcessModel: Default    DomainUsage: Single</message>
      <message>Execution Runtime: net-2.0</message>
      <message>.</message>
      <message>Tests run: 1, Errors: 0, Failures: 0, Inconclusive: 0, Time: 20.9481982 seconds</message>
      <message>  Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0</message>
    </buildresults>
    </build>
    </cruisecontrol>
    
    Advertisements

Configuring CruiseControl.Net with SVN, Visual Studio 2008 and MSBuild

Integrating CruiseControl.Net into our development environment was a fairly simple process. The steps below detail what was required to get CruiseControl.Net to pull changes from SVN, on an interval trigger, then build using Visual Studio 2008 via MSBuild.

For details on configuration options for CruiseControl, refer to the online documentation.

Installing CruiseControl.Net

1. Download the latest installation files. The latest release at the time of this article is 1.5.725.

2. Run the installation file and place the files in the default directory C:\Program Files\CruiseControl.NET.

CruiseControl.Net Overview

CruiseControl can run either as a stand-alone exe or by running as a service. It’s important to run the stand-alone application when building your config file at first. The exe will run in a command window displaying everything that’s happening within your CruiseControl.Net server. It’s an essential tool to debugging your config file.

Stand alone application is located in: C:\Program Files\CruiseControl.NET\server\ccnet.exe

The CruiseControl.Net service is named CruiseControl.Net Server (in Control Panel/Administrative Tools/Services)

Editing Your Configuration File

1. Open CruiseControl.Net’s main configuration file

Locate file ccnet.config in C:\Program Files\CruiseControl.NET\server.

2. Add your project


<project name="Public Website">

  <workingDirectory>d:\build\trunk\Website</workingDirectory>

  <webURL>http://server1/ccnet/server/local/project/testProject/ViewLatestBuildReport.aspx</webURL>

  <triggers>

    <intervalTrigger name="continuous" seconds="30" buildCondition="ForceBuild" initialSeconds="30"/>

  </triggers>

  ...

</project>

The project contains the following tags:

  • <workingDirectory> – The directory CruiseControl.Net will use to manage your project.
  • <webURL> – The build report for the project you’re configuring.
  • <triggers> – How often CruiseControl will pull down files from source control and build the solution. The example above has an interval trigger of 30 seconds. Every 30 seconds CruiseControl will check source control for modifications. If they exist, a build will be triggered.

3. Define SVN as your Source Control


    <sourcecontrol type="svn">

      <trunkUrl>https://MyServer/svn/website/trunk</trunkUrl>

      <workingDirectory>d:\build\Website</workingDirectory>

      <username>dave</username>

      <password>dave123</password>

      <timeout units="minutes">30</timeout>

    </sourcecontrol>

Within the <sourcecontrol> tag, our SVN configuration is defined:

  • <trunkUrl> – Location of the main trunk for our project.
  • <workingDirectory> – Directory to place all files pulled down from SVN when doing a build.
  • <username> / <password> – SVN credentials

4. Add an MSBuild task

A basic MSBuild task is below, essentially building our solution from the command prompt using Visual Studio. Build options used are debug and rebuild all.

    <tasks>

      <msbuild>

        <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>

        <workingDirectory>D:\build\Website</workingDirectory>

        <projectFile>MyWebSolution.sln</projectFile>

        <buildArgs>/p:Configuration=Debug /v:diag /t:rebuild</buildArgs>

        <timeout>120</timeout>

      </msbuild>

    </tasks>

5. Configure Notifications

CruiseControl.Net does a great job of notifying when builds break. The CCTray, CruiseControl’s notification icon stays in the bottom right-hand corner of your desktop in your system tray. Your icon turns green on successful builds, yellow when building and red when the build fails.

If this isn’t enough, you can setup email notifications. If you work in an environment where you have outsourced development, it helps to send out instant notifications if someone breaks the build.

    <publishers>

      <xmllogger logDir="D:\build\Website\BuildLogs" />

      <email mailport="25" includeDetails="TRUE">

        <from>no-reply@wordpress.com</from>

        <mailhost>mail.MyServer.com</mailhost>

        <users>

          <user name="Dave" group="BuildGuru" address="david.scott.peterson@gmail.com" />

        </users>

        <groups>

          <group name="BuildGuru">

            <notifications>

              <notificationType>Failed</notificationType>

              <notificationType>Fixed</notificationType>

              <notificationType>Exception</notificationType>

            </notifications>

          </group>

        </groups>

      </email>

    </publishers>

Server Configuration

The CruiseControl.Net service needs to run as an account that has access to the source code repository. Since our source control is listed under HTTPS, but with no valid SSL certificate, we have to convince CruiseControl to ignore the certificate error. The CruiseControl.Net user account needs to permanently accept the certificate exception, otherwise, CriuseControl will fail to pull down the latest code from SVN.

Steps to creating the CruiseControl.Net service account:

1. Create a CruiseControl.Net local user account.

New CruiseControl.Net User

Create a new user for the CruiseControl.Net service

2. Setup service to run as new CruiseControl.Net local user account.

CruiseControl.Net Service Settings

Run the service as your new CCNetUser local account

3. Accept SSL exception for CruiseControl.Net local user account.

Accept the SSL Certificate Permanently

Accept the SSL Certificate Permanently

Login to the server hosting CruiseControl.Net using the account created in step 1. Open a command prompt and type: ‘svn list https://<svn repository location>’. When prompted to accept the certification exception, type ‘p’ for permanently.

Full CCNet.config

<cruisecontrol>

  <!– This is your CruiseControl.NET Server Configuration file. Add your projects below! –>

 

  <!– Trunk –>

  <project name=My Website>

    <workingDirectory>d:\build\trunk\Website</workingDirectory>

    <webURL>http://server1/ccnet/server/local/project/testProject/ViewLatestBuildReport.aspx</webURL>

    <triggers>

      <intervalTrigger seconds=30 buildCondition=IfModificationExists/>

    </triggers>

    <sourcecontrol type=svn>

      <trunkUrl>https://MyServer/svn/website/trunk</trunkUrl>

      <workingDirectory>d:\build\Website</workingDirectory>

      <username>dave</username>

      <password>dave123</password>

      <timeout units=minutes>30</timeout>

    </sourcecontrol>

    <tasks>

      <msbuild>

        <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>

        <workingDirectory>D:\build\Website</workingDirectory>

        <projectFile>MyWebSolution.sln</projectFile>

        <buildArgs>/p:Configuration=Debug /v:diag /t:rebuild</buildArgs>

        <timeout>120</timeout>

      </msbuild>

    </tasks>

    <externalLinks>

      <externalLink name=My Website url=http://MySite.com />

    </externalLinks>

    <publishers>

      <xmllogger logDir=D:\build\Website\BuildLogs />

      <email mailport=25 includeDetails=TRUE>

        <from>no-reply@wordpress.com</from>

        <mailhost>mail.MyServer.com</mailhost>

        <users>

          <user name=Dave group=BuildGuru address=david.scott.peterson@gmail.com />

        </users>

        <groups>

          <group name=BuildGuru>

            <notifications>

              <notificationType>Failed</notificationType>

              <notificationType>Fixed</notificationType>

              <notificationType>Exception</notificationType>

            </notifications>

          </group>

        </groups>

      </email>

    </publishers>

  </project>

</cruisecontrol>