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.

Posted in download, DSL, fitnesse, generic fixture, install, java, tdd, test driven development | Tagged , , , , , , , , , , , , , , | 4 Comments

Writing Advanced Generic Fixture Test Scripts (loops, conditions etc)

It’s been really long time since I wrote my last article on Generic Fixture and FitNesse. My projects kept me on my toes for most of the time but in between whatever time I got I was probably just too lethargic to shoot down a full post. However it doesn’t mean that I wasn’t developing and supporting Generic Fixture all this time. I made it a point to respond to each and every question that was asked in the comments section. I also gave ample hints on these features in few of my comments on my Blog.So as the title suggests we are going to cover advanced test scripting on this post which means loops, conditions, branches, expressions, exception handling etc. Let me make it clear at this point that I am not recommending using these features in each and every test story because it will only make test stories a bit harder to read and maintain. It is best to handle these things in a helper class and you should deal with helper class though Generic Fixture. Continue reading
Posted in fitnesse, generic fixture, java, tdd, test driven development | Tagged , , , , , , , , | 1 Comment

Testing a JMS server using Generic Fixture

Its been a while since I posted my last blog on Generic Fixture. In my previous posts I demonstrated how to make use of Generic Fixture to write automated web tests, database tests, testing EJBs etc. Let’s see how to use Generic Fixture for testing a JMS (Java Messaging Service) server. What we are going to write essentially is translation of Java based JMS client into FitNesse using Generic Fixture, which can be used to write acceptance tests to validate almost any type of Java application.

For our demonstration I will be using Apache’s ActiveMQ, the most popular cross platform JMS provider. It’s open source product so please go ahead and download it from ActiveMQ download page. Once downloaded just unzip the installer zip file and start running activemq process from inside activemq-install-dir/bin directory.

Continue reading

Posted in fitnesse, generic fixture, java, jms, tdd, test driven development | Tagged , , , , , , , | 1 Comment

Database testing using Generic Fixture

As I have mentioned in my Introduction to Generic Fixture post that we can use Generic Fixture to write acceptance tests to validate almost any type of Java application. In my previous posts I demonstrated how to make use of Generic Fixture to write automated web tests and testing EJBs. Let’s now see how to use Generic Fixture for writing queries against an Oracle database.

We shall keep the database connection parameters in a separate SetUp page as well as the connection closing code in a separate TearDown page. After that we shall write our query in main test page. That way we can utilize SetUp and TearDown pages in all of our test pages without repeating that code again and again in for each test.

I am assuming that your FitNesse server process is running on localhost on post 8000. If that is not the case then please change the URLs accordingly.

To test a database we shall need the database vendor supplied JDBC driver to be able to make JDBC calls. In this example since we are using Oracle we are going to need Oracle’s JDBC driver jar file. You can place your JDBC driver jar file anywhere on your system where FitNesse server is running and give the path in !path directive of FitNesse. Continue reading

Posted in database, fitnesse, generic fixture, java, oracle, tdd, test driven development | Tagged , , , , , , , , , | 11 Comments

Use of variables, arrays and complex types in Generic Fixture

Please visit Introducing FitNesse’s Generic Fixture for introductory details about Generic Fixture.Here we shall see how we can use variables in Generic Fixture.You can use a variable myVar in test tables like this to store return value of method1:
| myVar=method1 | arg1 | arg2 | | returnValue |
….
….
or You can use a variable “params” in a test table like this to store the SUT (System Under Test, which is a HashMap here) itself:
!| Generic Fixture | params=java.util.HashMap |
| put | curr_id | 128 |
| size | | 1 |
| toString | |

and later to use this variable myVar in an argument list use this syntax:
| method2 | myVar= | arg2 | | returnValue |
….
or to use this variable myVar in return value use this syntax:
| method3 | arg1 | | myVar= |
….
or You can even use this variable myVar to instantiate a new class, use this syntax:
!| Generic Fixture | myClass | myVar= |
….
Continue reading
Posted in fitnesse, generic fixture, java, tdd, test driven development | Tagged , , , , , , , | 44 Comments

Introducing DSL Adapter for Generic Fixture

DSL (Domain Specific Language) is used to define problems in a specific domain. DSL, off late has gained a lot of focus due to its readability and ease of use. It is much more expressive than general purpose programming language especially for test authors, business people and end users.

When I published my Generic Fixture, there was a very valid concern raised by some FitNesse users that since Generic Fixture lets testers write their tests without writing any Java code and exposes user’s class level details (such as constructors and methods) to testers it might not be very appealing to customer and business folks as it is to developers. That’s when I started dwelling into this issue. Initially I thought of providing a MS Excel macro that lets testers write their test in DSL and by running that macro it will produce class level tests suited for Generic Fixture. But I abandoned that macro idea because of my unfamiliarity with VB and also to avoid hassle of an extra step for testers. (what if testers are writing tests directly on Wiki page rather than MS Excel). Finally I decided upon providing a plug-in kind of extension to Generic Fixture that will let testers define their own high level customer centric language (DSL). This DSL adapter will contain information on how to map it to Java Class level details. They just have to define this mapping once for each domain and can make it part of the SetUp page to make it available to for all the test pages.

Continue reading

Posted in DSL, fitnesse, generic fixture, java, selenium, tdd, test driven development | Tagged , , , , , , , , , | 15 Comments

Testing EJBs using Generic Fixture

As I have mentioned in my Introduction to Generic Fixture post that we can use Generic Fixture to write acceptance tests to validate almost any type of Java application. In my previous post I demonstrated how to make use of Generic Fixture to write automated web tests. Let’s now see how to use Generic Fixture for testing an EJB (Enterprise Java Bean).

Here is a sample Java code of a typical EJB client. Any Java developer who has ever written code to call EJBs will be well aware of following Java code snippet.

Continue reading

Posted in fitnesse, generic fixture, java, tdd, test driven development | Tagged , , , , , , , , | 8 Comments