Business-Driven Test Automation (BDTA)

abstract This is a step-by-step guide to get started with Sahi Pro's Business-Driven Test Automation.
Read and follow along to get familiar with the workflow. For tutorial videos, refer here.

Introduction

Business-Driven Test Automation (BDTA) allows test automation to begin much earlier in the project lifecycle - right at the feature conceptualization stage. The application under test need not be ready to begin BDTA.

With BDTA you can do the following even before your feature or application is ready:
  1. Define the flow of the application in your business language like English, German, Dutch, Chinese (Traditional), etc. Lets say, we define the flow in English (Eg. Login, Add Books etc.). These are called Key Words.
  2. Add optional parameters to different steps as the test demands. (Eg. Login | Username:test | Password: |). These can be fine tuned/added/modified later when the application is ready.
  3. For data intensive tests, you can make the relevant steps data driven and create and populate the data input file.
  4. Organize your tests and scenarios in Suites.
  5. Tag the tests for logical separation and for better control on execution.
  6. Get these verified by peers and managers.
  7. Checkin into Version control
When the application is ready,
  1. Use Run/Record feature to record steps and "implement" the Key Words. The wizard lets you parametrize etc and create the necessary javascript/sahiscript function.
  2. Use Accessor Repository during recording itself or do it later to separate all object identification into a separate file for easier maintenance.
  3. Run and verify that your automation works fine.
With BDTA, most of the automation tasks have moved to before the feature is ready. Even if automation is not done, they can serve as good manual test cases since there is no code involved in them.

infoBDTA supports multiple business languages like English, German, Dutch, Chinese (Traditional), etc. since Sahi Pro version 10.0.0. Older versions support only English.

Create Scenario File

  1. Start Sahi Pro
  2. Open the Sahi Pro Editor and click New -> Scenario to create a new Scenario file.
  3. Save the scenario file.

Write a TestCase

  1. A scenario file has multiple blocks of testcases. To write a testcase, either edit the existing template or click on Insert testcase on top.
  2. Specify a testcase id, and the description of the test.
  3. Now start adding steps that need to be executed. These steps are business domain steps, like "Login", "Add Items to Cart" etc. Do NOT write browser interaction steps here.
    1. The Key Word column is where you can enter the Words or Phrases for every action of the business flow.
    2. The Argument columns are where you can define inputs for that action or step. We recommend specifying as key: value or if the value is right now not known, just key:. Arguments/paramaters can be added/adjusted/finetuned even later during recording.

    Below is an example of a shopping cart total verification as seen on http://sahitest.com/demo/training/login.htm
    The use case is: Login to the application, add books to cart, and verify that the cart total amount is correct. The example is the same as in Getting Started.
    info Note:
    • The Keywords are shown in red - indicating that these keywords have not been implemented as functions yet
    • If the Keyword's implementation already exists, the step will show in orange. CTRL-Click to bring up the Functions dialog and include that script.
    • Ensure the usage of unique keywords and follow a naming convention for your project.
    • Keywords are re-usable across TestCases and Scenario files. So ensure that you are separating out the workflow into logically reusable parts when defining keywords.

Implement using Run/Record

  1. Select the Test Scenario, right click on it and click on Run/Record.
    warning For recording scenario on Java Applications, add _launchJavaApplication in the scenario file.
  2. Enter the start URL and click Run/Record.
  3. A browser will launch and navigate to your start URL. It will execute any implemented steps and then stop at the first unimplemented step. A dialog pops up on the Controller asking to enter a script name. Enter the Script Name and click the Record icon to begin recording.
    info A script file is the library where the implementations of all the keywords will be saved. You could create one per module (say, AdminLib.sah or CustomerLib.sah).
    info Note:
    • Sahi will execute any keywords that are implemented.
    • It will stop at the first unimplemented step. Sahi can now record the implementation of that step.
    • For the first time, you will be prompted to enter a script file name. Click OK and enter a script file name.
    • From the second time onwards, the script name is remembered and picked. A dialog asks for confirmation of script name and keyword being recorded. Press OK to start recording. Alternatively, press Cancel to modify any parameters and then click Record button to start recording.
  4. Perform the steps on the website as needed. You can also add assertions as needed.
  5. Once done, Stop the recording by toggling the Record button
  6. Controller now takes you to the Create Fn tab. Here you see the details of the function getting created and all the steps recorded. You are also shown the list of all inputs you made and are given an option to parameterise these inputs as arguments to the function.
    • Select the inputs you want to use as arguments.
    • Click Save.
  7. Once you click save
    • If the next keyword in your scenario is implemented, it will continue the playback.
    • If the next keyword is not implemented, it will again prompt you to Record it. The keyword being recorded is shown along with the script file name. Press OK to continue to record. Alternatively, press Cancel to modify any parameters and then click Record.

    • You will now be prompted to record all unimplemented Key Words one-by-one. Continue the above process of record, parameterize and save.
  8. Once done, the recording browser closes and the scenario file refreshes in the Editor.
    • The scenario file now shows the keywords in black indicating they are implemented.
    • The script file you used to save the functions is 'included' in the scenario automatically.
    • All arguments you selected when saving the functions are shown against the respective steps in their rows.
    • The scenario file is automatically saved with these changes.

