Code Construction for the Business Rules Test

This section explains how the scripts are built for implementing the CSDDT only. It does not cover scripts for building a GUI or properties test. For more information refer to the scripting examples set forth in Chapter 8. The test script components we employ include

  • Shell script

  • Main script/procedure

  • Window selection script/procedure

  • Tab selection script/procedure

  • Action selection script/procedure

  • Error detection script/procedure

  • Other supporting functions and include files

The Shell Script

The optional shell script is usually used to set up input conditions for the Main script, such as calling scripts that would initialize a database prior to testing or other setup-type functions. The shell script is also the location to prompt the tester for the name and path of the input file to be processed. This allows the test script to process multiple test scenarios one at a time as specified by the tester at runtime. The acquisition of the input file to be processed can be handled any number of ways depending on the tool you are using. The Main script in the next section invokes the windows file browser to acquire the input text file.

The Main Script

The Main script or procedure is kept in a script file named DDMain and is used to

1.
Open and read data from the input data file

2.
Control the primary processing loop

3.
Examine the control fields

4.
Call the appropriate procedures and functions that perform the various processes, procedures such as:

a. Selecting the window (window selection procedure is kept in a script file named DDWindow_Select)

b. Selecting the tab or subwindow (tab selection procedure is kept in a script file named DDTab_Select)

c. Performing the specified actions (perform action procedure is kept in a script file named DDPerform_Action)

d. Testing for the expected result (error handling procedure for detecting expected errors is kept in a script file named DDProcess_Error)

The Main procedure process has the following steps:

Acquire the path and filename of the input file to be read.

Open the file.

Enter the primary processing loop.

Read the first seven fields of the data record.

The Rec_Type code is examined first to determine if it is a normal or special record. If it is a special record, perform the special processing

Otherwise

Perform normal input processing as follows.

(The next section describes the program flow from this point.)

Read the remaining data fields into an internal string array, named DFld()

If necessary…

Call the DDWindow_Select procedure

If necessary…

Call the DDTab_Select procedure

If necessary…

Call the DDProcess_Error procedure

Return to the beginning of the loop and read the next record. If there are no more records to read, then DDMain is finished.

After the Data Are Read

The next step is to select the window that is specified in WinCd (window code) by calling the DDWindow_Select procedure. The WinCd value is made available to this procedure. Once the window has been selected and validated by the window selection procedure, the DDTab_Select procedure is called. It uses the TabCd (tab code), much like the window selection procedure used the WinCd, to select a targeted tab on the window. Realize that not all windows have tabs; therefore, the tab code is not used in all records. When there is no tab code, this procedure is simply skipped. The Main procedure should keep track of what window and/or tab is open so that, when the next record is read, if the window and/or tab called for are the same as the previous ones, a new selection is not necessary.

Now that the test script has navigated to the targeted window/tab, it is ready to perform an action against that window. Just as you would have had to create your own window and tab codes, you will need to create your own action codes. This will depend upon what actions can be performed on the window. Usually there are limited sets of actions that can be performed, such as inputting text; selecting check boxes, radio buttons, or items in drop-down lists (DDLs); or selecting items in a grid. Selecting these GUI objects should not be considered the actions, but rather the data inputs that translate into object selections. Actions are what occur either prior to or after the data input is performed. Using a simple example, the script might perform the data input and then execute a command, like clicking on the OK button, a Save button, or even the Cancel button. Design this script segment so that it inputs data to all controls (using null values for those that do not require any interaction) and then perform the final action such as clicking on the OK button.

Now that the action has been performed, the script has to determine if it should look for a normal response or an error response from the application. It must have previously determined if an error condition is expected (because the tester intentionally used bad input data to force an error). To do this, while still in the Perform_Action procedure, it preexamines the value of the ErrCd (error code).

If the error code is blank (null) or is equal to “none,” then it should continue processing as if it expected a normal response from the application. Looking for an indicator that the normal action occurred is dependent upon the AUT. The script might receive an indicator (for example, a status bar message) that a Save operation completed normally, or normal completion might be indicated by the fact that a window closed and a new record was added to a grid. It may also be something as benign as nothing happening. If no error message was displayed, then the action completed normally. Whatever happens, it must script the existence of that indicator. If nothing happens, then there is nothing to script. The test error will occur when you expect nothing to happen, and you get an error message instead. In Rational Robot, an unexpected error window is detected and the script can then be set up to cause the test to fail (you just caught a bug!). If the action performed completes normally, then the Perform_Action procedure returns to the Main procedure.

Now, if the error code is not blank or not equal to “none” then the script is expecting an error to occur. At this point the Perform_Action procedure returns to the Main procedure.

