stresstest.vbs

From iMacros
Jump to: navigation, search

When run, the script

  • asks for a number that will be used in the log file's name (stresstest.n.log)
  • initializes an iMacros browser instance that
  • runs an endless loop (you will need to kill it manually via the task manager!)
    • filling a form
    • saving a browser screenshot

Start this script several times (which means that several iMacros instances will run in parallel) to see how your system behaves under heavy web automation load.

Note that the system load depends on the sites that are automated. Replace the macros given here by your ones to see how many parallel instances of your macros your system can handle.

Dim objFileSystem, objOutputFile
Dim strOutputFile

Const OPEN_FILE_FOR_APPENDING = 8
' generate a logfile name based on the script name and on the number entered by the user
Dim number
number = inputbox("Enter unique script number: ")
strOutputFile = "./stresstest." + Cstr(number) + ".log" 
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)
objOutputFile.WriteLine("Error Log for stresstest.vbs demo script")

Dim iim, m, i
set iim1= CreateObject ("imacros")
m = 0 

do while true 
	 m = m + 1
 	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(returnStartMacro())
 	if i < 0 then objOutputFile.WriteLine(cstr(m)+"WSH-START: Error-No: " + cstr(i) + " => Description: " + iim1.iimGetLastError())
 
	 i = iim1.iimPlay(returnLunchMacro)
 	if i < 0 then objOutputFile.WriteLine(cstr(m)+"WSH-LUNCH: Error-No: " + cstr(i) + " => Description: " + iim1.iimGetLastError())
 
	 i = iim1.iimPlay(returnSubmitMacro)
 	if i < 0 then objOutputFile.WriteLine("WSH-SUBMIT: Error-No: " + cstr(i) + " => Description: " + iim1.iimGetLastError())
 
        i = iim1.iimTakeBrowserScreenshot("screenshot" + Cstr(number) + ".png")
	if i < 0 then objOutputFile.WriteLine("iimTakeBrowserScreenshot: 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())
 loop
 
 objOutputFile.WriteLine("TEST END")
 objOutputFile.Close
 Set objFileSystem = Nothing
 WScript.Quit(0)

function returnStartMacro
	 Dim macro
	macro= "CODE:"
	 macro = macro + " VERSION BUILD=300002    " + vbNewLine 
	macro = macro + " TAB T=1     " + vbNewLine 
	 macro = macro + " TAB CLOSEALLOTHERS  " + vbNewLine 
	macro = macro + " URL GOTO=http://demo.imacros.net/     " + vbNewLine 
	 macro = macro + " TAG POS=1 TYPE=A ATTR=TXT:Testform1  " + vbNewLine 
	macro = macro + " TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:TestForm ATTR=NAME:Name CONTENT=tom<SP>tester " + vbNewLine 
	 macro = macro + " TAG POS=1 TYPE=SELECT FORM=NAME:TestForm ATTR=NAME:main CONTENT=1 " + vbNewLine 
	macro = macro + " TAG POS=1 TYPE=SELECT FORM=NAME:TestForm ATTR=NAME:drink CONTENT=3 " + vbNewLine 
	 macro = macro + " TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:TestForm ATTR=NAME:C7&&VALUE:ON CONTENT=YES " + vbNewLine 
	macro = macro + " TAG POS=1 TYPE=SELECT FORM=NAME:TestForm ATTR=NAME:dessert CONTENT=0 " + vbNewLine 
	 macro = macro + " TAG POS=1 TYPE=INPUT:RADIO FORM=NAME:TestForm ATTR=NAME:Customer&&VALUE:Yes CONTENT=Yes " + vbNewLine 
	macro = macro + " TAG POS=1 TYPE=TEXTAREA FORM=NAME:TestForm ATTR=NAME:Remarks CONTENT=remark  " + vbNewLine 		
	 returnStartMacro = macro
end function

function returnLunchMacro
 Dim macro
 macro = "CODE:"
 macro = macro + "TAG POS=1 TYPE=TEXTAREA FORM=NAME:TestForm ATTR=NAME:Remarks CONTENT=Lunch "
 returnLunchMacro = macro
end function

function returnSubmitMacro
	 Dim macro
	macro= "CODE:"
	 macro = macro + " TAB T=1     " + vbNewLine 
	macro = macro + " TAB CLOSEALLOTHERS   " + vbNewLine 
	 macro = macro + " TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:TestForm ATTR=NAME:SendButton&&VALUE:Click<SP>to<SP>order<SP>now  " + vbNewLine 
	macro = macro + " WAIT SECONDS=3" + vbNewLine 
	 macro = macro + " URL GOTO=http://demo.imacros.net/automate/ok" + vbNewLine 
	macro = macro + "" + vbNewLine 
	 returnSubmitMacro = macro
end function