Jump to content
CaptainBeardsEyesBeard

Hey Guys, How do you check that you've done an action you wanted?

Recommended Posts

CaptainBeardsEyesBeard

For example if you look at one of my tests you can see I'm just doing MouseClicks and SEND commands to input data.

 

But for example how would I write a test like you would in C# with Try/CAtch

for eg:

Try

{click_a_field}

Catch (exception)

{If can't click this exact field exit test}

 

FUNC TEST10_Add_Costs_To_A_Matter($MatterNumber, $DateWorked, $Timekeeper, $Currency, $LocationCode, $CostCode, $Rate, $AuthorisedTax)

Navigation_Click_Billing_Manager()
Navigation_Click_Billing_Manager_Costs()
Navigation_Click_Billing_Manager_Costs_CostsEntry()

WinActivate("Cost Entry") ; Focus Time window
Sleep(2000)

;Click Go button
Send("{TAB}")
Sleep(1000)
Send("{ENTER}")
Sleep(2000)

WinActivate("New Costcard") ; Focus Time window
Sleep(4000)
Send($MatterNumber)
Send("{TAB}")
Sleep(3000)
Send($DateWorked)
Send("{TAB}")
Sleep(1000)
Send($Timekeeper)
Send("{TAB}")
Sleep(5000)
Send($Currency)
Sleep(3000)

If ($Currency = "AUSD" OR $Currency = "EUR" OR $Currency = "CAN" OR $Currency = "HKD" OR $Currency = "NZD") then
   Send("{TAB}")
   Sleep(1000)
   Send($Rate)
   Sleep(1000)
   Send("{TAB}")
   Sleep(1000)
   Send($Rate)
   Send("{TAB}")
   Sleep(1000)
Else

EndIf

Sleep(1000)
Sleep(1000)
;Send($LocationCode)
Send("{TAB}")
Send("{TAB}")
Sleep(1000)
Send("{Down}")
Send("{TAB}")
Sleep(1000)
Send($CostCode)
Send("{TAB}")
Sleep(1000)
;Send($AuthorisedTax)
Send("{TAB}")
Send($Rate)
Sleep(3000)

Local $hWnd = WinWait("Cost Entry", "", 10)
;obtain the text in that window which should be "Successfully Saved records for RSA1"
Local $RecordSaveSuccess = ControlGetText($hWnd, "", "ThunderRT6FormDC")
Sleep(1000)
if StringInStr($RecordSaveSuccess, $MatterNumber) then
   MsgBox($MB_SYSTEMMODAL, "Test" & $TestCount & "  Result", "Test Passed, Timekeeper Saved", 4)
      FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new Cost entry using " & $MatterNumber& "    Ensure Timekeeper saves     " & $RecordSaveSuccess & " Test Passed")

   Else
   MsgBox($MB_SYSTEMMODAL, "Test" + $TestCount & " Result", "Test Failed", 4)
         FileWrite($hFilehandle, @CRLF & "Test" & $TestCount & " Create a new Cost entry using " & $MatterNumber& " Ensure timekeeper saves     Test Failed" & $RecordSaveSuccess)


EndIf

Sleep(1000)
ControlClick("New Costcard", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:7;]")  ;click ok
Sleep(1000)




WinActivate("New Costcard") ; Focus Time window
Sleep(1000)
WinClose("New Costcard")  ; Close window

Sleep(1000)
WinActivate("Cost Entry") ; Focus Time window
Sleep(1000)
WinClose("Cost Entry")  ; Close window

Navigation_Click_Billing_Manager_Costs()
Navigation_Click_Billing_Manager()

$TestCount = $TestCount + 1


EndFunc

 

Share this post


Link to post
Share on other sites
FrancescoDiMuro
5 hours ago, CaptainBeardsEyesBeard said:

But for example how would I write a test like you would in C# with Try/CAtch

for eg:

Try

{click_a_field}

Catch (exception)

{If can't click this exact field exit test}

If, Return Values, @error codes... :)

 

Best Regards.


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Earthshine

could also use a switch statement


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
orbs

for the OP using mainly Send(), checking @error and return value is moot - Send() does not return any, see the help file.

when sending text into input fields of a foreign application, off-hand i'd say the proper validation method would be to capture the text of the window - i.e. WinGetText() - before and after the insertion of text, so you can see that the desired text was indeed typed in, and in the desired position. this may not always be possible, and requires a considerable amount of trial and error.

 

Share this post


Link to post
Share on other sites
jdelaney
Posted (edited)

That's a great question to becoming a good automater. ..rather than just doing actions and expecting an outcome, you can do an action and verify the outcome.  rinse and repeat if failed.

 

It's much easier to do with controlsettext and controlgettext

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Earthshine

i wrap the functions, like with that WaitForControls stuff, that logs everything.


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
CaptainBeardsEyesBeard
Posted (edited)

Ah thanks. Wrapping functions in wait controls should be what I'm doing.

 

I've seen the @error thing before but unsure how to use it. Could you provide an example?

 

Edit: Also is there a way to "Exit" a function so if one test fails it just continues to the next?

Edited by CaptainBeardsEyesBeard

Share this post


Link to post
Share on other sites
FrancescoDiMuro

 @CaptainBeardsEyesBeard:)

Local $strInputBox = InputBox("InputBox", "Type Text here:")
If @error = 1 Then
    MsgBox($MB_ICONINFORMATION, "", "The Cancel button has been pressed.")
Else
    ; Instructions...
EndIf


Best Regards.


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

as long as you can intercept the error you can log it and move on, yes

I posted a snippet, not a real UDF by any means, but it can be expanded to wrap other controls,

WaitForControls.au3 which uses log4a.au3 for logger.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
jdelaney
Posted (edited)

Although more complex, I setup an infrastructure where I could pass in a variable of the test to run.   that way, If something does error out, the other tests can still be executed.   if they are all stringed together in one script, that is not possible.   it also makes debugging or reruning a specific test much easier

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×