Jump Start FitNesse with Sahi using Generic Fixture

Sahi is one of the popular automated web test tool these days. Recently a comment was made by Mr Tom Heintzberger on my blog post here on Use of variables, arrays and complex types in Generic Fixture regarding use of Sahi with Generic Fixture and the problems he’s facing while trying to build DSL around it. So I decided to look into it and ended up creating a DSL myself to be used with Sahi.

Refer to Jump Start FitNesse with Selenium using Generic Fixture for detailed steps to download and install FitNesse & Generix Fixture.

Create a page on FitNesse for Sahi Web Test using Generic Fixture

  1. Open your browser and goto the URL http://localhost:8000/FrontPage. Look for the Edit button on the left hand navigation column. If Edit button is not present then goto the URL http://localhost:8000/FrontPage?properties and select the “Edit”check box and click on Save Properties. Now click on Edit button and once on the Edit Page add a new line at the end of all the text already there and save your changes.
    |[[Sahi Web Test Suites][FitNesse.SahiTestSuite]]|Sahi Web Tests|
  2. Now on the Front Page it will display a text like “Sahi Web Test Suites?” with ? as hyper link. Click on ? link.
  3. Once in the Edit Page, copy paste following text into text area and save your changes:
    !*> Class Path & Global Defines
    !path genericfixture.jar
    !path sahi.jar
    !path bsh.jar
    
    !define COLLAPSE_SETUP {true}
    !define COLLAPSE_TEARDOWN {true}
    *!
    ----
    >SetUp
    >TearDown
    >GoogleSahiTest
  4. You will notice 3 ? links on the page indicating missing pages. Now lets create each and every missing page.
  5. Click on the ? link next to SetUp text and on the “Edit Page” text area copy-paste following code and finally save your changes.
    !| DSL Adapter |
    | user starts the browser | open | |
    | user opens the URL | % | navigateTo | {1} |
    | page has the title | title | |
    | user clicks on the link named | % | GenericFixture.bsh | sahi.link( new String[] {"{1}"} ).click(); |
    | page loads in less than | % | seconds | waitFor | {1}000 |
    | user types | % | into | % | field | GenericFixture.bsh | sahi.textbox( new String[] {"{2}"} ).setValue( "{1}" ); |
    | user clicks on the button named | % | GenericFixture.bsh | sahi.submit( new String[] {"{1}"} ).click(); |
    | page has URL | fetch | location.href |
    | show | toString | |
    
    !| Generic Fixture| net.sf.sahi.config.Configuration |
    | initJava | /home/sahi | /home/sahi/userdata |
    
    !| Generic Fixture | sahi=net.sf.sahi.client.Browser | firefox |
    | user starts the browser |
  6. Go back to the page: http://localhost:8000/FitNesse.SahiTestSuite
  7. Click on the ? link next to TearDown text and on the “Edit Page” text area copy-paste following code and finally save your changes.
    !| Generic Fixture | sahi= |
    | user stops the browser |
  8. Again go back to the page: http://localhost:8000/FitNesse.SahiTestSuite
  9. Now click on ? link next to GoogleSahiTest text and on the “Edit Page” text area copy-paste following code an save your changes.
    !| Generic Fixture | sahi= |
    | isFirefox | | true |
    | user opens the URL | http://www.google.co.in |
    | user types | sahi forums | into | q | field |
    | user clicks on the button named | Google Search |
    | page loads in less than | 1 | seconds |
    | user clicks on the link named | Sahi - Web Automation and Test Tool |
    | page loads in less than | 1 | seconds |
    | page has the title | | Sahi - Web Automation and Test Tool  |
    | page has URL | | http://sahi.co.in/forums/ |
  10. After saving your changes click on Properties button from the left hand navigation menu and click on check box left to Test property and save your changes. Now you should see Test button available on the top lest navigation menu.

Execute your Google Sahi Test Page on FitNesse using Selenium

