22. February 2019
Comment créer un appel de procédure?
Procedures (also called function or subroutine) may be used in order to solve often (re-)occurring challenges. Like this, we may specify that certain successive actions are needed in order to solve a challenge (=programming a procedure). When we then encounter this challenge, we can simply call the procedure (and let the procedure solve this challenge for us).
How to insert a procedure-call within QF-Test
- Go to the point in your test-suite where you want to call a certain procedure.
- Insert a procedure call. In order to do so you may use the shortcut Ctrl+A or the menu Insert →Procedure nodes → procedure call.
- A dialog will pop up:
3.1 Click the button next to the label 'Procedure name'.
3.2 Another dialog will pop up. In this dialog choose the suite in which your procedure is located and select the wanted procedure in the tree.
3.3 After clicking on the OK-button the wanted procedure is specified in the 'Procedure name' textfield of the (first) pop up. If the procedure has some parameters, then these parameters are defined in the "Variable definition" table of the procedure-call.
- Depending on the exact challenge, you may need to change the predefined parameters in the "Variable definition" table or specify a text in the 'Variable for return value' textfield.
E.g. at a certain point in our test-suite, we want to get the current date in the format "year-month-day". In order to solve this challenge, we can use the procedure named qfs.utils.getDate which is already predefined in the standard library (suite: qfs.qft). So:
- Step 3.2: We need the procedure qfs.utils.getDate in the qfs.qft. So we select the tab qfs.qft and then the procedure qfs.utils.getDate in the tree.
- Step 4: By default this procedure is returning the current date in the format "day.month.year". Because we want to get the current date in the format "year-month-day" we replace the text "dd.MM.yyyy" in the "Variable definition" table by "yyyy-MM-dd" (see 'format' row).
- Step 4: We need to specify the name of the variable (e.g. currentDate) in which the current date should get saved. Therefore we simply specify currentDate in the 'Variable for return value' textfield.
- After executing this procedure call we can access the content of this variable (and thus the string describing the current date). This can be done via the syntax $(nameOfTheVariable) (e.g. $(currentDate)) in the attributes of the different nodes or via rc.lookup in scripts.
The complete procedure call is then looking like so:
- The qfs.qft is public. This means everyone is allowed to see, analyze and learn from the different procedures in this suite. (You can open this suite via QF-Test. It is located in the folder <path to the installation folder of qf-test>/qftest-$(version)/include/)
- It may also be a good idea to place suites with procedures you are use in multiple testing projects in an own, independent, directory. You can then tell QF-Test about this directory via the -libpath commandline parameter.