Frame Object
Description
An HTML frame.
Operations
The sections below list the built-in methods and properties that you can use as operations for the Frame object.
Note: You can also view a list and descriptions of the Frame description properties, for use in object repository descriptions, programmatic descriptions, checkpoint and output value steps, and as argument values for the GetTOProperty and GetROProperty methods.
Methods
CaptureBitmap | Saves a screen capture of the object as a .png or .bmp image using the specified file name. |
Check | Checks whether the actual value of an item matches the expected value. |
CheckProperty | Checks whether the actual value of the specified object property matches the specified expected value within the specified timeout. |
ChildObjects | Returns the collection of child objects contained within the object. |
GetAllROProperties | Returns the collection of properties and current values from the object in the application. |
GetROProperty | Returns the current value of the description property from the object in the application. |
GetTOProperties | Returns the collection of properties and values used to identify the object. |
GetTOProperty | Returns the value of the specified description property from the test object description. |
Highlight | Highlights the object in the application. |
Output | Retrieves the current value of an item and stores it in a specified location. |
RefreshObject | Instructs OpenText Functional Testing to re-identify the object in the application the next time a step refers to this object. |
RunScript | Runs the specified JavaScript. |
RunScriptFromFile | Runs the JavaScript stored in the specified file. |
SetTOProperty | Sets the value of the specified description property in the test object description. |
ToString | Returns a string that represents the test object. |
WaitProperty | Waits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step. |
Properties
Exist | Checks whether the object currently exists in the open application. |
Object | Accesses the native methods and properties of the object. |
RunScript Method
Description
Runs the specified JavaScript.
Syntax
object.RunScript (Script)
Arguments
Parameter | Description |
---|---|
Script |
Required. A String value. The full content of the JavaScript to run. |
Return Type
A Variant.
IMPORTANT
- If the script you run returns a JavaScript array, you cannot use standard VBScript syntax to access the array index (for example, arr(0) ) nor can use use JavaScript syntax (for example arr[0]).
- You can use JavaScript operations such as pop, push, shift or length to access JavaScript array items. Keep in mind, however, that most such JavaScript array operations also modify the content of the array. Therefore, you may want to consider cloning the array and using these operations on the cloned copy. (See example below.) Alternatively, you can run a JavaScript function that converts the returned array to a safearray. Then you can use standard VBScript syntax to iterate the array.
- The entire script must be specified as the argument value (as a string or variable). To specify a JavaScript file as the argument value, use the RunScriptFromFile method.
- To run this method, the security settings in your Web browser must be set to allow active scripting. Otherwise, steps using this method will fail.
- When working with Internet Explorer, using this method to run the Alert, Prompt, and Confirm JavaScript methods is not supported.
- When running this method, you should use an eval() function or anonymous function to run the script entered for this method.
For example, you can use functions like these:
"eval(var remove = document.getElementsByTagName('a')[0]; var per = remove.parentNode; per.removeChild(remove););"
OR
"(function(){var remove = document.getElementsByTagName('a')[0]; var per = remove.parentNode; per.removeChild(remove);})();"
Example
'This example uses the RunScript method to remove a DOM element from a frame. 'Then it verifies that the frame still behaves correctly when the DOM element is removed. Browser("MySearchEngine").Page("MySearchEngine").Frame("Web Search").RunScript "eval(var remove = document.getElementsByTagName('a')[0]; var per = remove.parentNode; per.removeChild(remove););" 'Check that the frame behaves correctly If Browser("MySearchEngine").Page("MySearchEngine").Frame("Web Search").Image("MySearchEngine").Exist Then Reporter.ReportEvent micFail, "Failed to remove MySearchEngine logo" End If
'This example provides a JavaScript function that uses a Push operation to clone 'the array that is returned by the RunScript method. The cloneArray function is then saved as a .js file in the file system. 'The example then uses the EmbedScriptFromFile method to embed the function in the specified frame, 'and the RunScript method to run the embedded cloneArray() function on the script that returned the array. 'Adapt the following function and save it as CloneArray.js on your C: drive: ' function cloneArray(arr) { ' var ret = []; ' for (var i = 0; i < arr.length; ++i) ' ret.push(arr[i]); ' return ret; ' } 'In OpenText Functional Testing, embed the function in the frame Browser("MyBrowser").Page("MyPage").Frame("MyFrame").EmbedScriptFromFile "C:\CloneArray.js" 'Call the function and run the script that returns the array Set cloned = Browser("MyBrowser").Page("MyPage").Frame("MyFrame").RunScript("cloneArray( /* JavaScript code that returns an array */ )")
RunScriptFromFile Method
Description
Runs the JavaScript stored in the specified file.
Syntax
object.RunScriptFromFile (FileName)
Arguments
Parameter | Description |
---|---|
FileName |
Required. A String value. The full path of the JavaScript file to run. The location can be an absolute or relative file system path or an ALM path. |
Return Type
A Variant.
IMPORTANT
- If the script you run returns a JavaScript array, you cannot use standard VBScript syntax to access the array index (for example, arr(0) ) nor can use use JavaScript syntax (for example arr[0]).
- You can use JavaScript operations such as pop, push, shift or length to access JavaScript array items. Keep in mind, however, that most such JavaScript array operations also modify the content of the array. Therefore, you may want to consider cloning the array and using these operations on the cloned copy. (See example below.) Alternatively, you can run a JavaScript function that converts the returned array to a safearray. Then you can use standard VBScript syntax to iterate the array.
- This method runs a JavaScript from a specified file. To run a script directly as the argument value, use the RunScript method.
- To run this method, the security settings in your Web browser must be set to allow active scripting. Otherwise, steps using this method will fail.
- When working with Internet Explorer, using this method to run the Alert, Prompt, and Confirm JavaScript methods is not supported.
- When running this method, you should use an eval() function or anonymous function to run the script entered for this method.
For example, you can use functions like these:
"eval(var remove = document.getElementsByTagName('a')[0]; var per = remove.parentNode; per.removeChild(remove););"
OR
"(function(){var remove = document.getElementsByTagName('a')[0]; var per = remove.parentNode; per.removeChild(remove);})();"
Example
'This example uses the RunScriptFromFile method to remove a DOM element from a frame. 'Then it verifies that the frame still behaves correctly when the DOM element is removed. Browser("MySearchEngine").Page("MySearchEngine").Frame("Web Search").RunScriptFromFile "c:\remove_logo.js" 'Check that the frame behaves correctly If Browser("MySearchEngine").Page("MySearchEngine").Frame("Web Search").Image("MySearchEngine").Exist Then Reporter.ReportEvent micFail, "Failed to remove MySearchEngine logo" End If
'This example provides a JavaScript function that uses a push operation to clone 'the array that is returned by the RunScriptFromFile method. The cloneArray function is then saved as a .js file in the file system. 'The example then uses the EmbedScriptFromFile method to embed the function in the specified frame, 'and the RunScriptFromFile method to run the embedded cloneArray() function on the script that returned the array. 'Adapt the following function and save it as CloneArray.js on your C: drive: ' function cloneArray(arr) { ' var ret = []; ' for (var i = 0; i < arr.length; ++i) ' ret.push(arr[i]); ' return ret; ' } 'In OpenText Functional Testing, embed the function in the frame Browser("MyBrowser").Page("MyPage").Frame("MyFrame").EmbedScriptFromFile "C:\CloneArray.js" 'Call the function and run the script that returns the array Set cloned = Browser("MyBrowser").Page("MyPage").Frame("MyFrame").RunScriptFromFile("cloneArray( /* JavaScript file path that returns an array */ )")
See also: