Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Verifying Page Content and Styles With Iridium

DZone's Guide to

Verifying Page Content and Styles With Iridium

When simulating user behavior is not enough, Iridium provides you with the ability to verify the contents and style of your web applications.

· Web Dev Zone
Free Resource

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

If you are just getting started with Iridium, please read the article An Introduction to Iridium, an Open Source Selenium and Cucumber Testing Tool.

In all our examples so far we’ve made the assumption that having the fields and elements that a user needs to interact with present on the page indicates that the web application is working as expected. While this is a good test of the functionality of a web application, sometimes you do want to go deeper and verify that the visual contents of the page is correct.

Iridium provides the ability to verify the contents of a page with steps that can extract the value in attributes and text content of elements and then compare them to the expected result.

For this example, we’ll use a test script that works against the JBoss Ticket Monster demo. Ticket Monster is an open source project that showcases a number of different JBoss technologies, and is a good example of the kind of web applications that Iridium was designed to test.

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.

We’ll start with what should be familiar steps to assign human readable aliases to xpaths and css selectors, open a web page and click around in a simulation of the behaviour of a end user

Feature: Buy Concert Tickets on TicketMonster
 Scenario: Set alias mappings
   When I set the alias mappings
     | Venue Selection Drop Down List | venueSelector |
     | Order tickets Button | bookButton |
     | Section Selection Drop Down List | sectionSelect |
     | Adult Ticket Prices | #ticket-category-fieldset-5 > div > div > span |
     | Adult Ticket Count | tickets-1 |
     | Add tickets Button | add |
     | Email | email |
     | Checkout | submit |
     | First Ticket Number | //*[@id="content"]/div[2]/div[2]/div/table/tbody/tr[1]/td[1] |
     | Second Ticket Number | //*[@id="content"]/div[2]/div[2]/div/table/tbody/tr[2]/td[1] |
     | Created on | //*[@id="content"]/div[2]/div[1]/div/p[5] |
 Scenario: Open Application
   When I set the default wait time between steps to "2" seconds
   And I open the application
   And I wait "10" seconds for the element found by "logo" to be displayed

 Scenario: Open Events Page
   And I click the link with the text content of "Events"
   And I click the link with the text content of "Concert"
   And I click the link with the text content of "Rock concert of the decade"

Now we introduce some verification steps. First is a step that verifies that an element has the expected class. In our case, we expect a button to have the class btn-primary assigned to it.

 Scenario: Order tickets
   And I select "Sydney : Sydney Opera House" from the drop down list found by alias "Venue Selection Drop Down List"
   Then I verify that the element found by alias "Order tickets Button" should have a class of "btn-primary"
   And I click the element found by alias "Order tickets Button"

Now we want to verify the text content of an element. This is a two step process.

First, we need to save the content of an element against an alias. This is achieved with the step that starts with “And I save the text content...”

Second, we need to verify that the value assigned to an alias has the expected content. This is achieved with the step that starts with “Then I verify that the alias...”

In this example, we are verifying the contents of an element against a regular expression, which ensures that the text content is the at symbol followed by a price, which you can see in the screenshot below.

Screen Shot 2016-07-22 at 7.17.04 AM.png

 Scenario: Checkout
   And I select "S1 - Front left" from the drop down list found by alias "Section Selection Drop Down List"
   And I save the text content of the element found by alias "Adult Ticket Prices" to the alias "Adult Ticket Prices Value"
   Then I verify that the alias "Adult Ticket Prices Value" matches the regex "@ \$\d+\.\d{2}"
   And I populate the element found by alias "Adult Ticket Count" with "2"
   And I click the element found by alias "Add tickets Button"
   And I populate the element found by alias "Email" with "a@a.com"
   And I click the element found by alias "Checkout"

If you don’t need the power of a regular expression, Iridium also supports simple verifications, such as verifying that a string is a number. In this final scenario we save the content of some table cells and verify that they are indeed numbers.

 Scenario: Verify Checkout
   And I save the text content of the element found by alias "First Ticket Number" to the alias "First Ticket Number Value"
   And I save the text content of the element found by alias "Second Ticket Number" to the alias "Second Ticket Number Value"
   And I save the text content of the element found by alias "Created on" to the alias "Created on Value"
   And I dump the alias map to the console
   Then I verify that the alias "First Ticket Number Value" is a number
   Then I verify that the alias "Second Ticket Number Value" is a number
   Then I verify that the alias "Created on Value" matches the regex "Created on: \w+ \d+ \w+ \d+ at \d+:\d+"

Between the implied testing that is done as we navigate around an application and the explicit testing done with verification steps, Iridium test scripts provide you with a high degree of confidence that your web applications are functioning as expected.

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:
selenium ,cucumber ,test ,test automation

Published at DZone with permission of Matthew Casperson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}