My First Xebium / FitNesse / Selenium Test

Yesterday, I was a bit quick in publishing my Installing FitNesse, Selenium and Xebium post. Although the post gets your testing environment up and running, it isn’t enough to be able to run your tests.

OK, sorry! I’ll make it to you guys up with this post! 🙂

If you’ve followed the installation instructions from the Xebium crew, that got Xebium running. However, running Xebium outside their demo environment means we have to copy many of their settings.

For starters, we’ll need to set the test system to Slim and add the Xebium JAR on our classpath, just like in the demo environment.

Project Xebium Classpath, which includes Xebium classes

There it is! The Xebium classes are on the classpath!

  • Start your FitNesse environment and open it in a browser
  • Edit the FrontPage, adding MyFirstSuite to the bottom of the page. Save the page.
  • Click the question mark ([?]) behind MyFirstSuite to create the suite page.
  • Add !path xebium-0.x.jar to the bottom of the suite page. This will add the Xebium JAR to the Java classpath.
  • Add !define TEST_SYSTEM {slim} underneath it. This will set the test system to Slim.
  • Save the page.

OK, now we need to instruct FitNesse to load the Xebium fixture.

  • Inside MyFirstSuite, click Add Child. Give the new page the name SetUp. Remove the suggested content. Leave the page type set to Default.

As MyFirstSuite already includes !contents, we can immediately see this new SetUp page. SetUp is a reserved word in FitNesse, SetUp pages get run before your test.

  • Open and edit SetUp. Add the following:
    | import |
    | com.xebia.incubator.xebium |

    | library |
    | selenium driver fixture |

    | script | selenium driver fixture |
    | start browser | firefox | on url | http://www.google.com |

OK, that concludes the settings. If you want to reuse these, don’t forget to change the URL on the last line of the SetUp page.

My First Test

Now lets make our first demo test. We’re going to set our tests up using Given When Then and abstract out any scenarios.

  • Create a new child page to MyFirstSuite, name it ScenarioLibrary. It should be of the type Default.
  • Add the following content to your new page:
    !1 Scenarios

    | scenario | Search for word | word |
    | Type | @word | in searchbox |
    | Click Google Search |

    !1 Steps

    | scenario | Open Google |
    | ensure | do | open | on | / |

    | scenario | Check word | word | present on page |
    | ensure | do | assertTextPresent | on | @word |

    | scenario | Type | word | in searchbox |
    | ensure | do | type | on | id=gbqfq | with | @word |

    | scenario | Click Google Search |
    | ensure | do | clickAndWait | on | id=gbqfba |

Note: The id values above are not constant, you may have to change them depending on which Google you’re redirected to.

Scenarios in ScenarioLibrary pages automatically get imported into any tests in the suite. This Scenario Library includes five scenarios, one of which is a high-level scenario and four of which are low-level steps. To learn more about this syntax, I suggest you look at the Xebium documentation, FitNesse UserGuide and Selenium Reference.

Next, we’re going to create our first test:

  • Create a new child page to MyFirstSuite, of the type Test, and name it MyFirstTest. Notice the two collapsable boxes for Scenario Libraries and SetUp.
  • Add the following test code:
    !*> Library

    !2 Given

    | scenario | Given Google is open |
    | Open Google |

    !2 When

    | scenario | When I search for the term Xebium |
    | Search for word | Xebium |

    !2 Then

    | scenario | Then the word Xebium is present on the page |
    | Check word | Xebium | present on page |

    *!

    ![ script
    Given Google is open
    When I search for the term Xebium
    Then the word Xebium is present on the page
    ]!

As the Given, When and Then statements are specific to the test, I define these on the test page, not on the scenario library. To keep the test page clean to look at, we define these statements in a collapsable box. More on how to properly sort, abstract and arrange your tests in my next post.

Finally, we need to close the browser at the end of the test.

  • Add a new child page to MyFirstSuite, name it TearDown.
  • Add the following content:
    | script |
    | stop browser |

TearDown pages automatically get run at the end of your test.

Finally, on MyFirstSuite, click Suite. Your tests should run nicely, searching for the word Xebium on Google and verifying that the word is present on the search results page!

The first successful test run using Xebium

Victory! My first Xebium / FitNesse / Selenium test run!

As promised, my next post will be about how to sort, abstract and arrange your scenarios and testing environment. For example, you will want to reuse your tests to work with different browsers and different environments (testing vs. acceptance), without copying all the tests! And how do you automatically save screenshots whenever a test fails? Till next time!