Keyword-driven Testing does not only consist in possibilities that are provided by TestComplete. In a wider sense, Keyword-driven testing is such an approach to testing: when we are creating our own keywords, and in the result, tests creation is nothing short of evoking these keywords. Ideally, tests are created as tables, where each line stands for one test action (call of the keywords with parameters). Apart from the tables, we also have the code written with the help of the programming language and the driver (a class, function or several functions) used, which read keywords from the tables and call the corresponding code from the project.
Schematically, the simplified Keyword-driven approach will appear as follows:
The major advantage of the approach consists in the fact that the code of the scripts and the driver are written and maintained by programmers, while the tests can be created by anyone, including those who are not well-cognizant in programming (that is, testers, product specialists, or customers).
In this recipe we will take up a simple example of creating our own Keyword-driven Tests, for consideration. As a tested application, we will use a standard Notepad application.
We will create three components for our keyword-driven framework:
Also, for our example, it is necessary to create the C:somefile.txt
file with any contents.
First and foremost, we will create a function to work with the Notepad:
startNotepad
will launch the Notepad and open the file that was passed as a fileName
parameter:function startNotepad(fileName) { if(fileName == undefined) { fileName = ""; } Win32API.WinExec("notepad.exe " + fileName, SW_SHOWNORMAL) }
closeNotepad
function closes all the open copies of the Notepad:function closeNotepad() { while(Sys.WaitProcess("notepad", 500).Exists) { Sys.Process("notepad").Terminate(); } }
checkNotepadFileName
function checks if the correct file has been opened:function checkNotepadFileName(expectedName) { var np = Sys.Process("notepad").Window("Notepad"); aqObject.CompareProperty(np.WndCaption, cmpStartsWith, expectedName); }
OPEN
, CLOSE,
and CHECK
keys (as they correspond to the operations, which are to be executed in the test: open the Notepad, check if the correct file has been opened, and then close the Notepad). The keywords OPEN
and CHECK
will also have their parameters.function driver(fileName, table) { var steps = DDT.ExcelDriver(fileName, table); while(!steps.EOF()) { var stepNum = steps.Value("Step"); var action = steps.Value("Action"); var param = steps.Value("Param1"); switch(action) { case "OPEN": startNotepad(param); break; case "CHECK": checkNotepadFileName(param); break; case "CLOSE": closeNotepad(); break; default: Log.Error("Unknown action: " + action); } steps.Next(); } }
driver("C:\notepad.xls", "Sheet1");
C:somefile.txt
file.The driver calls the functions that correspond to each keyword, which is encountered in the test. Fine-tooth-combing of the file is made possible with the help of the DDT driver, provided by TestComplete.
The tests themselves are separated from the code, that is working with the tested application, this is why they are easy to comprehend even for a person who is not learned in programming (quite naturally, the keywords should correspond with the actions that are to be performed at the call of the keyword).
This is a very simple example, wherein we have the basics of the Keyword-driven approach demonstrated. In more complex situations (for example, when testing several or more multiple-components applications), more complicated approaches are usually used. For example, several self-standing drivers, each being meant for a separate application or a component, or a more complex structure of the tables (for example, we can add an Application column, wherein the presently workable application is to be signified), and so forth.
3.144.30.178