views:

1013

answers:

2

I'm new to integration testing, but have had great success so far buiding up a suite of tests using Se:IDE. As I've been running my tests, it has occurred to me that I'm generating a substantial amount of data and I'd like to clean up after myself.

Most of my tests involve creating a new 'page', and the id is available in the querystring. I'd like to have Se:IDE store a querystring value and pass it to another page that calls a delete method to tidy up after I have run my verifications.

I see that I can use the command storeLocation, but I'm not sure how I would go about parsing that value for the id in the querystring, and then pass it to another page using Open.

Have I reached the point where I need to migrate my tests to c#, or is this possible using the IDE?

+2  A: 

If you keep all your test cases inside the same test suite. They can share variables between executions without problems. So, all you have to do is to store the desired value:

storeLocation | variable | |

and in a future test, you have to use the variable as the following:

open | ${variable} | |

Note: for more info on test suites, take a look at: http://seleniumhq.org/docs/03%5Fselenium%5Fide.html#writing-a-test-suite

Update:

You can now use javascript regular expressions to get a substring from a variable:

storeEval | reg = /substring pattern/;reg.exec(${variable}) | substring
open | ${substring} | |

Example:

store | "012la4la" | a
storeEval | re = /[0-3]*la/;re.exec(${a}) | new
echo | ${new} |

output:

[info] echo: 012la
Santi
While that's very handy to know, I still have the issue of parsing the URL that is stored in ${variable} for the querystring value. Either I need a method which can return the querystring value, or some way to parse ${variable} with a regular expression.
Bayard Randel
Updated the post in case you needed to parse it using regexp
Santi
Santi's regular expression solution is somewhat more elegant than mine. Cheers Santi.
Dave Hunt
+1  A: 

A quick example for extracting an id parameter from a query string would be:

storeLocation | myLocation
store | javascript{ storedVars['myLocation'].substring(storedVars['myLocation'].indexOf('id=')+3, storedVars['myLocation'].length); } | idValue

This assumes that the id parameter is the last in the query string. If it's not then you might be best splitting the location on '&' and looping through the resulting array for the 'id' parameter value.

Dave Hunt
Do I run the javascript from the Value textbox?
Bayard Randel
Ah figured it out, I need to use storeEval to run javascript against the stored variable.
Bayard Randel