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.
- 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!
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!
6 comments
Thanks so much! This is exactly what I needed!
Mark Geiger
No problem, do come back for more! 😉
Rogier van het Schip
Hi Rogier.
I’ve been running a test case in both Selenium IDE and have now exported it to Xebium. I get a timeout Error in xebium but not Selenium IDE.
What’s the reason?
Assertions: 25 right, 1 wrong, 0 ignored, 1 exceptions (27.912 seconds)
scriptTable_2_8
__EXCEPTION__:com.thoughtworks.selenium.SeleniumException: null (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 79 milliseconds
Build info: version: ‘unknown’, revision: ‘unknown’, time: ‘unknown’
System info: os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘2.6.32-38-generic’, java.version: ‘1.6.0_20’
Driver info: driver.version: RemoteWebDriver
Aditya
Hi Aditya,
Sorry, I can’t tell from just the information you’ve sent me, there is no extra information attached to the exception and I don’t know what the test does. A way to approach this problem is to create an empty test without the timeout error and gradually copy the faulty test into the new test, line by line, running the new test after each line, until you can isolate the line that’s causing the timeout.
Also, one question: What do you mean by ‘running a test case in BOTH Selenium IDE’?
– Rogier
Rogier van het Schip
Sorry added BOTH by mistake.
My first error occurs on two javascript store Element and StoreEval Expressions. Does Xebium throw an error on javascript ?
Here it is :
| $Present= | is | storeElementPresent | on | id=id_0-Extension |
| $choose= | is | storeEval | on | storedVars[‘Present’]==true?”id_0-Extension”:”class=addfield” |
| ensure | do | click | on | $choose |
Aditya
I would say this is a Selenium error, given that you receive a SeleniumException, but I’m not sure what Xebium sends to Selenium about your javascript. I can understand what you’re trying to do from the code, though. What does your output log say about these lines? Did this code work in Selenium?
One other thought: Shouldn’t the second line be
| $choose= | is | storeEval | on | storedVars['Present']==true?”id=id_0-Extension”:”class=addfield” |
What you could also do is take this to the Xebium developers, at their Google Group.
Interesting to know, by the way, is why FitNesse never included if, for or while constructs: Acceptance tests (FitNesse’s target) describe the behaviour of the system in a certain case, there shouldn’t be multiple paths in this behaviour. If there are, you could say they’re multiple tests. Or, as Gojko puts it: “Acceptance tests (in this case FitNesse pages) should describe the specification of what the software should do (or does in regression test), not how it the test is performed.“
Rogier van het Schip