Identify Wich Step Has Failed

Discussions and Tech Support related to automating the iMacros Browser or Internet Explorer from any scripting and programming language, such as VBS (WSH), VBA, VB, Perl, Delphi, C# or C++.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information:CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
Ervella
Posts: 9
Joined: Thu May 03, 2018 7:56 pm

Identify Wich Step Has Failed

Post by Ervella » Thu May 03, 2018 8:15 pm

Hello!

I've been searching for an answer for this, but without success...
I have a few scripts that need to show exactly wich step, guided by stopwatch, has failed.
Actually, I'm using an IF to show the error text. I was trying put some variable inside the macro that receive an identifier to the step. The code is below.
Thanks!

Code: Select all

Option Explicit

Dim macro

macro = "VERSION BUILD=10002738" + vbNewLine 
macro = macro + "TAB T=1     " + vbNewLine 
macro = macro + "TAB CLOSEALLOTHERS " + vbNewLine 
macro = macro + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
macro = macro + "STOPWATCH ID=T5_Total" + vbNewLine
macro = macro + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine
macro = macro + "URL GOTO=URL" + vbNewLine
macro = macro + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine
macro = macro + "STOPWATCH ID=T2_LogIn" + vbNewLine
macro = macro + "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmLogin ATTR=NAME:txtUsuario CONTENT=USER" + vbNewLine
macro = macro + "SET !ENCRYPTION NO" + vbNewLine
macro = macro + "TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:frmLogin ATTR=NAME:pwdSenha CONTENT=PASS" + vbNewLine
macro = macro + "TAG POS=1 TYPE=BUTTON:SUBMIT FORM=NAME:frmLogin ATTR=NAME:sbmLogin" + vbNewLine
macro = macro + "STOPWATCH ID=T2_LogIn" + vbNewLine
macro = macro + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine
macro = macro + "TAG POS=1 TYPE=A ATTR=TXT:Controle<SP>de<SP>Processos" + vbNewLine
macro = macro + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine
macro = macro + "STOPWATCH ID=T4_LogOff" + vbNewLine
macro = macro + "TAG POS=1 TYPE=IMG ATTR=SRC:https://URL/imagens/sair.gif" + vbNewLine
macro = macro + "STOPWATCH ID=T4_LogOff" + vbNewLine
macro = macro + "STOPWATCH ID=T5_Total"

Dim iim1, iret, iplay
Dim s

set iim1= CreateObject ("imacros")

iret = iim1.iimOpen ("-kioskmode",true)
iret = iim1.iimDisplay("Get Response Times")
iplay = iim1.iimPlayCode(macro)

Dim errortext
errortext  = iim1. iimGetErrorText()

[b]If iplay < 0 Then
	WScript.Echo "CRITICAL: The following error occurred on "+ [i]STEP [/i]+": " + errortext + vbNewLine
	iret = iim1.iimClose
	WScript.Quit(2)
End If[/b]

Dim idName
Dim T1_PaginaInicial,T2_LogIn,T3_ControleProcessos,T4_LogOff,T5_Total

iret = iim1.iimGetStopwatch(3,idName,T1_PaginaInicial)
iret = iim1.iimGetStopwatch(4,idName,T2_LogIn)
iret = iim1.iimGetStopwatch(5,idName,T3_ControleProcessos)
iret = iim1.iimGetStopwatch(6,idName,T4_LogOff)
iret = iim1.iimGetStopwatch(2,idName,T5_Total)

iret = iim1.iimClose

dim hoje
hoje = Now()

WScript.Echo "Passos executados em " & T5_Total & " segundos Executado em: " & hoje & " | T1_PaginaInicial=" & T1_PaginaInicial & "s;;;0; T2_LogIn=" & T2_LogIn & "s;;;0; T3_ControleProcessos=" & T3_ControleProcessos & "s;;;0; T4_LogOff=" & T4_LogOff & "s;;;0; T5_Total=" & T5_Total & "s;;;0;"
WScript.Quit(0)
Last edited by Ervella on Wed May 16, 2018 3:33 pm, edited 1 time in total.
chivracq
Posts: 8143
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Identify Wich Step Has Failed

Post by chivracq » Fri May 04, 2018 12:23 am

Ervella wrote:Hello!

I've been searching for an answer for this, but without success...
I have a few scripts that need to show exactly wich step, guided by stopwatch, has failed.
Actually, I'm using an IF to show the error text. I was trying put some variable inside the macro that receive an identifier to the step. The code is below.
Thanks!

Code: Select all

Option Explicit

Dim macro

