Please help me in using EmbedScriptFromFile
& RunScriptFromFile
for executing JS file in QTP/UFT.
I'm trying to fetch N number of values using JS file, and receive the same in QTP/UFT in an array. For which, I have got to know about EmbedScriptFromFile
& RunScriptFromFile
in QTP/UFT help section. But when I've tried to use the sample code, I couldn't make it as expected. Please help me in this issue
Java Script code I'm using:
function cloneArray(arr) {
var ret = [];
for (var i = 0; i < arr.length; ++i)
ret.push(arr[i]);
return ret;
}
VB Script, I'm using:
Browser("Home").Page("Home").EmbedScriptFromFile "C:\Users\Gopi\Desktop\CloneArray.js" 'Call the function and run the script that returns the array'
Set cloned = Browser("Home").Page("Home").RunScriptFromFile("cloneArray(C:\Users\Gopi\Desktop)")
Getting some errors while executing these two line - for first line, I'm getting error as 'Object doesn't support this property or method'. And for the second line, I'm getting error as 'The parameter is incorrect'. Please help
15-Dec-2014:
I have tried the suggestions below and it worked! But on top of that, I'm trying to get the array values too from JavaScript function.
Code to create an array:
function makeArray() {
var myArray = new Array(4);
for (var i = 0; i < myArray.length; i++){
myArray[i] = i+1;
}
return myArray;
}
So exactly what I'm trying to achieve is, execute makeArray()
function to create an array and create the QTP/UFT supporting array using cloneArray
method by passing the makeArray()
returning value/array as parameter to ConeArray(arr)
. But when I try to achieve this with following code, I couldn't make it.
Browser("Home").EmbedScriptFromFile "C:\Users\Gopi\Desktop\cloneArray.js"
'Set arr1 = Browser("Home").Page("Home").RunScriptFromFile "C:\Users\Gopi\Desktop\makeArray.js"
Set arr = Browser("Home").Page("Home").RunScript("cloneArray[C:\Users\Gopi\Desktop\makeArray.js]")
For i = 0 To arr.length - 1
msgbox i & ": " & arr.item(i)
Next
EmbedScript
& RunScript
are working fine when I try separately, but not able to use while trying to pass another function as parameter.
I have tried to have both the functions in same JS file and call the functions, and tried with a few other possibilities too. But nothing helped, so please help.