Our R2 release of Test Studio 2012 enables you to create data-driven find expressions! This is an uber-geeky feature which can help you build out very flexible, powerful tests.
There are a number of scenarios where you may find this useful; this post will show you one scenario for quickly validating the contents of the top menu in our Telerik demo application. In the image below you can see we’ve got three items, each identified by an ID, and each with some text content.
To build a data-driven locator, fire up the recorder, pick an element from the menu (#1 below), and add it to the project’s repository (# 2). Give it a good, clear name via the Friendly Name dialog! (#3)
Exit the recorder. Create a new test to hold your new validation, and move in to that test. Select the element you just added, and click the Step Suggestions icon (the nifty gear at the upper left of the Element Repository). Next, add in a text verification on the element.
You’ll need a data source to work with. You can work with an external source, or you can use a local data table. Either’s fine and both offer pros and cons for your workflow. (The external source can be easily updated by other folks, the local table is extraordinarily lightweight and goes with the test if you should move it to another project.)
Here’s a local data source:
Now let’s wire up the find logic! Select the menu element in the repository, and edit it.
You can fire up a live browser, but frankly in this case it’s a lot faster to simply select Find Without Connection. You won’t be validating the expression against a live page, so it doesn’t make sense to wait on a browser to start and connect.
At this point you’re in the Edit Element screen. Pull down the arrow by the filter item you want to bind to (ID, in this case. Top arrow.) Select the data item you want (Locator, here), then click the Set button (lower arrow).
You’ll get a warning about being unable to validate the element due to the data binding. That’s understandable, so click OK to dismiss.
If you had other tests referencing this element you’ll be asked which ones you want to update. (Pssst! It’s usually “All”!)
Now it’s off to the easy stuff: Binding the validation.Select your test step, then simply bind that as you would any other data driven step. Use the Content column in this case.
Make sure you click the Set button, otherwise your binding won’t be configured!
Now you can wrap this data driven validation into another test. Using your data driven test as a sub/child test in another ensures you’re iterating through only the sensible portion of your overall test.
Run the test and you’ll see green results! Our logging’s been enhanced to give you more information about each iteration and its values.
The beauty of this is you can easily extend your data table if new items are added to your menu, e.g.
This is just one simplistic scenario for using data bound find expressions.
We hope you’ll find this useful!
Subscribe to be the first to get our expert-written articles and tutorials for developers!