macro = "VERSION BUILD=10002738" + vbNewLine 
macro = macro + "TAB T=1     " + vbNewLine 
macro = macro + "TAB CLOSEALLOTHERS " + vbNewLine 
macro = macro + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
macro = macro + "STOPWATCH ID=T5_Total" + vbNewLine
macro = macro + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine
macro = macro + "URL GOTO=URL" + vbNewLine
macro = macro + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine
macro = macro + "STOPWATCH ID=T2_LogIn" + vbNewLine
macro = macro + "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmLogin ATTR=NAME:txtUsuario CONTENT=USER" + vbNewLine
macro = macro + "SET !ENCRYPTION NO" + vbNewLine
macro = macro + "TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:frmLogin ATTR=NAME:pwdSenha CONTENT=PASS" + vbNewLine
macro = macro + "TAG POS=1 TYPE=BUTTON:SUBMIT FORM=NAME:frmLogin ATTR=NAME:sbmLogin" + vbNewLine
macro = macro + "STOPWATCH ID=T2_LogIn" + vbNewLine
macro = macro + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine
macro = macro + "TAG POS=1 TYPE=A ATTR=TXT:Controle<SP>de<SP>Processos" + vbNewLine
macro = macro + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine
macro = macro + "STOPWATCH ID=T4_LogOff" + vbNewLine
macro = macro + "TAG POS=1 TYPE=IMG ATTR=SRC:https://URL/imagens/sair.gif" + vbNewLine
macro = macro + "STOPWATCH ID=T4_LogOff" + vbNewLine
macro = macro + "STOPWATCH ID=T5_Total"

Dim iim1, iret, iplay
Dim s

set iim1= CreateObject ("imacros")

iret = iim1.iimOpen ("-kioskmode",true)
iret = iim1.iimDisplay("Get Response Times")
iplay = iim1.iimPlayCode(macro)

Dim errortext
errortext  = iim1. iimGetErrorText()

[b]If iplay < 0 Then
	WScript.Echo "CRITICAL: The following error occurred on "+ [i]STEP [/i]+": " + errortext + vbNewLine
	iret = iim1.iimClose
	WScript.Quit(2)
End If[/b]

Dim idName
Dim T1_PaginaInicial,T2_LogIn,T3_ControleProcessos,T4_LogOff,T5_Total

iret = iim1.iimGetStopwatch(3,idName,T1_PaginaInicial)
iret = iim1.iimGetStopwatch(4,idName,T2_LogIn)
iret = iim1.iimGetStopwatch(5,idName,T3_ControleProcessos)
iret = iim1.iimGetStopwatch(6,idName,T4_LogOff)
iret = iim1.iimGetStopwatch(2,idName,T5_Total)

iret = iim1.iimClose

dim hoje
hoje = Now()

WScript.Echo "Passos executados em " & T5_Total & " segundos Executado em: " & hoje & " | T1_PaginaInicial=" & T1_PaginaInicial & "s;;;0; T2_LogIn=" & T2_LogIn & "s;;;0; T3_ControleProcessos=" & T3_ControleProcessos & "s;;;0; T4_LogOff=" & T4_LogOff & "s;;;0; T5_Total=" & T5_Total & "s;;;0;"
WScript.Quit(0)
FCIM...! :mrgreen: (Read my Sig...)
=> iMB v10.0 Scripting Interface...?, Browser=iMB v10.0...?, OS...?

Oh..., I was going to tell you to use 'iimGetErrorText()' but you've "discovered" it since you opened your Thread, always a bit "dangerous" to silently edit your Posts btw... Then OK, are you settled now or do you still need some Help...?

Some other Option could be to use the Profiler, you then get the same Info, but you get that Info only after your Script has finished running, not IRT like with 'iimGetErrorText()' where you can take some direct Decision on how your Script will further handle the Error... And the Profiler slows down by about 30% the Script Execution, which could play a Role for you as you are using 'STOPWATCH'...

Or you could split your whole Script in 5 Sub-Macros if you want to have more Control on each part, but you will "lose" the 'T5_Total' Time...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Ervella
Posts: 9
Joined: Thu May 03, 2018 7:56 pm

Re: Identify Wich Step Has Failed

Post by Ervella » Fri May 04, 2018 11:22 am

Oh, im sorry, I'm using W7 and iMacros V10.0. And i didn't edited my post, I was already using iimGetErrorText(), but, I ain't getting the expected result...
Using sub-macros will enable to get wich step (stopwatch) has failed?
How is the syntax of sub-macros?
Thanks
chivracq
Posts: 8143
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Identify Wich Step Has Failed

Post by chivracq » Fri May 04, 2018 2:31 pm

Ervella wrote:Oh, im sorry, I'm using

Code: Select all

