Stage 5: Implement support for the test object operations
After enabling UFT One to recognize the custom controls, you must provide support for running test object operations. For each test object operation that you defined, you must write a JavaScript function that UFT One runs to perform the step on the control.
In this section, you provide support for the WebExtBook's test object methods: Select, GoToAuthorPage (AuthorName), and GoToUsedBooksPage.
Note: All of the JavaScript code that you write in this tutorial is designed to run on Microsoft Internet Explorer. When you develop support for your own controls, you can design it to be browser-independent and enable UFT One to support the controls on other browsers as well. For details, see the section on developing browser-independent support in the Micro Focus UFT One Web Add-in Extensibility Developer Guide.
Open the WebExtBook.js JavaScript file
It is possible to specify a JavaScript file and function for each test object method that you define. However, in this lesson, you develop support for running test object methods in the simplest way possible.
Do one of the following:
In the Operations tab in the test object designer, select the Select operation and click the Implementation Code button
next to the Name box.
In the Class View, right-click the Select operation, and select Implementation Code.
The
WebExtBook.js
file opens to the stub created for the Select function in a JavaScript Editor.Add the implementation code for the operations you defined
By default, UFT One searches in the JavaScript file for a function with the same name as the test object operation. The JavaScript functions must also have the same signature as the test object operations they run. Therefore, you need to implement the following JavaScript functions: Select, GoToAuthorPage (
AuthorName
), and GoToUsedBooksPage.Extensibility Accelerator already created stubs for these functions, with commented out suggestions of code lines that you might want to include.
Locate the stub for each function and replace it with the relevant implementation provided below.
Note: The _elem object is a reserved object that UFT One uses to refer to the HTML control currently being handled.
function Select() {// Click the link in the second cell of the first row. _elem.rows[0].cells[1].children[0].click(); _util.LogLine("Running Select test object method.",1); }
function GoToAuthorPage(AuthorName) {// Look for the specified author name among the children of the first cell // in the second row and click it. var bWasFound = false; for( var i = 0 ; i < _elem.rows[1].cells[0].children.length ; ++i ) { if( _elem.rows[1].cells[0].children[i].innerText == AuthorName ) { _elem.rows[1].cells[0].children[i].click(); _util.LogLine("Running GoToAuthorPage test object method.",1); bWasFound = true; // Update the report var params = new Array(); params[0] = AuthorName; _util.Report(micPass, "GoToAuthorPage", toSafeArray(params), "Author '" + AuthorName + "' was found :-)"); break; } } if( bWasFound == false ) throw ("Author name not found !"); }
function GoToUsedBooksPage() {// Click the link in the first cell of the third row. _elem.rows[3].cells[0].children[1].click(); _util.LogLine("Running GoToUsedBooksPage test object method.",1); }
Continue to Stage 6: Test and debug the support you designed for the test object operations.