Use testcomplete to implement a keyword-Driven Testing Framework

Source: Internet
Author: User
Tags testcomplete
Use testcomplete to implement a keyword-Driven Testing FrameworkChen nengji recently made an automated test project using testcomplete, and found that in testcomplete, The findchild method can be used to implement a simple keyword-driven framework, the method is as follows: (1) Write test keywords in Excel. Write test keywords in an Excel file, including test objects, test operations, and input parameters ,: (2) Write a test script and read the test keywords in execl. // Global variable array, used to store the test keywords var keyword_testobject, keyword_operation, keyword_parameters read from Excel; //...................................... ....................................... // purpose: to query Excel data through ADO // input the following parameter: // excelfilepath: Excel file path // querystring: query statement // return result: // return all keyword data, assigned to the keyword_testobject, keyword_operation, keyword_parameters global variable arrays // Note: // Author: Chen nengtech // Date: 2008-6-3 //.................................. ........................................... Function readkeywordfromexcel (excelfilepath, querystring); var constr, connection, RS, classobjarray, lineindex, classobject: olevariatn; begin // defines the connection string constr: = 'provider = Microsoft. jet. oledb.4.0; Data Source = % s; extended properties = Excel 8.0 '; constr: = utilities. format (constr, [excelfilepath]); connection: = sys. oleobject ('ADODB. connection '); // open the connection. O Pen (constr); // execute the query operation RS: = connection. execute (querystring); // create the variable array keyword_testobject: = createvariantarray (); keyword_operation: = values (); keyword_parameters: = createvariantarray (); lineindex: = 0; // read all data cyclically while not Rs. EOF do begin Inc (lineindex); // dynamically modify array size vararrayredim (keyword_testobject, LineIndex-1); vararrayredim (keyword_operation, LineIndex-1); vararrayredim (Keyword_parameters, LineIndex-1); // value keyword_testobject [LineIndex-1]: = Rs ['testobject']. value; keyword_operation [LineIndex-1]: = Rs ['operation']. value; keyword_parameters [LineIndex-1]: = Rs ['parameters ']. value; // The next data Rs. movenext; end; RS. close; // close the connection. close; end; Procedure test_readkeywordfromexcel; var I: olevariant; begin readkeywordfromexcel ('d:/code/mytestsuite/data/keyword. XL S ', 'select * from [keyword $]'); for I: = 0 to vararrayhighbound (keyword_testobject, 1) Do begin log. message (vartostr (keyword_testobject [I]) + '|' + vartostr (keyword_operation [I]) + '|' + vartostr (keyword_parameters [I]); end; (3) encapsulate a function to create available test objects based on the test keywords read in Excel. Uses checkuiperformance; //...................................... ....................................... // purpose: return the specified test object in the current process // input parameter: // process: Process object // testobject: description of the test object // return result: // return the specified test object in the current process // Note: // Author: Chen nengtech // Date: 2008-6-3 //................................. ........................................ .... function GetObject (process, testobject); var proparray, valuesarray; begin proparray: = createvariant Array (0, 0); valuesarray: = createvariantarray (0, 0); proparray [0]: = 'fullname'; valuesarray [0]: = testobject; // call the findtestobject function and return the result of the specified test object in the current process: = findtestobject (process, proparray, valuesarray); end; the findtestobject function written in the checkuiperformance script is called here, this function is used to find the test object in the specified process based on the description of the test object. The script is as follows: function findtestobject (process, proparray, valuearray); var res; begin result: = false; // search for the specified test object process. re Fresh (); Res: = process. findchild (proparray, valuearray, 1000); // returns the test object if res. exists then begin result: = res; log. message ('found test object: '+ Res. fullname) end else log. message ('test object not found '); end; (4) encapsulate a function to perform the test operation based on the test keywords read in Excel. //...................................... ....................................... // Purpose: perform the test operation // input the following parameters: // testobject: Test object // operation: description of the test operation // parameters: parameters corresponding to the test operation // return results: NONE // Note: // Author: Chen nengtech // Date: 2008-6-3 //................................. ........................................ .... function dooperation (testobject, operation, parameters); begin case operation of 'keys ': testobject. keys (parameters); 'clic K': testobject. Click; // Add code for processing other types of test operations... else log. Error ('This test operation is not supported! '); End; Note: Only test operations of keys and click are added here. (5) The keyword-driven core framework has the basis of the previous functions, so you can write the following simple key-driven core framework: //...................................... ....................................... // purpose: keyword-driven core framework // input parameter: // return result: // Note: // Author: Chen nengtech // Date: 2008-6-3 //................................. ........................................ .... procedure driver; var testobject, I; begin // 1. Read the keyword readkeywordfromexcel ('d:/code/mytestsuite/data/keyword.xls ', 'select * from [Key Word $] '); // 2. traverse the keywords to create a test object and execute the test operation for I: = 0 to vararrayhighbound (keyword_testobject, 1) Do begin // log. message (vartostr (keyword_testobject [I]) + '|' // + vartostr (keyword_operation [I]) + '|' // + vartostr (keyword_parameters [I]); // create the testobject: = GetObject (sys. process ('flight4a '), vartostr (keyword_testobject [I]); // execute the test operation dooperation (testobject, vartostr (keyword_operation [I]), vartostr (keywo Rd_parameters [I]); end; after testing, this method can implement a keyword-driven testing framework similar to qtp, but it is just a very basic keyword-driven testing framework, if you want to apply this framework to a real project, you still need to modify and improve it. There is still much work to be done, including: (1) writing the keyword editor. Currently, the test keyword is entered directly in an Excel file, which causes efficiency and availability problems. You need to create a keyword view editor that is similar to qtp. (2) Add more test operations and methods. Currently, as a test, only test operations of keys and click are added. Many testing methods of controls need to be encapsulated, such as clickitem and selectitem of list controls. In addition, the attribute assignment operation and attribute check operation (similar to the checkpoint of qtp) of the test object need to be further written in framework code. (3) synchronization between the keyword code and the test script. Relying only on Excel keyword data to automate the test of the entire project is too idealistic. qtp provides a good code generation mechanism, data in the keyword view and test scripts in the expert view can be synchronized and switched at any time. Therefore, this keyword-driven testing framework still lacks a code generator, how to Establish the ing between Excel Data and test scripts is one of the main tasks in the next step.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.