Passing Data in and out of Fitnium

185 views
Skip to first unread message

Keith Sterling

unread,
Jul 20, 2010, 4:25:00 AM7/20/10
to Fitnium
To everyone who has asked about passing data in and out of Fitnium,
attached is a working example.
This will be added to 2.0.2 and released shortly

This is based on the use of Fitnesse/SLiM Symbols
Any method in a fixture that can return a value can be assign to a
Symbol that the system remembers for the entire execution of the test.
To assign a value to a symbol your fixture method must return a value

In Fitnium we assign a value like this
| $V = | value of element | locator |
Any Fitnium API that returns a value can be used here.

In a Decision Table or Column Fixture you assign like this
| Column Fixture Name |
| some input | other input | output? |
| xxx | yyy | $V= |

In both these instances the value $V is retained for the duration of
the test.
We can now use the value in any Fixture and Fitnesse/SLiM will
automatically replace the value

This is the script for the entire page and shows an example of how to
create data, then call other fixtures that return data and use the
data later on in the same script

This is currently only based on SLiM, I'll be writing a Fitnesse one
shortly, but the concept is the same

-----------------------------------------------------------------------------------------------------------------------------------------------

!1 Passing Data Between Fixtures

Tell the world we are using SLiM
!define TEST_SYSTEM {slim}

Define our paths for Jars
!path fitnesse.jar
!path fitlibrary.jar
!path ./lib/*.jar

Import the Fitnium Fixture
|import|
|fitnesse.slim.test|
|fitnesse.fixtures|
|com.magneticreason.fitnium|
|com.magneticreason.fitnium.test|

Start the test by going to our basic start page
| script | Base Fitnium Fixture |
| the server is located at | localhost |
| the server is on port | 4444 |
| using the browser | *chrome | start at | localhost:8090/fitnium/ |
| check | is selenium initialised | true |
| set speed to |100| milliseconds |
| set timeout to |20000| milliseconds |
| write to debug | starting test |
| starting at URL| testpage1.html |
| wait for page to load for | 5 | seconds |
| check| title of current page | Magnetic Reason |

--------------------------------------------------------------------------------------

This sections expands on the Paramterising Tests page to provide more
details

We can define Fitnesse variables using th !define {} command, these
will then act as
substitutions in your scripts, the variable is replaced in your script
whereever it occurs

!define firstname {Keith}
!define surname {Sterling}

Fitnium variables are defined as !{name} and can be used as parameters
into your tests

!| script | Base Fitnium Fixture |
| set fitnium variable called | surname | with value | Sterling |

Finally you can also store values directly in the Selenium Javascript
environment, making them acessible
to Javascript commands in your scripts. However Selenium variables are
not accessible to Fitnium

Selenium variables are defined as !-${name}-! and are available to
Javascript inside Selenium
To use selenium variables you need to have started a browser

!| script | Base Fitnium Fixture |
| set selenium variable called | name | with value | Keith |

Now we can used our variable in our scripts instead of actual values

!| script | Base Fitnium Fixture |
| check | get fitnium variable called | surname | Sterling |
| enter | !-${name}-! | in input field | firstname |
| check | get selenium variable called | name | Keith |
| enter | !{surname} | in input field | surname |

Lets check the values of the fields we just put some data in
!| script | Base Fitnium Fixture |
| check| value of element | firstname | Keith |
| check| value of element | surname | Sterling |

As an alternative lets use the Fitnesse defines we created earlier
!| script | Base Fitnium Fixture |
| check| value of element | firstname | ${firstname}|
| check| value of element | surname | ${surname} |

Now lets create a Variable call '$V' and assign it the value of first
name
If it works, you'll see the value $V is populate with, shows as '<-
[Keith]'
!| script | Base Fitnium Fixture |
| $V= | value of element | firstname |

Now we have the value we can checks its value or use it else where
If it works, you'll see the value of $V shown as '->[Keith]'
!| script | Base Fitnium Fixture |
| check| value of element | firstname | $V |

Lets break out of the Fitnium script and pretend to call a Secure
login facility
This is via a DecisionTable in SLiM or a Column Fixture in Fitnesse.
It returns a secure token we can use somewhere else
| secure login |
| user name | password | secure token ? |
| ksterling | 54321 | $T= |

Alternatively we could use the value of $V previously set in out
Fitnium Fixture
| secure login |
| user name | password | secure token ? |
| $V | 54321 | $T= |

Jump back to our UI script and enter the secure token in the firstname
field.
!| script | Base Fitnium Fixture |
| enter | $T | in input field | token |
| check | value of element | token | $T |

--------------------------------------------------------------------------------------

Now the test is over, lets close the browser and clean up
| script | Base Fitnium Fixture |
| set selenium variable called | name | with value | keith |
| check | get selenium variable called | name | keith |
| close the browser |

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Code for the Secure Login Fixture

package com.magneticreason.fitnium.test;

/**
*
* @author keith
*/
public class SecureLogin {
private String userName;
private String password;

public void setUserName ( String name ) {
this.userName = name;
}

public void setPassword ( String word ) {
this.password = word;
}

public String secureToken () {
return String.valueOf( System.currentTimeMillis() );
}
}

Keith Sterling

unread,
Jul 20, 2010, 5:04:49 AM7/20/10
to Fitnium
Unfortunately I don't think its possible to pass data between fixtures
using Symbols in the old Fit Engine

Nothing seems to work, apart from Column Fixtures, and nothing on the
Web seems to suggest it will work in the Java version of Fitnesse

So this is probably the biggest reason/excuse to move to SLiM and the
solution is quite powerful and allows multiple fixtures on the same
page as well as passing data between them

This would therefore make integration with DBFit pretty easy which is
what I'm going to do next by way of a worked examples
Reply all
Reply to author
Forward
0 new messages