W7 and iMacros V10.0.
And i didn't edited my post, I was already using iimGetErrorText(), but, I ain't getting the expected result...
Using sub-macros will enable to get wich step (stopwatch) has failed?
How is the syntax of sub-macros?
Thanks
Hum..., OK, strange about "post edited", when I had looked at your Post/Script, the Script was "only" going until the 2nd 'STOPWATCH=T5_Total' Line, but hum, I had looked at it from the 'Forum Moderator Interface' before approving it, so maybe your Post got "truncated" as you didn't format it using the ']CODE[' Meta-Tags, dunno... But OK, never mind... :?
(Well, would still be nice if you could format your first Post with the ]CODE[ Tags, that makes the Thread easier to read/follow... :idea: )

Well, splitting your current Script is fairly easy... You currently construct your "macro" String as one big String before using 'iimPlay()' to run it as one big Macro, which is "normally" the correct way to do it, you then simply split it in 5 parts and you play each part with 5x 'iimPlay()'.
You only need to repeat the '!FILESTOPWATCH' Line in each Sub-Macro as all Vars get reset at the end of each Use of 'iimPlay()' (oh...!, same thing with 'iimPlayCode()').

That would give stg like...:

Code: Select all

macro1 = "VERSION BUILD=10002738" + vbNewLine
macro1 = macro1 + "TAB T=1     " + vbNewLine
macro1 = macro1 + "TAB CLOSEALLOTHERS " + vbNewLine
macro1 = macro1 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
//macro = macro + "STOPWATCH ID=T5_Total" + vbNewLine
macro1 = macro1 + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine
macro1 = macro1 + "URL GOTO=URL" + vbNewLine
macro1 = macro1 + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine

macro2 = "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
macro2 = macro2 + "STOPWATCH ID=T2_LogIn" + vbNewLine
macro2 = macro2 + "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmLogin ATTR=NAME:txtUsuario CONTENT=USER" + vbNewLine
macro2 = macro2 + "SET !ENCRYPTION NO" + vbNewLine
macro2 = macro2 + "TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:frmLogin ATTR=NAME:pwdSenha CONTENT=PASS" + vbNewLine
macro2 = macro2 + "TAG POS=1 TYPE=BUTTON:SUBMIT FORM=NAME:frmLogin ATTR=NAME:sbmLogin" + vbNewLine
macro2 = macro2 + "STOPWATCH ID=T2_LogIn" + vbNewLine

macro3 = "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
macro3 = macro3 + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine
macro3 = macro3 + "TAG POS=1 TYPE=A ATTR=TXT:Controle<SP>de<SP>Processos" + vbNewLine
macro3 = macro3 + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine

macro4 = "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
macro4 = macro4 + "STOPWATCH ID=T4_LogOff" + vbNewLine
macro4 = macro4 + "TAG POS=1 TYPE=IMG ATTR=SRC:https://URL/imagens/sair.gif" + vbNewLine
macro4 = macro4 + "STOPWATCH ID=T4_LogOff" + vbNewLine
//macro = macro + "STOPWATCH ID=T5_Total"

Dim iim1, iret, iplay1, iplay2, iplay3, iplay4
Dim s

set iim1= CreateObject ("imacros")

iret = iim1.iimOpen ("-kioskmode",true)
iret = iim1.iimDisplay("Get Response Times")
iplay1 = iim1.iimPlayCode(macro1)
iplay2 = iim1.iimPlayCode(macro2)
iplay3 = iim1.iimPlayCode(macro3)
iplay4 = iim1.iimPlayCode(macro4)
Well, it's 4 parts actually, and not 5... :oops:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Ervella
Posts: 9
Joined: Thu May 03, 2018 7:56 pm

Re: Identify Wich Step Has Failed

Post by Ervella » Fri May 04, 2018 3:50 pm

Ah, I got it...
Well, i separated the macro in a few sub-macros, AND, now I can get the step where are the error. However, the time of each step isn't getting computed.
The above code maybe seen nailed-up, but I'll improve it later...

Code: Select all

Option Explicit


Dim macro, macro1, macro2, macro3, macro4


macro1 = "VERSION BUILD=10002738" + vbNewLine 
macro1 = macro1 + "TAB T=1     " + vbNewLine 
macro1 = macro1 + "TAB CLOSEALLOTHERS " + vbNewLine 
macro1 = macro1 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
macro1 = macro1 + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine
macro1 = macro1 + "URL GOTO=URL" + vbNewLine
macro1 = macro1 + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine

macro2 = macro2 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
macro2 = macro2 + "STOPWATCH ID=T2_LogIn" + vbNewLine
macro2 = macro2 + "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmLogin ATTR=NAME:txtUsuario CONTENT=USER" + vbNewLine
macro2 = macro2 + "SET !ENCRYPTION NO" + vbNewLine
macro2 = macro2 + "TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:frmLogin ATTR=NAME:pwdSenha CONTENT=PASS" + vbNewLine
macro2 = macro2 + "TAG POS=1 TYPE=BUTTON:SUBMIT FORM=NAME:frmLogin ATTR=NAME:sbmLogin" + vbNewLine
macro2 = macro2 + "STOPWATCH ID=T2_LogIn" + vbNewLine

macro3 = macro3 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
macro3 = macro3 + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine
macro3 = macro3 + "TAG POS=1 TYPE=A ATTR=TXT:Controle<SP>de<SP>Processos" + vbNewLine
macro3 = macro3 + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine

macro4 = macro4 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
macro4 = macro4 + "STOPWATCH ID=T4_LogOff" + vbNewLine
macro4 = macro4 + "TAG POS=1 TYPE=IMG ATTR=SRC:URL/sair.gif" + vbNewLine
macro4 = macro4 + "STOPWATCH ID=T4_LogOff" + vbNewLine


Dim iim1, iret, iplay1, iplay2, iplay3, iplay4, errortext

set iim1= CreateObject ("imacros")

iret = iim1.iimOpen ("-kioskmode",true)
iret = iim1.iimDisplay("Get Response Times")

iplay1 = iim1.iimPlayCode(macro1)
errortext= iim1. iimGetErrorText()
If iplay1 < 0 Then
    WScript.Echo "CRITICAL: The following error occurred in step T1_PaginaInicial: " + errortext + vbNewLine
	iret = iim1.iimClose
	WScript.Quit(2)
End If
iplay2 = iim1.iimPlayCode(macro2)
errortext= iim1. iimGetErrorText()
If iplay2 < 0 Then
    WScript.Echo "CRITICAL: The following error occurred in step T2_LogIn: " + errortext + vbNewLine
	iret = iim1.iimClose
	WScript.Quit(2)
End If
iplay3 = iim1.iimPlayCode(macro3)
errortext= iim1. iimGetErrorText()
If iplay3 < 0 Then
    WScript.Echo "CRITICAL: The following error occurred in step T3_ControleProcessos: " + errortext + vbNewLine
	iret = iim1.iimClose
	WScript.Quit(2)
End If
iplay4 = iim1.iimPlayCode(macro4)
errortext= iim1. iimGetErrorText()
If iplay4 < 0 Then
    WScript.Echo "CRITICAL: The following error occurred in step T4_LogOff: " + errortext + vbNewLine
	iret = iim1.iimClose
	WScript.Quit(2)
End If

Dim idName
Dim T1_PaginaInicial,T2_LogIn,T3_ControleProcessos,T4_LogOff,total

iret = iim1.iimGetStopwatch(1,idName,T1_PaginaInicial)
iret = iim1.iimGetStopwatch(2,idName,T2_LogIn)
iret = iim1.iimGetStopwatch(3,idName,T3_ControleProcessos)
iret = iim1.iimGetStopwatch(4,idName,T4_LogOff)

dim hoje

hoje = Now()

WScript.Echo "Passos executados em " & total & " segundos Executado em: " & hoje & " | T1_PaginaInicial=" & T1_PaginaInicial & "s;;;0; T2_LogIn=" & T2_LogIn & "s;;;0; T3_ControleProcessos=" & T3_ControleProcessos & "s;;;0; T4_LogOff=" & T4_LogOff & "s;;;0; Total=" & total & "s;;;0;"
WScript.Quit(0)
chivracq
Posts: 8143
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Identify Wich Step Has Failed

Post by chivracq » Fri May 04, 2018 5:31 pm

Ervella wrote:Ah, I got it...
Well, i separated the macro in a few sub-macros, AND, now I can get the step where are the error. However, the time of each step isn't getting computed.
The above code maybe seen nailed-up, but I'll improve it later...

Code: Select all

Option Explicit


Dim macro, macro1, macro2, macro3, macro4


macro1 = "VERSION BUILD=10002738" + vbNewLine 
macro1 = macro1 + "TAB T=1     " + vbNewLine 
macro1 = macro1 + "TAB CLOSEALLOTHERS " + vbNewLine 
macro1 = macro1 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
macro1 = macro1 + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine
macro1 = macro1 + "URL GOTO=URL" + vbNewLine
macro1 = macro1 + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine

macro2 = macro2 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
macro2 = macro2 + "STOPWATCH ID=T2_LogIn" + vbNewLine
macro2 = macro2 + "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmLogin ATTR=NAME:txtUsuario CONTENT=USER" + vbNewLine
macro2 = macro2 + "SET !ENCRYPTION NO" + vbNewLine
macro2 = macro2 + "TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:frmLogin ATTR=NAME:pwdSenha CONTENT=PASS" + vbNewLine
macro2 = macro2 + "TAG POS=1 TYPE=BUTTON:SUBMIT FORM=NAME:frmLogin ATTR=NAME:sbmLogin" + vbNewLine
macro2 = macro2 + "STOPWATCH ID=T2_LogIn" + vbNewLine

macro3 = macro3 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
macro3 = macro3 + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine
macro3 = macro3 + "TAG POS=1 TYPE=A ATTR=TXT:Controle<SP>de<SP>Processos" + vbNewLine
macro3 = macro3 + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine

macro4 = macro4 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
macro4 = macro4 + "STOPWATCH ID=T4_LogOff" + vbNewLine
macro4 = macro4 + "TAG POS=1 TYPE=IMG ATTR=SRC:URL/sair.gif" + vbNewLine
macro4 = macro4 + "STOPWATCH ID=T4_LogOff" + vbNewLine


Dim iim1, iret, iplay1, iplay2, iplay3, iplay4, errortext

set iim1= CreateObject ("imacros")

iret = iim1.iimOpen ("-kioskmode",true)
iret = iim1.iimDisplay("Get Response Times")

iplay1 = iim1.iimPlayCode(macro1)
errortext= iim1. iimGetErrorText()
If iplay1 < 0 Then
    WScript.Echo "CRITICAL: The following error occurred in step T1_PaginaInicial: " + errortext + vbNewLine
	iret = iim1.iimClose
	WScript.Quit(2)
End If
iplay2 = iim1.iimPlayCode(macro2)
errortext= iim1. iimGetErrorText()
If iplay2 < 0 Then
    WScript.Echo "CRITICAL: The following error occurred in step T2_LogIn: " + errortext + vbNewLine
	iret = iim1.iimClose
	WScript.Quit(2)
End If
iplay3 = iim1.iimPlayCode(macro3)
errortext= iim1. iimGetErrorText()
If iplay3 < 0 Then
    WScript.Echo "CRITICAL: The following error occurred in step T3_ControleProcessos: " + errortext + vbNewLine
	iret = iim1.iimClose
	WScript.Quit(2)
End If
iplay4 = iim1.iimPlayCode(macro4)
errortext= iim1. iimGetErrorText()
If iplay4 < 0 Then
    WScript.Echo "CRITICAL: The following error occurred in step T4_LogOff: " + errortext + vbNewLine
	iret = iim1.iimClose
	WScript.Quit(2)
End If

Dim idName
Dim T1_PaginaInicial,T2_LogIn,T3_ControleProcessos,T4_LogOff,total

iret = iim1.iimGetStopwatch(1,idName,T1_PaginaInicial)
iret = iim1.iimGetStopwatch(2,idName,T2_LogIn)
iret = iim1.iimGetStopwatch(3,idName,T3_ControleProcessos)
iret = iim1.iimGetStopwatch(4,idName,T4_LogOff)

dim hoje

hoje = Now()

WScript.Echo "Passos executados em " & total & " segundos Executado em: " & hoje & " | T1_PaginaInicial=" & T1_PaginaInicial & "s;;;0; T2_LogIn=" & T2_LogIn & "s;;;0; T3_ControleProcessos=" & T3_ControleProcessos & "s;;;0; T4_LogOff=" & T4_LogOff & "s;;;0; Total=" & total & "s;;;0;"
WScript.Quit(0)
Euh, yep..., but you need to fire each 'iimGetStopwatch()' directly after each 'iimPlay(Code)()', you can have different Stopwatch_ID's in a same (.iim) Macro, but all previous ones get "flushed" at the next Use of 'iimPlay(Code)()'..., so currently where you've placed your 4x 'iimGetStopwatch()' Commands in your Script, I would expect that you only get the last one about 'T4'.
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Ervella
Posts: 9
Joined: Thu May 03, 2018 7:56 pm

Re: Identify Wich Step Has Failed

Post by Ervella » Wed May 09, 2018 4:55 pm

Euh, yep..., but you need to fire each 'iimGetStopwatch()' directly after each 'iimPlay(Code)()', you can have different Stopwatch_ID's in a same (.iim) Macro, but all previous ones get "flushed" at the next Use of 'iimPlay(Code)()'..., so currently where you've placed your 4x 'iimGetStopwatch()' Commands in your Script, I would expect that you only get the last one about 'T4'.
That worked perfectly, thank you! I apologize for the inconvenience :D

Code: Select all

Option Explicit

SetLocale("es-sv")

Dim msg, errortext, iim1, iret

Main()

Sub showError(msg) 
	WScript.Echo msg + vbCrLf + "Erro: " + errortext + vbNewLine
	iret = iim1.iimClose
	WScript.Quit(2)
End Sub

Sub Main()
	Dim macro, macro1, macro2, macro3, macro4, idName, iplay1, iplay2, iplay3, iplay4, T1_PaginaInicial, T2_LogIn, T3_ControleProcessos, T4_LogOff
	set iim1= CreateObject ("imacros")
	iret = iim1.iimOpen ("-kioskmode",true)
	iret = iim1.iimDisplay("Get Response Times")
	
	macro1 = "VERSION BUILD=10002738" + vbNewLine 
	macro1 = macro1 + "TAB T=1     " + vbNewLine 
	macro1 = macro1 + "TAB CLOSEALLOTHERS " + vbNewLine 
	macro1 = macro1 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
	macro1 = macro1 + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine
	macro1 = macro1 + "URL GOTO=https://URL/sei/" + vbNewLine
	macro1 = macro1 + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine
	iplay1 = iim1.iimPlayCode(macro1)
	iret = iim1.iimGetStopwatch(2,idName,T1_PaginaInicial)
	errortext = iim1. iimGetErrorText()
	If iplay1 < 0 Then
		showError("CRITICAL: Ocorreu uma falha no acesso da página inicial (Passo = T1_PaginaInicial): ")
	End If

	macro2 = macro2 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
	macro2 = macro2 + "STOPWATCH ID=T2_LogIn" + vbNewLine
	macro2 = macro2 + "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmLogin ATTR=NAME:txtUsuario CONTENT=USR" + vbNewLine
	macro2 = macro2 + "SET !ENCRYPTION NO" + vbNewLine
	macro2 = macro2 + "TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:frmLogin ATTR=NAME:pwdSenha CONTENT=PASS" + vbNewLine
	macro2 = macro2 + "TAG POS=1 TYPE=BUTTON:SUBMIT FORM=NAME:frmLogin ATTR=NAME:sbmLogin" + vbNewLine
	macro2 = macro2 + "STOPWATCH ID=T2_LogIn" + vbNewLine
	iplay2 = iim1.iimPlayCode(macro2)
	iret = iim1.iimGetStopwatch(2,idName,T2_LogIn)
	errortext = iim1. iimGetErrorText()
	If iplay2 < 0 Then
		showError("CRITICAL: Ocorreu uma falha no login (Passo = T2_LogIn): ")
	End If

	macro3 = macro3 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
	macro3 = macro3 + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine
	macro3 = macro3 + "TAG POS=1 TYPE=A ATTR=TXT:Controle<SP>de<SP>Processos" + vbNewLine
	macro3 = macro3 + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine
	iplay3 = iim1.iimPlayCode(macro3)
	iret = iim1.iimGetStopwatch(2,idName,T3_ControleProcessos)
	errortext = iim1. iimGetErrorText()
	If iplay3 < 0 Then
		showError("CRITICAL: Ocorreu uma falha na busca do processo (Passo = T3_ControleProcessos) ")
	End If

	macro4 = macro4 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
	macro4 = macro4 + "STOPWATCH ID=T4_LogOff" + vbNewLine
	macro4 = macro4 + "TAG POS=1 TYPE=IMG ATTR=SRC:URL/imagens/sair.gif" + vbNewLine
	macro4 = macro4 + "STOPWATCH ID=T4_LogOff" + vbNewLine
	iplay4 = iim1.iimPlayCode(macro4)
	iret = iim1.iimGetStopwatch(1,idName,T4_LogOff)
	errortext = iim1. iimGetErrorText()
	If iplay4 < 0 Then
		showError("CRITICAL: Ocorreu uma falha no Logoff (Passo = T4_LogOff): ")
	End If

	Dim total
	total = CDbl(CCur(T1_PaginaInicial) + CCur(T2_LogIn) + CCur(T3_ControleProcessos) + CCur(T4_LogOff))
	iret = iim1.iimClose

	dim hoje

	hoje = Now()

	WScript.Echo "Passos executados em " & total & " segundos Executado em: " & hoje & " | T1_PaginaInicial=" & T1_PaginaInicial & "s;;;0; T2_LogIn=" & T2_LogIn & "s;;;0; T3_ControleProcessos=" & T3_ControleProcessos & "s;;;0; T4_LogOff=" & T4_LogOff & "s;;;0; Total=" & total & "s;;;0;"
	WScript.Quit(0)
End Sub	

chivracq
Posts: 8143
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Identify Wich Step Has Failed

Post by chivracq » Wed May 09, 2018 4:56 pm

Oh, good..., I see you are currently replying to this Thread, good-good...! :wink:

:arrow: Any chance you could edit your first Post in this Thread and use the ]CODE[ Meta-Tags to improve Readability of your Post/Thread, like I already asked...? :?:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
Posts: 8143
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Identify Wich Step Has Failed

Post by chivracq » Wed May 09, 2018 5:15 pm

Ervella wrote:
Euh, yep..., but you need to fire each 'iimGetStopwatch()' directly after each 'iimPlay(Code)()', you can have different Stopwatch_ID's in a same (.iim) Macro, but all previous ones get "flushed" at the next Use of 'iimPlay(Code)()'..., so currently where you've placed your 4x 'iimGetStopwatch()' Commands in your Script, I would expect that you only get the last one about 'T4'.
That worked perfectly, thank you! I apologize for the inconvenience :D

Code: Select all

Option Explicit

SetLocale("es-sv")

Dim msg, errortext, iim1, iret

Main()

Sub showError(msg) 
	WScript.Echo msg + vbCrLf + "Erro: " + errortext + vbNewLine
	iret = iim1.iimClose
	WScript.Quit(2)
End Sub

Sub Main()
	Dim macro, macro1, macro2, macro3, macro4, idName, iplay1, iplay2, iplay3, iplay4, T1_PaginaInicial, T2_LogIn, T3_ControleProcessos, T4_LogOff
	set iim1= CreateObject ("imacros")
	iret = iim1.iimOpen ("-kioskmode",true)
	iret = iim1.iimDisplay("Get Response Times")
	
	macro1 = "VERSION BUILD=10002738" + vbNewLine 
	macro1 = macro1 + "TAB T=1     " + vbNewLine 
	macro1 = macro1 + "TAB CLOSEALLOTHERS " + vbNewLine 
	macro1 = macro1 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
	macro1 = macro1 + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine
	macro1 = macro1 + "URL GOTO=https://URL/sei/" + vbNewLine
	macro1 = macro1 + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine
	iplay1 = iim1.iimPlayCode(macro1)
	iret = iim1.iimGetStopwatch(2,idName,T1_PaginaInicial)
	errortext = iim1. iimGetErrorText()
	If iplay1 < 0 Then
		showError("CRITICAL: Ocorreu uma falha no acesso da página inicial (Passo = T1_PaginaInicial): ")
	End If

	macro2 = macro2 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
	macro2 = macro2 + "STOPWATCH ID=T2_LogIn" + vbNewLine
	macro2 = macro2 + "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmLogin ATTR=NAME:txtUsuario CONTENT=USR" + vbNewLine
	macro2 = macro2 + "SET !ENCRYPTION NO" + vbNewLine
	macro2 = macro2 + "TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:frmLogin ATTR=NAME:pwdSenha CONTENT=PASS" + vbNewLine
	macro2 = macro2 + "TAG POS=1 TYPE=BUTTON:SUBMIT FORM=NAME:frmLogin ATTR=NAME:sbmLogin" + vbNewLine
	macro2 = macro2 + "STOPWATCH ID=T2_LogIn" + vbNewLine
	iplay2 = iim1.iimPlayCode(macro2)
	iret = iim1.iimGetStopwatch(2,idName,T2_LogIn)
	errortext = iim1. iimGetErrorText()
	If iplay2 < 0 Then
		showError("CRITICAL: Ocorreu uma falha no login (Passo = T2_LogIn): ")
	End If

	macro3 = macro3 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
	macro3 = macro3 + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine
	macro3 = macro3 + "TAG POS=1 TYPE=A ATTR=TXT:Controle<SP>de<SP>Processos" + vbNewLine
	macro3 = macro3 + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine
	iplay3 = iim1.iimPlayCode(macro3)
	iret = iim1.iimGetStopwatch(2,idName,T3_ControleProcessos)
	errortext = iim1. iimGetErrorText()
	If iplay3 < 0 Then
		showError("CRITICAL: Ocorreu uma falha na busca do processo (Passo = T3_ControleProcessos) ")
	End If

	macro4 = macro4 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI_V3\output.csv" + vbNewLine
	macro4 = macro4 + "STOPWATCH ID=T4_LogOff" + vbNewLine
	macro4 = macro4 + "TAG POS=1 TYPE=IMG ATTR=SRC:URL/imagens/sair.gif" + vbNewLine
	macro4 = macro4 + "STOPWATCH ID=T4_LogOff" + vbNewLine
	iplay4 = iim1.iimPlayCode(macro4)
	iret = iim1.iimGetStopwatch(1,idName,T4_LogOff)
	errortext = iim1. iimGetErrorText()
	If iplay4 < 0 Then
		showError("CRITICAL: Ocorreu uma falha no Logoff (Passo = T4_LogOff): ")
	End If

	Dim total
	total = CDbl(CCur(T1_PaginaInicial) + CCur(T2_LogIn) + CCur(T3_ControleProcessos) + CCur(T4_LogOff))
	iret = iim1.iimClose

	dim hoje

	hoje = Now()

	WScript.Echo "Passos executados em " & total & " segundos Executado em: " & hoje & " | T1_PaginaInicial=" & T1_PaginaInicial & "s;;;0; T2_LogIn=" & T2_LogIn & "s;;;0; T3_ControleProcessos=" & T3_ControleProcessos & "s;;;0; T4_LogOff=" & T4_LogOff & "s;;;0; Total=" & total & "s;;;0;"
	WScript.Quit(0)
End Sub	
Yep, very nice...! Thanks for sharing your Final Script, very "neat" Example of a nice '.vbs' Script with iMacros... :D
(There are not that many '.vbs' Script Samples on the Forum as most Users using the Scripting Interface have a Support License and have direct access to TechSupport and such "Cases" never reach the Forum..., so that's very useful for other Users...)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Ervella
Posts: 9
Joined: Thu May 03, 2018 7:56 pm

Re: Identify Wich Step Has Failed

Post by Ervella » Wed May 16, 2018 3:35 pm

chivracq wrote:Oh, good..., I see you are currently replying to this Thread, good-good...! :wink:

:arrow: Any chance you could edit your first Post in this Thread and use the ]CODE[ Meta-Tags to improve Readability of your Post/Thread, like I already asked...? :?:
Sure! It's done!
Ervella
Posts: 9
Joined: Thu May 03, 2018 7:56 pm

Re: Identify Wich Step Has Failed

Post by Ervella » Wed May 16, 2018 3:41 pm

By the way, I refined the script again (didnt know if I should translate to english):

Code: Select all

Option Explicit

SetLocale("es-sv")

Dim msg, errortext, iim1, iret, idName

Main()

'Função que coleta os dados de tempo de execução e status da execução da macro e os retorna como array
Function getData(macro, stepName)
	dim iplay
	iplay = iim1.iimPlayCode(macro)
	iret = iim1.iimGetStopwatch(2,idName,stepName)
	errortext = iim1. iimGetErrorText()	
	getData = Array(iplay, idName)
End Function

'Função que trata alguns dos status da execução da macro
Sub getError(pagina, iplay, idName)
	If iplay < 0 Then
		If iplay = -1300 or iplay = -1320 Then
			showError("CRITICAL: Um ou mais elementos do item '" + Pagina + "' não foram carregados conforme o esperado! (Passo = " + idName + ")")
		ElseIf iplay = -1350 Then
			showError("CRITICAL: O teste do item '" + Pagina + "' retornou um status HTTP 4xx/5xx! (Passo = " + idName + ")")			
		ElseIf iplay = -1930 Then
			showError("CRITICAL: A macro atingiu o tempo limite de resposta da página '" + Pagina + "'! (Passo = " + idName + ")")
		Else
			showError("CRITICAL: Ocorreu uma falha ao acessar a página '" + Pagina + "'! (Passo = " + idName + ")")
		End If
	End If
End Sub

'Função que constrói a mensagem de erro
Sub showError(msg) 
	WScript.Echo msg + vbCrLf + "Erro: " + errortext + vbNewLine
	iret = iim1.iimClose
	WScript.Quit(2)
End Sub

Sub Main()
	Dim data, macro01, macro02, macro03, macro04
	Dim T1_PaginaInicial, T2_LogIn, T3_ControleProcessos, T4_LogOff
	set iim1= CreateObject ("imacros")
	iret = iim1.iimOpen ("-kioskmode",true)
	iret = iim1.iimDisplay("Get Response Times")
	
	macro01 = "VERSION BUILD=10002738" + vbNewLine 
	macro01 = macro01 + "TAB T=1     " + vbNewLine 
	macro01 = macro01 + "TAB CLOSEALLOTHERS " + vbNewLine 
	macro01 = macro01 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI\output.csv" + vbNewLine
	macro01 = macro01 + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine
	macro01 = macro01 + "URL GOTO=https://URL/" + vbNewLine
	macro01 = macro01 + "STOPWATCH ID=T1_PaginaInicial" + vbNewLine
	'Passa como parâmetro o identificador da página testada, o status da execução da macro e o nome do stopwatch, respectivamente
	data = getData(macro01, T1_PaginaInicial)
	getError "Inicial", data(0), data(1)
	
	macro02 = macro02 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI\output.csv" + vbNewLine
	macro02 = macro02 + "STOPWATCH ID=T2_LogIn" + vbNewLine
	macro02 = macro02 + "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmLogin ATTR=NAME:txtUsuario CONTENT=USR" + vbNewLine
	macro02 = macro02 + "SET !ENCRYPTION NO" + vbNewLine
	macro02 = macro02 + "TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:frmLogin ATTR=NAME:pwdSenha CONTENT=PWD" + vbNewLine
	macro02 = macro02 + "TAG POS=1 TYPE=BUTTON:SUBMIT FORM=NAME:frmLogin ATTR=NAME:sbmLogin" + vbNewLine
	macro02 = macro02 + "STOPWATCH ID=T2_LogIn" + vbNewLine
	data = getData(macro02, T2_LogIn)
	getError "Login", data(0), data(1)
	
	macro03 = macro03 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI\output.csv" + vbNewLine
	macro03 = macro03 + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine
	macro03 = macro03 + "TAG POS=1 TYPE=A ATTR=TXT:Controle<SP>de<SP>Processos" + vbNewLine
	macro03 = macro03 + "STOPWATCH ID=T3_ControleProcessos" + vbNewLine
	data = getData(macro03, T3_ControleProcessos)
	getError "Controle de Processos", data(0), data(1)

	macro04 = macro04 + "SET !FILESTOPWATCH C:\opmon\scripts\SEI\output.csv" + vbNewLine
	macro04 = macro04 + "STOPWATCH ID=T4_LogOff" + vbNewLine
	macro04 = macro04 + "TAG POS=1 TYPE=IMG ATTR=SRC:https://URL/sair.gif" + vbNewLine
	macro04 = macro04 + "STOPWATCH ID=T4_LogOff" + vbNewLine
	data = getData(macro04, T4_LogOff)
	getError "LogOff", data(0), data(1)

	
	Dim Total
	'Força a conversão das Strings para Double
	Total = CDbl(CCur(T1_PaginaInicial) + CCur(T2_LogIn) + CCur(T3_ControleProcessos) + CCur(T4_LogOff))
	iret = iim1.iimClose

	dim hoje

	hoje = Now()

	WScript.Echo "Passos executados em " & Total & " segundos. Executado em: " & hoje & " | T1_PaginaInicial=" & T1_PaginaInicial & "s;;;0; T2_LogIn=" & T2_LogIn & "s;;;0; T3_ControleProcessos=" & T3_ControleProcessos & "s;;;0; T4_LogOff=" & T4_LogOff & "s;;;0; Total=" & Total & "s;;;0;"
	WScript.Quit(0)
End Sub	

Post Reply