QTP / UFT

         This page covers the following topics:

Installing Applitools Eyes SDK for UFT

  • Download the latest SDK of Applitools Eyes for UFT from https://store.applitools.com/download/eyes.qtp and extract it into a folder of your choice.
  • Associate the Eyes.fql function library, located in the extracted folder with your test by navigating to File > Settings > Resources > +.

          If you want Eyes to be included in all tests, make sure to check the ‘Set As Default’ option.


Storing Eyes.qfl as a Quality Center resource

If you intend to store Eyes.qfl as a quality center resource, please follow the following steps:

  • Deploy the SDK dlls at the same path on all UFT machines or in a shared folder accessible by the same path from all machines.
  • In another QFL file that is associated with your tests define the constant EYES_PATH to point to that path.

    For example:


    const EYES_PATH = "\\Files\eyespath"

Using the Applitools Eyes SDK

' Make sure to include 'Eyes.qfl' via File -> Settings... -> Resources
' This is your api key, make sure you use it in all your tests.
eyes.ApiKey = "YOUR_API_KEY"

' Test setup - You should have 'Notepad' object in your objects repository
Set notepad = Window("Notepad")
eyes.SetBaselineInfoFromWindow(notepad)

' Start visual testing - Open eyes test
eyes.Open "Notepad", "QTP Notepad Test"

' Visual validation point #1
eyes.CheckObject notepad, "Yeah #1!"

notepad.WinEditor("Edit").Type "Testing notepad with Applitools Eyes!"

' Visual validation point #2
eyes.CheckObject notepad, "Yeah #2!"

' End visual testing. Validate visual correctness.
eyes.Close()

' Report
If Not eyesReport.IsPassed Then
    If eyesReport.IsNew Then
        Reporter.ReportEvent micFail, eyesReport.TestName, "New test inserted, See " & eyesReport.Url & " for details."
    else
        Reporter.ReportEvent micFail, eyesReport.TestName, "See " & eyesReport.Url & " for details."
    End If
End If


Eyes global variable

Eyes global variable is the main variable in Applitools Eyes SDK.



API Key

First, you should set the API key, which will allow you to communicate with the Applitools Eyes server. Note that you can set it once an eyes global object exists. In order to obtain your API Key, login to Applitools Eyes web application and open your account details page.

Example:

eyes.ApiKey = "MY_API_KEY"


Replace MY_API_KEY with your personal API key (it’ll appear it in your signup Email).


Baseline info

In order to let Applitools associate a test with the right basline, you should call on the right baseline one of the ‘SetBaselineInfo*’ methods.

  • If the AUT is a window call ‘SetBaselineInfoFromWindow’
  • If the AUT is a browser call ‘SetBaselineInfoFromBrowser’
  • If the AUT/DUT is a PerfectoMobile device * call ‘SetBaselineInfoFromDevice’

Otherwise, just use the explicit form and call SetBaselineInfo(topLevelObject, hostOS, hostApp)

Example:

eyes.SetBaselineInfoFromWindow(Window("WindowsObj")) 'Or
eyes.SetBaselineInfoFromBrowser(Browser("BrowserObj")) 'Or
eyes.SetBaselineInfoFromDevice(Device("DeviceObj")) 'Or
eyes.SetBaselineInfo(CustomGuiWindow("CustomAppObj"), "OS", "AppName")


WindowsObj The name of the window object in the Objects Repository.
BrowserObjThe name of the browser object in the Objects Repository.
DeviceObjThe name of PerfectoMobile device object in the Objects Repository.
CustomGuiWindowCustom call to get the custom app object from the Objects Repository.
AppObjThe name of the object in Objects Repository.
OSOS full name of the app/device under test.
AppName

The name of the app/device under test.

 

Initialization

The open method tells eyes that new test is about to start.

Example:

eyes.Open "AppName", "testName"


appName – is a string that represents the logical name of the AUT (this name will be presented in the test result itslef)

testName – is a string that represents the name of the test (this name will be presented in the test result)

Visual UI validation - Check Object

The check object command will take a snapshot of the current object area in the AUT and will perform a smart visual comparison of that area with the baseline. If this is a new object that didn’t exist in the baseline, this object will now be added to the baseline.

Example:

eyes.CheckObject object, "windowName"


object - The object that will be checked. Use Window("Notepad") for a full window, or one of the inner objects: Window("Notepad").WinEditor("Notepad"). 

windowName – a string that represents the logical name of the window/validation point that will appear in the test result report.

Visual UI validation - Check Object With Timeout

Behaves the same as CheckObject but allows the user to override the default timeout in specific application/test areas layouts which might take longer/less time to stabilize.

