UFT automation framework

There are 3 automation framework approches in UFT.
  • Data driven
  • Keyword driven
  • Hybrid

Data driven automation framework

In Data driven framework, we have test script and data table with test data. This type of framework is suitable for projects where we have to test same functionality with different type of data. So we run same script but with different type of data. For example - we have to create a customer but with different title like Mr, Mrs, Dr etc

Keyword driven automation framework

In Keyword driven framework, we have test script, function (keyword) library and data table with test steps and test data. This type of framework is suitable for large project with hundreds of tests and various modules. Important components of keyword driven framework are mentioned below.
  • Main driver script - There can be 2 variations here.
    • With ALM integration - If you want to save the script in ALM, we will need simple driver script that will read the test case from the datatable and execute one step at a time. Each test is associated with library file, shared object repo and data table containing single test. We can run the tests from the ALM easily. Each test is saved as separate test in ALM. Since execution can be done in ALM, report is generated in ALM test lab. So no need of custom report.
    • Without ALM integration - When we do not need ALM integration, we can have main driver script which reads all tests stored in single excel. Here we have single script which will run all tests and custom report is generated in the form of HTML.
  • Library files - We can create reusable functions mapped to application functionality. e.g. Login, book ticket, create customer etc.
  • Datatable containing test cases and test data - We can use functions in library files to write test cases.
  • Reports - For UFT tests integrated with ALM, we can get the report from ALM. For UFT tests that are not integrated with ALM, we will need to create a custom HTML report.
  • Shared object repo - We can associate .tsr file with UFT script.
  • Environment variables
  • Recovery Scenarios - A framework may have few recovery scenarios.

Driver Script

Driver script performs below operations.
  • Read configuration data from environment variables
  • Import excel sheet into data table
  • Read steps from data table
  • For each test step, we have a function in function library that is called by driver script
  • Repeat above step until all test steps are executed.
  • In a framework where we are not integrating tests with ALM/QC, driver script is also responsible for generating the execution report in excel or html format.
Here is a sample driver script to run read test steps from datatable and run tests in UFT
 
'Load Environment Variables
Environment.Value("TestDirectory") = replace(Environment.Value("TestDir"),"ScriptsXYZ","")
tmpDataTbl = "testsheet"
tmpSheetLocation =  Environment.Value("TestDirectory")  & "Input DataTestCases.xls"

'Load sheet
DataTable.DeleteSheet(tmpDataTbl)
DataTable.AddSheet tmpDataTbl
DataTable.ImportSheet tmpSheetLocation, tmpDataTbl, tmpDataTbl

'loop through test steps in test sheet
intTotalRows = DataTable.GetSheet(tmpDataTbl).GetRowCount

For dtRows = 1 To intTotalRows

    'Read Test Case data
    strExecutionflag = trim(ucase(DataTable("Exec_Flag", tmpDataTbl)))
    strExecutionflag = Replace(strExecutionflag, Chr(13), "")
    strExecutionflag = Replace(strExecutionflag, Chr(10), "")
    temprows = dtRows
    strTestCaseID = DataTable("ID", tmpDataTbl)
    strTest_Case_Name = DataTable("Test_Case_Name", tmpDataTbl)
    strTest_Step_ID = DataTable("Test_ID", tmpDataTbl)
    strControlType = DataTable("ObjectTypes", tmpDataTbl)
    strControlName = DataTable("ObjectNames", tmpDataTbl)
    strControlValues = DataTable("ObjectValues", tmpDataTbl)
    StrScenarioName=DataTable("Test_Step_ID", tmpDataTbl)
    libFunction =  DataTable("Keyword", tmpDataTbl)
    strParameter1 =  DataTable("Parameter1", tmpDataTbl)

    'Execute library function - this is when UFT interacts with the application
    ret = Eval (libFunction)

    If (ret = False) OR (ret = "") Then
      Reporter.ReportEvent micPass, "test passed"
    Else
      Reporter.ReportEvent micFail, "test failed"
      'stop the run if test fails
      exit 
    End If

  DataTable.GetSheet(tmpDataTbl).SetNextRow  
Next

Integration with ALM

An excel will be attached to each UFT test in ALM. Or it can be placed in resources directory as well. Shared object repo (.tsr) and function library will be saved in resources directory in ALM. Before saving the test in ALM, make sure that test settings are updated accordingly.

Before running tests from ALM, make sure that ALM platform loaded is installed and Allow running UFT remotely from ALM settings is turned on in UFT.

Hybrid framework

Hybrid framework is the combination of Data driven and Keyword driven framework.

Web development and Automation testing

solutions delivered!!