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.
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:
- 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.
- 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.
- For data intensive tests, you can make the relevant steps data driven and create and populate the data input file.
- Organize your tests and scenarios in Suites.
- Tag the tests for logical separation and for better control on execution.
- Get these verified by peers and managers.
- Checkin into Version control
- 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.
- Use Accessor Repository during recording itself or do it later to separate all object identification into a separate file for easier maintenance.
- Run and verify that your automation works fine.
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
- Start Sahi Pro
- Open the Sahi Pro Editor and click New -> Scenario to create a new Scenario file.
- Save the scenario file.
Write a TestCase
-
A scenario file has multiple blocks of testcases. To write a testcase, either edit the existing template or click on
Insert testcase
on top. - Specify a testcase id, and the description of the test.
- 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.
- The
Key Word
column is where you can enter the Words or Phrases for every action of the business flow. - The
Argument
columns are where you can define inputs for that action or step. We recommend specifying askey: value
or if the value is right now not known, justkey:
. 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.
- The
Implement using Run/Record
- 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. - Enter the start URL and click
Run/Record
. - 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.
- Perform the steps on the website as needed. You can also add assertions as needed.
- Once done, Stop the recording by toggling the Record button
- 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.
- 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.
- 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
- To execute this test case now, right click on the test case again, select
Run/Record
and selectRun
from the dropdown in theRun/Record
menu button.
The scenario executes by calling corresponding functions implemented for each step, using the argument values entered.
Reports
- 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.- Single Row Data Drive
- 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
andPassword
parameters to be included in the data file. - Click
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.
- In your scenario file, select the Login Row, right click on it and select
- Multiple Rows Data Drive
- 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 selectData Drive
. - 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. - 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.
- Open and see the data file created. You can edit and add more data rows in your data file.
- Now, Select Multiple rows (or the keyword cells of a bunch of rows) that contain one or more arguments defined.
- Now execute the test case again.
- Right click the test case name, select
Run/Record
. - In the
Run/Record
dialog > SelectRun
from the dropdown in theRun/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]
.
- Right click the test case name, select
- 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
- Store the data as 2D array in a variable using
_getDB
API.TestCase Data Key Word Argument 1 Argument 2 $db= _getDB($jdbcDriver, $jdbcURL, "", "") $sql= "SELECT * FROM BOOKSDATA" BooksData= $db.selectWithHeader($sql) info Here,BOOKSDATA
is a table in the database, which hasJava
,Ruby
,Python
&Total
columns. -
Use the variable as a data drive for the one or more keywords.
TestCase Data Key Word Argument 1 Argument 2 Argument 3 [BooksData] [Repeat] Add Books Java : 1 Ruby : 2 Python : 3 Verify Total Total : 1750 [End] TestCase Data Key Word Argument 1 Argument 2 Argument 3 Argument 4 [BooksData] Check Total Java : 1 Ruby : 2 Python : 3 Total : 1750
Tutorial Videos
- Define a TestCase
- Automate the TestCase
- Data Drive the TestCase