Friday, September 30, 2011

a selenesse trick

Selenesse is the mashup between Fitnesse and Selenium I helped work on some time ago.  I keep encountering this pattern in my selenesse tests, so I thought I'd share it...

Every once in a while a test needs some sort of persistent quasi-random bit of data.  In the example below I'm adding a new unique "location" and then checking that my new location appears selected in a selectbox.   This is also a neat trick for testing search, or anywhere else you need to add a bit of data to the system and then retrieve that exact bit of data from somewhere else in the system. 

| note | eval javascript inline FTW! |
| type; | location_name | javascript{RN='TestLocation' + Math.floor(Math.random()*9999999999);while (String(RN).length < 14) { RN= RN+'0';}} |
| note | instantiate a variable and assign the new value to it in a single line FTW! |
| $LOCATION= | getValue | location_name |
| note | click a thingie to add the new data to the system |
| click | location_submit_button ||
| waitForTextNotPresent | Adding ||
| note | check that the newly added data appears as the selected entry in a selectbox FTW! |
| check | getSelectedLabel | location_site_id | $LOCATION |

4 comments:

Great Britain Shop Information said...
This comment has been removed by a blog administrator.
Yogesh Kumar said...
This comment has been removed by a blog administrator.
alessandroprimerano said...
This comment has been removed by a blog administrator.
TestWithUs said...
This comment has been removed by a blog administrator.