Wednesday, November 18, 2015

Your First Applitool Eyes Test Integrated in a .NET WebDriver Framework

Introduction

In this article we will talk about Applitool Eyes and how we can use this tool to integrate it in a WebDriver framework.
The following tools were used:
- Visual Studio 2013
- Selenium WebDriver with C#
- Nunit to run the tests
- An existing page object framework
- CI --> Jenkins

What is Applitools Eyes?

It is an automation testing tool that will check all visual aspects of the application from a given screen, meaning that we don't need to write separate tests for each UI element on the screen. The tool provides easy integration with different test tools and frameworks like Selenium, CodedUI, HP QC, etc. It allows testing the application on different browsers and resolutions. The logs that are generated after running the tests are very smart, include playback with step by step actions.
What you need: create an account. Once you are logged in, an API key will be generated for you. This will be used in your framework. Find the key by accessing menu My API key.



The tutorial from applitool site that you can read is this: https://eyes.applitools.com/app/tutorial.html.
The tool has a free limited version that will allow running 25 tests/week. You can find more about pricing here: https://applitools.com/pricing/.

Create your First Test

As described in the tutorial, in order to write your first test you need to add Eyes.Selenium package to your project. Go to your project --> References --> Right click on the project --> Manage NuGet Packages... -->Online -->search for Eyes.Selenium and Install it. The reference will be added to your project.



Then you can create your first test like this:



After you run your test for the first time it will be saved as a baseline. You need to run it again and open Applitools Eyes --> Test Results page to analyze the changes. If your test fails it means that there are wanted or unwanted changes in your application page. Depending on your analysis you can accept (if the change is not a bug) or keep the baseline = reject changes (if we have a bug in the application). For a failed test in the nunit test run window we will see a link to the test report providing the exception thrown by Eyes.Close() method. See image below that is taken from applitool site.



Include Applitool in an Existing Framework

We've seen above a brief description about how we can create our first webdriver + applitool test. But what if we want to have a suite of applitool tests and to include them in an existing framework?
We mentioned in previous posts about page object and a way of separating NUnits/MSTests from page object identification. Have a look on http://ralucasuditu-softwaretesting.blogspot.ro/2015/06/write-your-first-test-with-specflow-and.html because the idea is the same. 
- Create a project where 
  • you keep some Utils to deal with the driver, with the controls, to extend web driver if this is necessary, etc.
  • you keep the page object identification for every page, meaning that this is the place where you find your objects with selenium
- Create another project where
  • you define a Start test for SetUp/TearDown actions
  • you are writing your NUnit tests, without having any reference to webdriver elements
  • create an app.config in which you define what is the application url, login credentials, configuration on which you run your tests (browser). Below, you can see an example of app.config file used in our solution and also, the structure of the project













How to adapt this framework to run tests on applitool?
Open your Driver.cs class and:
  • Use Applitols as reference 
  • Create an Eyes field that is using your API Key

  • Initialize your driver with Applitool
  • To close your driver with Applitools you can use this

  • Driver.Initialize method is used in the Nunit SetUp (i.e. the sequence of code that will be executed before each test that, in our case, is defined in Start.cs class). Driver.Close is used in TearDown  (i.e. the sequence of code that will be executed after each test that, in our case, is defined also in Start.cs class). See an example below:



where GetUnitName is the name of the unit test that will be run and in this case, will also be the name of the Applitool test that will appear in Applitool UI --> Test Results page.




  • Now we are ready to write our tests


  • Check the test result on Applitool UI --> Test Results page.


  • Include your applitool in a CI system, like Jenkins. You can create a job that is running only nunit tests having category = "Applitool". See this link, chapter Specifying Test Categories to Include or Exclude, that shows you how to do this: http://www.nunit.org/index.php?p=consoleCommandLine&r=2.2
  • If a test fails, you will notice in jenkins the error 

I hope you enjoyed this article!
Happy testing and... make it green, becomes a dream :).

For every post I'll recommend something to read. The link for today is: Learning Selenium Testing Tools - Third Edition

Popular Posts