Integration Testing With Iridium
Integration Testing With Iridium
Learn how to write integration tests that validate complex widgets in a web application with the Iridium testing tool.
Join the DZone community and get the full member experience.Join For Free
Access over 20 APIs and mobile SDKs, up to 250k transactions free with no credit card required
If you are just getting started with Iridium, please read the article An Introduction to Iridium, an Open Source Selenium and Cucumber Testing Tool.
So far we have focused on using Iridium to create end to end tests that simulate the actions of a user as they navigate a web application. But Iridium can be used to run a more comprehensive set of tests against an individual element. For example, you may want to validate some complex widget on your site, like a search box.
Gherkin supports the notion of a scenario outline, which when used with an examples table, provides a way to rerun a scenario multiple times with different inputs. To demonstrate this we’ll create a test script that enters a number of different searches into the DZone search menu.
To run this example, right click, download and run this Web Start file. If you have not already done so, ensure that you have trusted the location where the Iridium JAR file is downloaded from using the instructions in the installation chapter of the getting started guide.
The first half of the test script is the same top to bottom execution of scenarios and steps that you have seen in other examples.
Feature: Open an application # This is where we give readable names to the xpaths, ids, classes, name attributes or # css selectors that this test will be interacting with. Scenario: Generate Page Object Given the alias mappings | SearchMenu | dropdownMenu2 | | SearchField | search | # Open up the web page Scenario: Launch App And I set the default wait time between steps to "2" And I open the application And I maximise the window And I click the element found by alias "SearchMenu"
Scenario outlines are a feature of the Gherkin language that allow you to rerun a scenario multiple times. You add steps to the scenario outline as you would for any other scenario, but at the end you’ll add a Examples table. The header element in this table defines the name of the row, which is referenced in the steps with the format <rowname>.
Scenario Outline: Test the search box And I clear the hidden element with the ID alias of "SearchField" And I populate the element found by alias "SearchField" with "<search>" Examples: | search | | Java | | Devops | | Linux | | Agile |
In our example, we clear and populate the search field with a selection of search queries. When the test is run, the scenario outline will be run once with each of the rows in the examples table.
On a side note, you'll notice that we used the step
And I clear the hidden element with the ID alias of "SearchField"
instead of using the simple selection of
And I clear the hidden element found by alias "SearchField"
This is because in this case the string "search" (which is what the alias SearchField references) is not specific enough to identify a single element on the page, so we use a step that specifically references the ID rather than finding elements with id, classes, names, xpaths, css selectors that may also match the string "search".
Scenario outlines are a powerful way to write test cases for small units of functionality in a web application, and when combined with the steps already defined as part of Iridium you can quickly write an integration test that ensures your web application is functioning as expected.
Published at DZone with permission of Matthew Casperson , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.