Forum Discussion
how would I code the call in jscript?
jloyzagawh wrote:
how would I code the call in jscript?
var oShell = Sys.OleObject("WScript.Shell"); oShell.Run("C:\\MyFolder\\MyScript.vbs");
- FlossyThePig8 years agoOccasional Contributor
Sorry to resurrect this topic but I am moving from QTP to TestComplete and have a lot of function libraries used in our existing framework. I have tried a simple exercise to try calling a function from a .vbs file but TestComplete fails to see the function. The function works when it is included in the TC script. I feel I've missed something obvious, but what?
Local script:
sub Main()
dim strDay, strWeek
Set ws = Sys.OleObject("WScript.Shell")
ws.Run("C:\string_functions.vbs")
strWeek = "Sun,Mon,Tues,Wed,Thus,Fri,Sat"
'local function
strDay = ChooseStr(strWeek, 3 )
Log.Message ("Day using function ChooseStr = " + strDay)
'external function
strDay = StrChoose(strWeek, 3)
Log.Message ("Day using external function StrChoose = " + strDay)
end sub
Function ChooseStr(ByVal sCSV, ByVal nIndex)
Dim values
values = Split(sCSV,",")
ChooseStr = values(nIndex)
End Function
External file ("C:\string_functions.vbs")
Option Explicit
Function StrChoose(ByVal sCSV, ByVal nIndex)
Dim values
values = Split( sCSV,",")
StrChoose = values(nIndex)
End Function- HKosova8 years agoSmartBear Alumni (Retired)
Hi Flossy,
Add your .vbs file as an existing item to your project. Then in your main script, use:
'USEUNIT string_functions
sub Main()
...
strDay = ChooseStr(strWeek, 3)
' or prefix the function name with the file name
strDay = string_functions.ChooseStr(strWeek, 3)
...
end subThat said, this specific example (reading an item from a comma-separated list) can be replaced with TestComplete's built-in function aqString.GetListItem:
strWeek = "Sun,Mon,Tues,Wed,Thus,Fri,Sat"
aqString.ListSeparator = "," strDay = aqString.GetListItem(strWeek, 2) ' Indexes start from 0, so the 3rd item has index 2- FlossyThePig8 years agoOccasional Contributor
Thank you for your answer which solved the initial problem.
Unfortunately our current QTP framework has more than 400 function libraries built up over the last 10 years, covering:- Basic framework functions;
- Business functions;
- Applications functions (used by the Business functions).
Each test (250+) is controlled by an Excel spreadsheet which lists a sequence of Business functions required to cover a specific Business Process, with the test name used to identify the controlling spreadsheet.
Hopefully we will be able to use TestComplete's built-in functions to replace, or simplify, a lot the current QTP based function libraries.
I think the conversion exercise will take a little bit longer :-)
Related Content
- 13 years ago
- 8 years ago
Recent Discussions
- 9 hours ago
- 7 days ago
- 10 days ago