After returning to the Main procedure, the ErrCd (error code) is examined once again by the Main procedure. If the error code is not blank or not equal to “none” then the Process_Error procedure is called; otherwise, Main is finished processing this record, and it returns to the beginning of the loop and the next record is read and processed.

In the Process_Error procedure, the code is used to select a code segment that will check and verify the existence of the predetermined error indication. This may be a message box displaying the error text or some other indication that the AUT uses to show the user that an error has occurred. Once the error processing is finished, it returns to Main. Main then returns to the beginning of the loop and the next record is read and processed.

Each of the four procedures other than Main is designed in precisely the same manner. The design objective here is to keep it simple!

The code for the Main procedure template file follows.

Note: The apostrophe in the scripts is used for comment fields except where '$ is used for compiler directives.

'$Include: "Global.sbh"       'storage for global variables
'$Include: "DataDriven.sbh"   'storage for global variables specific to the Data-Driven
 procedures

    Declare Function ReadFields BasicLib "Global" (File_Num, Fld_Cnt, GFlds())
    Declare Function Key_Word_Sub  BasicLib "DDKeyWord_Sub" (Fld_Cnt)

    Dim Rec_Type                      'Record Type
    Dim Fld_Cnt                       'Data Field count
    Dim Comment As String
    Dim Child_Open As String
    Dim record_counter

Option Compare text                  'allows LIKE to be case insensitive
Sub Main                             'program starts here
    Dim Result As Integer
    On Error GoTo Error_Handler1
    Child_Open="No"
    current_win=""
    current_tab=""
    record_counter=0

'other ways to initialize the InfileName variable
  'InFileName="c:sqatemplates	estdata	estdata1.txt"
  'InFileName=InputBox$("Enter the name of the input file to process.","Data Driven
 testing",InFileName)

    CallScript "OpenFile_txt" 'open a text file for test input data this script opens a
 file browser window
    InFileName=txt_filename 'from the openfile_txt routine

    If InFileName="" then
        Exit Sub     'the test is canceled no filename was supplied
    End if
    Open InFileName For Input As #1
    Do while Not EOF(1)   'Main process loop. Read and Process input records until there
 are none left.
'''''''''''''''''''''''''''''
'read input test data file
'''''''''''''''''''''''''''''
        Input #1,Rec_Type,WinCd,TabCd,ActCd,ErrCd,Fld_Cnt,Comment
        if Fld_Cnt<> 0 then

            ReDim DFld(Fld_Cnt) 'set the appropriate size of the array for the number of
                                'data fields in this record

            Result=ReadFields(1, Fld_Cnt, DFld())   'pass file number, fld_cnt, address of
 DFld
            if Result=0 then
                MsgBox "ReadFields function failed. Program terminating"
                Close #1  'close the open file
                Exit Sub
            end if
        end if

''''''''''''''''''''''''''''''''''''''''
'log which record we are processing
''''''''''''''''''''''''''''''''''''''''

        record_counter=record_counter+1
        SQALogMessage sqaPass, "last record read ="&Cstr(record_counter), ""

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Determine the record type
'
' H=header record, skip this do not process
' B=Breakpoint stop for program debugging
' X=Terminate prior to the end of the input data file
' G=Good record. Process normally
' K=Good record. Pre-Process for Keyword substitution,
'   then process normally
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
        if Rec_Type LIKE "H" then
            goto NoProcess
        elseif Rec_Type LIKE "B" then
            stop            'data breakpoint
        elseif Rec_Type LIKE "X" then 'terminate the program
            Close #1
            Exit Sub
        elseif Rec_Type LIKE "G" then
            Goto Start                  'good record
        elseif Rec_Type LIKE "K" then
            key_word_sub(Fld_Cnt)      'this call is used when keywords are used in the
 data such as 'AutoDate"
        else
            MsgBox "The record type is invalid. The program is terminating"
            Close #1
            Exit Sub
        end if

Start:             'this is a label
'''''''''''''''''''''''''''''''''''''''''''''''''
'Determine if we need to open a new window or not
'''''''''''''''''''''''''''''''''''''''''''''''''
        if Child_Open="No" then
            'Result = Window_Select(WinCd) 'go open the selected window. This is executed
 at first pass only.
            CallScript "DDWindow_Select"
            if Gen_Return_Code=0 then
            'if Result=0 then
                close #1
                exit sub
            end if

            Current_Win=WinCd   'update and save the current window selection
            Child_Open="Yes"    'we have now opened a window
        else
            if Current_Win<>WinCd then
                CallScript "DDWindow_Select"
                if Gen_Return_Code=0 then
                    close #1
                    exit sub
                end if
                Current_Win=WinCd   'update and save the current window selection
                Child_Open="Yes"    'we have now opened a window
            end if
        end if