Run the TestCase or Scenario

  1. To execute this test case now, right click on the test case again, select Run/Record and select Run from the dropdown in the Run/Record menu button.
    The scenario executes by calling corresponding functions implemented for each step, using the argument values entered.

Reports

  1. The Run completes successfully. Check the logs. The log shows details of the scenario run as follows. Clicking on any line opens up to show the corresponding actions performed on browser.

Data Drive the TestCase

Once the testcase is implemented, you may decide to execute it repeatedly with varying input data. You can set up the testcase to pick up data from a separate data file and repeatedly execute with the provided data.

  1. Single Row Data Drive

    1. In your scenario file, select the Login Row, right click on it and select Data Drive. The Data Drive dialog opens.
      • Enter a Data File name and a label.
      • Select the Username and Password parameters to be included in the data file.
      • Click Save.
      Scenario file updated after Save.
      info A Data column gets added. If you selected a single row for Data Drive, you will see the [DataFile:label] on that row.
      info Regarding Data File creation:
      • The data file gets created automatically with provided name in the same directory as the scenario file.
      • The data file is created as a .csv file by default (recommended).
      • You can also create a .xlsx or .xls file by explicitly providing filename.extension when entering in the file name.
      • You may select an existing data file by using the browse button and selecting the file from file explorer.
  2. Multiple Rows Data Drive

    1. Now, Select Multiple rows (or the keyword cells of a bunch of rows) that contain one or more arguments defined.
      Select Add Books and Verify Cart Total rows > Right click and select Data Drive.
    2. The data drive dialog opens. Here, enter Data File name and Label.
      Data File Name - is entered the same as Single Row Data Drive.
      Label - Enter a new label name to save Book details. You can also select the column headers (parameters) you want to include in the data file from the list of all parameters.
      info Use checkboxes to select all or some parameters.
    3. Scenario file updated after Save.
      info Regarding Data File creation-
      • A Data column gets added (if not already present).
      • The data file name & label is shown against the group of rows you did Data Drive for [datafile:label] and you see [Repeat] and [End] labels on top & bottom of the group.
      • The scenario file is updated and saved automatically.
    4. Open and see the data file created. You can edit and add more data rows in your data file.
  3. Now execute the test case again.
    • Right click the test case name, select Run/Record.
    • In the Run/Record dialog > Select Run from the dropdown in the Run/Record menu button.
    • The scenario will execute with data picked from the data file, as many times as the number of data rows that exist in the respective [datafile:label].
  4. The Run completes successfully. Check the logs.
    • Each step's row is shown in Green when passed or in Red when failed.
    • The step repeats as many number of times as many data rows exist against the corresponding label in the data file.

Data Drive Using Database

  1. Store the data as 2D array in a variable using _getDB API.
    TestCaseDataKey WordArgument 1Argument 2
    $db=_getDB($jdbcDriver, $jdbcURL, "", "")
    $sql="SELECT * FROM BOOKSDATA"
    BooksData=$db.selectWithHeader($sql)
    info Here, BOOKSDATA is a table in the database, which has Java, Ruby, Python & Total columns.
  2. Use the variable as a data drive for the one or more keywords.
    TestCaseDataKey WordArgument 1Argument 2Argument 3
    [BooksData][Repeat]
    Add BooksJava : 1Ruby : 2Python : 3
    Verify TotalTotal : 1750
    [End]
    OR
    TestCaseDataKey WordArgument 1Argument 2Argument 3Argument 4
    [BooksData]Check TotalJava : 1Ruby : 2Python : 3Total : 1750

Tutorial Videos

  1. Define a TestCase



  2. Automate the TestCase



  3. Data Drive the TestCase