Robot Framework With Key Driven Approach Internally For Acceptance Test-Driven Development (ATDD) Using QTP

Robot Framework is a generic test automation framework for acceptance testing and Acceptance Test-Driven Development (ATDD). It has easy-to-use tabular test data syntax and utilizes the keyword-driven testing approach.

Keyword-driven testing, also known as table-driven testing or action word-based testing, is a software testing methodology suitable for both manual and automated testing. This method separates the documentation of test cases, including the data to be used, from the prescription of the way the test cases are executed. As a result it separates the test creation process into two distinct stages, a design and development stage and an execution stage.

Overview of Framework Architecture

Test-Driven-Development-1.jpg

Batch Manager: Component-written C#.NET class library takiing care of triggering the QTP, including collection of event logs after test completion and converting them into XML and pushing into a Sharepoint server and reports shown in the web browser using SSRS (SQL Server Reporting Services) for multiple users and the clients.

The reason it is implemented in this way is to ensure single component controls, both unit testing, regression testing and automation testing (including load and performance tests as written with CodedUI and DBFit for Data Base tests). The Reporting System with SSRS is well integrated with the SharePoint portal for daily test reports for all the tests above.

  1. Used to control the execution of regression tests as in the following:

    • Invokes HP QTP application
    • Opens a test in HP QTP
    • Associates function libraries and shared object repository
    • Runs the test
       
  2. Used to store test run information, test-specific reports and log files in the Reports DB

Configuration File: Generated automatically after completion of every build ready with TFS (Team Foundation Server). The rest of the key-driven approach is as below.

Pros

An advantage is that maintenance is low in the long run as in the following:

  1. Test cases are concise:
    • Test cases are readable for the stake holders
    • Test cases are easy to modify
    • New test cases can reuse existing keywords more easily
  2. Keywords are re-used across multiple test cases
  3. Not dependent on a specific tool or programming language
  4. Division of Labor:
    • Test case construction needs stronger domain expertise, fewer tools / programming skills
    • Keyword implementation requires stronger tool/programming skills, with relatively lower domain skill
  5. Abstraction of Layers

Cons

A disadvantage is:

  • Moderately high learning curve initially(*)

QTP Test Project Folder Structure

Test-Driven-Development-2.jpg

The key-driven approach need to be used
as in the following:

  1. Preparation test script in Excel or other supported documents or databases with test cases and detailed test steps.
  2. Create a new test project in QTP with only three actions as described below.

Action 1: Import the test cases from the Excel Sheet and store in the internal table format supported by QTP

Action 2: Execution of Test Cases with Test Case ID and every individual test case with detailed steps that calls the individual function library for better reusability and maintenance.

Action 3: Again Export the test results back to the Excel Sheet

 Implementation for the keywords is already a part of the tool. Examples include Selenium and QTP. Testers or test designers (who do not need to know how to program) that write test cases based on the keywords defined in the planning stage that have been implemented by the engineers. The test is executed using a driver that reads the keywords and executes the corresponding code.

Test Cases Sheet in Excel

Test-Driven-Development-3.jpg

Detail Test Steps sheet in Excel

Test-Driven-Development-4.jpg

Action 1: Import the test cases from the Excel Sheet and store in internal table format supported by QTP

'**Get my data from Excel Test Cases template***

'Add DataSheets

DataTable.AddSheet("dTestCases")

DataTable.AddSheet("dTestSteps")

'Call Test Management Function Library

Call TestManagement()

MainLogger("=====:: START Importing Excel Sheet  ::=====")

'Variable Allocation

strImportTestSheetFolder = strGetConfigValueOf("IMPORTTESTSHEETFOLDER")

DataTable.ImportSheet(strImportTestSheetFolder, "TestCases", "dTestCases")

DataTable.ImportSheet(strImportTestSheetFolder, "TestSteps", "dTestSteps")

On Error Resume Next

If Err.Number <> 0 Then

   MainLogger("=====::  Import Exceel Sheet Failed : Please Close the Excel Sheet and Run Agian :  ::=====" & Err.Number & "|" & Err.Description)

End If

On Error GoTo 0

'*End of  Emporting TestCases and TestSteps in Excel Sheets*********

  
Action 2: Execution of Test Cases with Test Case ID as mentioned in Excel sheets (TestCases and TestSteps) and every individual test case with detail steps calls the individual function library for better reusability and maintenance.

'Default TestCase Result

 strTCResult = "NORESULT"

 strTSResult = "NORESULT"

 'Get row count

 intTCRows = DataTable.GetSheet("dTestCases").GetRowCount

 intTSRows = DataTable.GetSheet("dTestSteps").GetRowCount

 '1st loop for each test case

 For i = 1 To intTCRows

     'For each row in the Test Cases sheet

     DataTable.GetSheet("dTestCases").SetCurrentRow(i)

     'This is used to set the focus on that row for that sheet

     If DataTable.Value("Execute", "dTestCases") = "Y" Then

         '2 nd loop for each test steps

         For j = 1 To intTSRows

             DataTable.GetSheet("dTestSteps").SetCurrentRow(j)

             'This is used to set the focus on that row for that sheet

             If DataTable.Value("TCID", "dTestCases") = DataTable.Value("TCID", "dTestSteps") Then

                 ''Main  Logic

                 Select Case DataTable.Value("Keyword", "dTestSteps")

                     Case "Test_OpenApplication"

                         strTSResult = OpenApplication(strOpenApplicationPath)

                         DataTable.value("Result", "dTestSteps") = strTSResult

                         DataTable.value("Result", "dTestCases") = strTSResult

                 End Select

             End If

         Next

     End If

   Next

End Sub
 
Action 3: Again export the test results back to the Excel Sheet
 

'****Export the Test Results ******

'ExportData- Action

MainLogger("=====:: End of the tests: Exporting the Test Results  ::=====")

strExportTestResultsPath = strGetConfigValueOf("EXPORTTESTSHEETFOLDER")

On Error Resume Next

DataTable.ExportSheet(strExportTestResultsPath, "dTestCases")

DataTable.ExportSheet(strExportTestResultsPath, "dTestSteps")

 

If Err.Number <> 0 Then

   MainLogger("=====::  Export the test result failed  : Please close the Excel Sheet and Run Agian :  ::=====" & Err.Number & "|" & Err.Description)

End If

On Error GoTo 0

'******End of exporting the Test Results ***************

 

(*) Excerpt from Wikipedia

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now