'tab select
'''''''''''''''''''''''''''''''''''''''''''''''''
'Determine if we need to open a new tab or not
'''''''''''''''''''''''''''''''''''''''''''''''''
            if TabCd <> "" and TabCd <> "none" and TabCd <> "TabCd" and Current_Tab<>TabCd
 then
                CallScript "DDTab_Select"
                if Gen_Return_Code=0 then
                    close #1
                    exit sub
                end if
                Current_Tab=TabCd
            end if

'''''''''''''''''''''''''''''''''''''''
'Perform the specified Action
'''''''''''''''''''''''''''''''''''''''
        CallScript "DDPerform_Action"
        if Gen_Return_Code=0 then
           MsgBox "Specified Action Could Not be Performed"
           close #1
           exit sub
        end if

'''''''''''''''''''''''''''''''''''''''
'Process the Error Code
'''''''''''''''''''''''''''''''''''''''
        if ErrCd="" or ErrCd="none" or ErrCd="ErrCd" then 'Error is not expected
            goto NoProcess
        else
            CallScript "DDProcess_Error"
            if Gen_Return_Code=0 then
               MsgBox "Specified Error Processing Could Not be Performed"
               close #1
               exit sub
            end if
        end if

NoProcess:       'this is a label
    Loop 'end of main loop

    'End of File has been reached, close any open child window
    Exit Sub

Error_Handler1:
    MsgBox "Error number "&Cstr(Err)& " occurred at line: "&Erl &" -- "&Error$
    Exit Sub
End Sub
--------------------------------------------------------------------------------------------

Window Select and Tab Select Procedures

This is the actual code for the Window_Select template script with some example placeholder information.

'$Include: "DataDriven.sbh"
Declare Function Window_Select(WinCd)
Sub Main
    Gen_Return_Code = Window_Select(WinCd)
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Window_Select(WinCd)
Window_Select=1
Select Case WinCd
    Case "w1"
        msgbox "w1 selected"
    Case "w2"
        msgbox "w2 selected"
    Case "w3"
        msgbox "w3 selected"
    Case Else
        Msgbox "Window Select not found for WinCd: "&Cstr(WinCd)&" Terminating"
        Window_Select=0  ''return value FAIL
        SQALogMessage sqaFail, "Window Select not found for: "&Cstr(WinCd)&"", ""
    End Select
End Function

The line from the front of the file:

'$Include: "DataDriven.sbh"

tells the compiler to include or use variables defined in the Header file named datadriven.sbh below.

The following takes this piece of code that was originally written in Rational Robot's SQABasic and modifies it slightly for discussion purposes. Let's assume for example that it will be coded to select one of three windows—the User Preference window, the Options window, and the Customer Information window. We would have decided to use the window selection codes of

User_Preference

Options

Customer_Info

These window selection codes would then be utilized in the input data file and in the Select Case statement as indicated here.

'$Include: "DataDriven.sbh"
Declare Function Window_Select(WinCd)
Sub Main
    Gen_Return_Code = Window_Select(WinCd)
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Window_Select(WinCd)
Window_Select=1    'this is the return code for this function indicating success. It is
 preset here
                   'below in the case else statement it is changed to indicate an error
 because the WinCd
                   'could not be found.

Select Case WinCd

    Case "User_Preferences"
        Record here, performing the actions necessary to select the User_Pref window
        It is very important to insert code here that verifies that the window opens and
 is in the expected state.
        The test fails here if the window does not open as expected.

    Case "Options"
        Record here, performing the actions necessary to select the Options window
        It is very important to insert code here that verifies that the window opens and
 is in the expected state.
        The test fails here if the window does not open as expected.

    Case "Customer_Info"
        Record here, performing the actions necessary to select the Customer Information
 window
        It is very important to insert code here that verifies that the window opens and
 is in the expected state.
        The test fails here if the window does not open as expected.

    Case ... add additional cases as needed.

    Case Else
        Msgbox "Window Select not found for WinCd: "&Cstr(WinCd)&" Terminating"
        Window_Select=0  ''return value FAIL
        SQALogMessage sqaFail, "Window Select not found for: "&Cstr(WinCd)&"", ""
    End Select
End Function

Verifying that the selection took place properly is very important here. When using Rational Robot, always insert a window existence verification point at the end of the selection code. For other test tool environments, develop similar window verification tests using the capabilities unique to your tool of choice.

If the window is present and in the proper state (enabled, maximized, etc.) and ready to accept an action, then this section of the test passes, else a test case failure occurs, which should terminate the test.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.33.87