Just click on the Test click on this page: http://localhost:8000/FitNesse.GenericFixture.SahiTestSuite.GoogleSahiTest and watch how your Sahi automated web test is being run. Test will open a new Firefox browser and go to http://www.google.com and search Google with query text “sahi forums
Upon completion of test you should see this on the top of the results page:

Assertions: 3 right, 0 wrong, 0 ignored, 0 exceptions

Hope this post will help some readers trying to use Sahi Automation Testing with Generic Fixture or people facing similar issues while using other frameworks with Generic Fixture.

Jump Start FitNesse with Selenium using Generic Fixture

Download FitNesse

Go to http://fitnesse.org/FitNesseDevelopment.DownLoad and download the the latest fitnesse.jar. Create a directory c:\program files\fitnesse\. Copy the downloaded fitnesse.jar into directory c:\program files\fitnesse. fitnesse.jar is an executable jar file so just double click this file and it will install itself.

Download Selenium Remote Control (Selenium RC)

Go to http://selenium-rc.openqa.org/download.jsp and download the latest version (1.0.3 at the time of writing this page). Unpack the zip into c:\program files\selenium\ directory. Current version for Selenium-RC is 1.0.3 and these instructions are written assuming you are using this version.

Create a smart start script

Copy and paste following script into a file called run.vbs under the directory “C:\Program Files\selenium\selenium-server-1.0.3”. This script will start both FitNesse servers and Selenium remote control servers on their default ports 8000 and 4444 respectively. This script will ONLY start these processes if these processes are not running, so this script can be safely run any time.

PS: Please note that this script is starting Selenium in an experimental Proxy Injection Mode which lets you run your web test across multiple domains. If you don’t want to use this feature feel free to change this start script.

Continue reading

Introducing Generic Fixture for FitNesse

I have been using FitNesse (A wiki based integrated testing framework) for last few years to create automated integrated acceptance tests for my back end Java based and legacy C/C++ applications. It has helped us tremendously towards our efforts to adapt to Test Driven Development (TDD). FitNesse has really helped our development team to find & fix bugs much earlier and our QA team to validate them pretty quickly. For beginners I will recommend reading the documentation on its official web site http://fitnesse.org/ for information on downloading, installing and setting up FitNesse. FitNesse provides various “Test Table Styles” (or fixtures) to write your tests. Each Table/Fixture Style has its own usage and purpose.

For testing business logic in my back end applications I mostly used ColumnFixture, TableFixture and RowFixture for defining inputs and output data sets. All I needed to write was a thin adapter or mapper Java class that extends any of these fixtures. That thin adapter Java class just gets input data from wiki and use that data to make a call to my back end application. At the end of the call it just makes the result available for FitNesse to display on wiki page. This thin adapter class is fully Fixture aware and developer of this class must know how to map data between back end application and FitNesse front end wiki page.

So far so good no major complains here, it worked great for us.

But I found this requirement to write the thin fixture adapter class for each new transaction a little annoying and have always toyed with the idea of building a generic Table/Fixture, one that will not require a developer to understand and be aware of the various fixtures coding conventions. In other words a fixture/table style where testers can write acceptance tests without needing development support of writing fixture specific code for each new transaction.

That became the main driving force behind the thought of developing a Generic Fixture where you just drop your class in FitNesse’s class path, write your test tables in wiki and be ready to test without having to write a single line of Java code. This idea is simple enough to understand but not so simple to implement because of the complexity of Java classes. Each class is different, it can have various type of constructors and methods (even overloaded ones). Each method can be returning different type of values (or not returning at all if method is void). We have to define some rules of defining class names, constructors, method names and their return types on wiki test tables first.

Continue reading

Download and Install Instructions

Install Requirements

You must have FitNesse framework installed on your computer and FitNesse server must be running on the computer where Generic Fixture is being installed.

To download Generic Fixture

Download the jar file genericfixture.jar containing full source code and compiled classes from Generic Fixture GitHub Site. Included classes have been generated using Sun’s JDK 1.5 Java compiler. Should you need to build Generic Fixture with any other JVM then make sure to put fitnesse.jar and fitlibrary.jar (provided in all the Fitnesse releases) in your CLASSPATH.
Continue reading