Technology Highlight: Focus on What We Do Best Product Roadmap: Automated Testing Part 2 of 3

Posted on by

office-594132_640As we outlined in our last technology highlight, automated testing is an essential part of our product development lifecycle.

We ended last week’s discussion with assertions within Watir WebDriver. Each check or verification that a test completes is called an assertion. These assertions allow the Automation Engineers the ability to verify that interactions with the browser produce the correct results (i.e., the webpage has the correct information in the correct place). Ensuring something is on the screen in the correct place is called a positive assertion, while ensuring something is not on the screen is called a negative assertion.

One-Time Use PIN Authentication

Let’s continue with the one-time use PIN example from last week. Once we retrieve the one-time use PIN and enter it into the correct text area, we look for a confirmation message that the PIN was accepted: “Your One-Time Use PIN Has Been Accepted.”

Then, using our browser, we look for an HTML element called a div that contains a specific identifier. We tell Watir that if the PIN is correct and has been accepted, that it should have a value of “Congratulations!” inside of it.
browser.div(:id, “pin_success”).should have_text(“Congratulations!”)

If this assertion returns as true we know the browser successfully sent the PIN to the server, validated it, and returned the correct response. To take the test a step further and ensure that all of the information provided in the “pin_success” div is correct, we next look inside the div for an HTML element called a span.

browser.div(:id, “pin_success”).should have_tag(“span”, :text, “Your One-Time Use PIN Has Been Accepted”)

If this assertion returns true we know that the expected text is the actual value of that span inside the expected div. We could even take this test a step further and verify that the color of the text, the font family, or other attributes were correct.

In order to ensure an error did not appear on the screen we use a negative assertion to verify certain text is not on the screen. For example, if we want to check the screen to guarantee the word “Oops!” is not anywhere on it we could simply write the following code:
browser.should_not have_text(“Oops!”)

This verifies that “Oops!” was not in the HTML that was sent to the client’s browser. However, if it is OK for “Oops!” to be found on the screen, provided it is not in the div “pin_success”, this statement will not give the desired result. Instead, we must use this code:

browser.div(:id, “pin_success”).should_not have_text(“Oops!”)

This checks whether “Oops!” is present on the screen within the div of the success message. We utilize all varieties of positive and negative assertions to validate that the user interface of the web-portals is working as expected and displaying the correct web pages to the end user. Without the ability to perform these types of assertions on the user interface, our automated tests would be limited to verifying information directly in the database or querying for information through our eCore® API.

Stay Tuned

As you can see, Watir is a very powerful and elegant tool. In our next post we will talk about how we utilize other Ruby plugins (called gems) to further expand our abilities to test our web-portals with Watir.

 

 

 

This entry was posted in software development, Technology and tagged , , .