Combine-Macros.vbs
From iMacros
This example is for combining calls to macros in a single script. It calls the macros: Wsh-Start.iim, Wsh-Lunch.iim, and Wsh-Submit-Button. The example also shows how to create a custom error report log file. The script is also available as PowerShell version.
Visual Basic Script:
'*****
'This part is for the script specific error log (instead of popup messages).
'The advantage of an error log instead of a popup is that the script
'continues running even after an error appears. An example of an error would
'be a timeout due to a temporarily slow web site.
Dim objFileSystem, objOutputFile
Dim strOutputFile
Const OPEN_FILE_FOR_APPENDING = 8
' generate a logfile name based on the script name
strOutputFile = "./combine-macros-errorlog.txt"
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)
objOutputFile.WriteLine("Error Log for COMBINE-MACROS.VBS demo script")
'****
Msgbox ("This example script calls several Internet macros. Each macro performs a specific function on the website (Loading the
website with wsh-start, form filling with wsh-lunch and finally submitting the form with wsh-submit)." + vbCrLf + vbCrLf + "The
script also demonstrates how to create a SCRIPT SPECIFIC error log file.")
set iim1= CreateObject ("imacros")
i= iim1.iimInit
'If i < 0 Then msgbox iim1.iimGetLastError()
if i < 0 then objOutputFile.WriteLine("INIT: Error-No: " + cstr(i) + " => Description: " + iim1.iimGetLastError())
i = iim1.iimPlay("wsh-start")
'If i < 0 Then msgbox iim1.iimGetLastError()
if i < 0 then objOutputFile.WriteLine("WSH-START: Error-No: " + cstr(i) + " => Description: " + iim1.iimGetLastError())
i = iim1.iimPlay("wsh-lunch")
'If i < 0 Then msgbox iim1.iimGetLastError()
if i < 0 then objOutputFile.WriteLine("WSH-LUNCH: Error-No: " + cstr(i) + " => Description: " + iim1.iimGetLastError())
i = iim1.iimPlay("wsh-submit-button")
'If i < 0 Then msgbox iim1.iimGetLastError()
if i < 0 then objOutputFile.WriteLine("WSH-SUBMIT: Error-No: " + cstr(i) + " => Description: " + iim1.iimGetLastError())
i = iim1.iimExit
if i < 0 then objOutputFile.WriteLine("EXIT: Error-No: " + cstr(i) + " => Description: " + iim1.iimGetLastError())
'*****
'This part is for the script specific error log (instead of popup messages).
objOutputFile.Close
Set objFileSystem = Nothing
'*****
WScript.Quit(0)
Macro code for Wsh-Start:
VERSION BUILD=300002 TAB T=1 TAB CLOSEALLOTHERS URL GOTO=http://www.iopus.com/imacros/demo/v5 TAG TYPE=A ATTR=TXT:*Testform1* TAG TYPE=INPUT:TEXT FORM=NAME:TestForm ATTR=NAME:Name CONTENT=Tom<SP>Tester TAG TYPE=SELECT FORM=NAME:TestForm ATTR=NAME:main CONTENT=1 TAG TYPE=SELECT FORM=NAME:TestForm ATTR=NAME:drink CONTENT=3 TAG TYPE=INPUT:CHECKBOX FORM=NAME:TestForm ATTR=NAME:C7&&VALUE:ON CONTENT=YES TAG TYPE=SELECT FORM=NAME:TestForm ATTR=NAME:dessert CONTENT=0 TAG TYPE=INPUT:RADIO FORM=NAME:TestForm ATTR=NAME:Customer&&VALUE:Yes CONTENT=Yes TAG TYPE=INPUT:RADIO FORM=NAME:TestForm ATTR=NAME:newcustomer&&VALUE:Not_yet CONTENT=Not_yet
Macro code for Wsh-Lunch:
VERSION BUILD=300002 TAG TYPE=TEXTAREA FORM=NAME:TestForm ATTR=NAME:Remarks CONTENT=Lunch
Macro code for Wsh-Submit-Button:
VERSION BUILD=300002 TAB T=1 TAB CLOSEALLOTHERS TAG TYPE=INPUT:SUBMIT FORM=NAME:TestForm ATTR=NAME:SendButton&&VALUE:Click<SP>to<SP>order<SP>now WAIT SECONDS=3 URL GOTO=http://www.iopus.com/imacros/home/msg/ok.htm
Test Script
This is a modified version of the VBS script that runs continously in a loop. It is useful for testing issues with the Scripting Interface as it opens the browser, runs a few macros and closes the browser continously. All errors are logged. Of course, you can replace the macros ("wsh-start.iim" etc.) with any macro that you want to use for testing, e. g. Demo-Download or Demo-Flash.
Msgbox ("Start Test!"+vbCrlf+vbCrlf + "You can stop the script anytime by closing wscript.exe in the Windows Task Manager. On Win 2003 the process name is cscript.exe.")
Dim objFileSystem, objOutputFile
Dim strOutputFile, m
Const OPEN_FILE_FOR_APPENDING = 8
' generate a logfile name based on the script name
strOutputFile = "./test-log.txt"
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)
objOutputFile.WriteLine("Test Log")
'****
set iim1= CreateObject ("imacros")
for m = 1 to 1000
objOutputFile.WriteLine("--LOOP: "+cstr(m))
i= iim1.iimInit
if i < 0 then objOutputFile.WriteLine(cstr(m)+" INIT: Error-No: " + cstr(i) + " => Description: " + iim1.iimGetLastError())
i = iim1.iimPlay("wsh-start")
if i < 0 then objOutputFile.WriteLine(cstr(m)+"WSH-START: Error-No: " + cstr(i) + " => Description: " + iim1.iimGetLastError())
i = iim1.iimPlay("wsh-lunch")
if i < 0 then objOutputFile.WriteLine(cstr(m)+"WSH-LUNCH: Error-No: " + cstr(i) + " => Description: " + iim1.iimGetLastError())
i = iim1.iimPlay("wsh-submit-button")
if i < 0 then objOutputFile.WriteLine("WSH-SUBMIT: Error-No: " + cstr(i) + " => Description: " + iim1.iimGetLastError())
i = iim1.iimExit
if i < 0 then objOutputFile.WriteLine(cstr(m)+"EXIT: Error-No: " + cstr(i) + " => Description: " + iim1.iimGetLastError())
next
objOutputFile.WriteLine("TEST END")
objOutputFile.Close
Set objFileSystem = Nothing
WScript.Quit(0)