Example:

eyes.CheckObjectWithTimeout object, "windowName", timeout


object - The object that will be checked. Use Window("Notepad") for a full window, or one of the inner objects: Window("Notepad").WinEditor("Notepad"). 
windowName – string that represents the logical name of this window/validation point that will appear in the test result report.

timeout - The timeout for layout stabilization.


Ending a test

At the end of each test, make sure to call the eyes.close method to notify the service that the test was completed.

Example:

eyes.Close()



Reporting

After closing the test, it is a good practice to check the results and populate them further. Use the ‘eyesReport’ global object to check the results.

Example:

If Not eyesReport.IsPassed Then
    If eyesReport.IsNew Then
          Reporter.ReportEvent micFail, eyesReport.TestName, "New test inserted, See " & eyesReport.Url & " for details."
    else
          Reporter.ReportEvent micFail, eyesReport.TestName, "See " & eyesReport.Url & " for details."
    End If
End If


eyesReport.IsPassed - will receive a True value if the eyes visual test passed successfully. Otherwise, there are two main reasons that eyes can fail and return a False value: IsNew test is set to True (this is a new test) or simply, the test failed.

eyesReport.IsNew - When a test is initially introduced, it will fail because it has never been run before - IsNew will be set to true, therefore the test will be return as failed (as mentioned, IsPassed will be set to false).

Note: No action is required when a test fails after being run for the first time. Applitools Eyes automatically accepts it as the baseline. From this point onwards, this version will be used as the baseline.

eyesReport.TestName - The same testName that was given upon loading the test.

eyesReport.Url - Direct URL to test results page in the Applitools Eyes web console. Use this URL to see, analyze and accept results.


(Optional) Creating a batch of tests

The object BatchInfo represent a batch/collection of tests that will be unified as a single group in the Test Manager screen. As a result, the batch’s success or failure will be determined by the results of all the included tests. In order to start a batch, just call the eyes.setBatch method. In order to add additional tests to the same batch, make sure to call eyes.setBatch for each one of the tests in the batch. It’s also important to make sure you distribute a unique batch id between each test run but is shared by the different tests.

Example:

eyes.SetBatch runId, "batchName"


runId - This id distinguishes between the batches so it should be unique between the runs, thus enabling each batch to be grouped separately in the results page. This id should also be identical for all tests within a single run. Make sure to generate and distribute the id to all tests associated with the batch. batchName - This is the name of the batch that will be displayed in the results page.

(Optional) Enabling Logs

The logFile setter of the eyes variable enables logging for troubleshooting purposes. Note: Make sure the directory structure exists in order for the log file to be created.

eyes.LogFile = "c:/logs/applitools­eyes/eyes.log"


(Optional) Working with branches

Applitools Eyes includes built-­in support for branching, and allows creation of separate baselines per branch, so whenever a developer makes changes in the app, they can run their visual tests locally without affecting other branches, and only commit the baseline changes after making sure that the tests are passing properly. In order to create a branch, simply edit the value of eyes.BranchName before starting the test with the name of the branch as the parameter for this method. As a result, the subsequent tests will run as part of that branch and any baseline changes that you will perform on these tests via the web application will only be administered to this branch.

Example:

eyes.BranchName = branchName;


branchName - The name of the branch.

The initial baseline used in a branch is taken from its parent branch. You can specify the parent branch by setting ParentBranchName option with the parent branch name as a parameter. If you don’t specify a parent branch, the default branch will be used. Note that just like branching code; the baseline is copied from the parent branch only the first time it is accessed. Once the baseline is accessed in a branch, it is no longer affected by changes made in the parent branch.

Example:

eyes.ParentBranchName = parentBranchName;


parentBranchName – the name of the parent branch to inherit from .

When the developer is ready to commit the code changes that they have made to the app, they will need to also commit the baseline changes to the main branch to ensure the tests will keep passing. In order to push/commit the baseline changes of a private branch, Applitools Eyes exposes a web API that allows taking a baseline from a private branch and overwriting the baseline of the main branch with it.POST https://eyes.applitools.com/api/branches/overwrite In the request body you provide the object { "source": "≶name≷", "target" : "≶name≷" } which indicates the source and target branch names and causes the server to copy all baselines and models from the source branch to the target branch. It is recommended to add a hook to the source control client so that after every successful merge from the private branch to the main branch (or alternatively a "push" from the local repository to the main one), a web call will be made to the above API. This is a source control framework specific configuration and each framework has different APIs for accomplishing this. It is also recommended to configure your test framework, so the current branch name that the developer is working on and the parent branch name will be obtained automatically from the source control client when the test starts.