Jump to content

Missing commands after function call


crushyna
 Share

Recommended Posts

Hello Everyone!

I'm new here on forums and completely new into AutoIt language (although I have some VBA/C++ scripting behind me). I'm after few basic tutorials, studying examples, and my few own first scripts.
We're currently looking for some simple test software, and I was ordered to look more into AutoIt (as it can become very useful in our regression tests), and just test its functionality.
(FYI: it's POS software).

I'm having problem with commands after exiting function.
Here's the function that checks if the error occurs (in this case - wrong product number) - if it does, it asks for decision.

Func CheckProduct()
Local $Answer
If ControlCommand("","","[CLASS:WindowsForms10.Window.8.app.0.21093c0_r12_ad1; NAME:panelMsgBox]", "IsEnabled", "") Then
   Sleep($Sleep_05)
   $Answer = MsgBox(52, "Error!", "Product not found. Continue testing?")
   Sleep($Sleep_05)
   Switch $Answer
      Case 6
      MsgBox(0, "Error!", "Test will now continue.", 3)
      Send("{Enter}")
      WinActivate("TP.net POS")
      Return(0)
      Case 7
      MsgBox(64, "Error", "Test canceled.", 5)
      Exit(0)
   EndSwitch
EndIf
EndFunc

It's designed as a function - so we'll be able to use it every time after entering product number.

After that, we have some examples of entering product numbers into the system. So after each "Enter" there's product-check function.

ControlClick("TP.net POS", "", $ProductID)
ControlSend("[CLASS:WindowsForms10.Window.8.app.0.21093c0_r12_ad1]", "", "[CLASS:WindowsForms10.EDIT.app.0.21093c0_r12_ad1]", "5")
ControlClick("TP.net POS", "", $Multiply)
  Sleep($Sleep_075)
ControlSend("[CLASS:WindowsForms10.Window.8.app.0.21093c0_r12_ad1]", "", "[CLASS:WindowsForms10.EDIT.app.0.21093c0_r12_ad1]", "10400")
ControlClick("TP.net POS", "", $Enter)
   Call("CheckProduct")
   Sleep($Sleep_075)
ControlSend("[CLASS:WindowsForms10.Window.8.app.0.21093c0_r12_ad1]", "", "[CLASS:WindowsForms10.EDIT.app.0.21093c0_r12_ad1]", "10")
ControlClick("TP.net POS", "", $Enter)
   Call("CheckProduct")
   Sleep($Sleep_075)
ControlSend("[CLASS:WindowsForms10.Window.8.app.0.21093c0_r12_ad1]", "", "[CLASS:WindowsForms10.EDIT.app.0.21093c0_r12_ad1]", "10200")
ControlClick("TP.net POS", "", $Enter)
   Call("CheckProduct")
   Sleep($Sleep_075)

   Send("Company{Enter}")
   Send("IT{Enter}")
   Send("Country{Enter}")
   Send("Street{Enter}{Enter}")
   Sleep($Sleep_075)

Product "10" doesn't exist in our database, so it'll trigger warning message. It works fine. Even function exit works properly.
Although after selecting "Yes", the test continues, but it jumps over product "10200" and starts filling invoice (product 10200 requires invoice).

Any idea why? I suppose it has simple explanation, though I couldn't find anything about this :(
Thanks in advance!

Link to comment
Share on other sites

Func CheckProduct() returns all times with 0, exept MsgBox answer is no. You have to return 1 for the case product was found:

Func CheckProduct()
    Local $Answer
    If ControlCommand("", "", "[CLASS:WindowsForms10.Window.8.app.0.21093c0_r12_ad1; NAME:panelMsgBox]", "IsEnabled", "") Then
        Sleep($Sleep_05)
        $Answer = MsgBox(52, "Error!", "Product not found. Continue testing?")
        Sleep($Sleep_05)
        Switch $Answer
            Case 6
                MsgBox(0, "Error!", "Test will now continue.", 3)
                Send("{Enter}")
                WinActivate("TP.net POS")
                Return
            Case 7
                MsgBox(64, "Error", "Test canceled.", 5)
                Exit
        EndSwitch
    EndIf
    Return 1
EndFunc   ;==>CheckProduct

and after each execution fo Checkproduct you have to test the returned result and depending further executing what's needed for this result.

Link to comment
Share on other sites

Hey!
Just fixed this script as you did, but still it does jump over product 10200 and keeps filling invoice :/
And what do You mean by "test the returned result and depending further executing what's needed for this result"? Don't really follow You here :D

Link to comment
Share on other sites

30 minutes ago, crushyna said:

And what do You mean by "test the returned result and depending further executing what's needed for this result"? Don't really follow You here :D

if Call("CheckProduct") Then
    ;code executing whats to do when Product is found
Else
    ;code executing what's to do when Product isn't found
EndIf

i don't know the app you are automating  but it's also possible that

ControlClick("TP.net POS", "", $Enter)

should only be done in one of both cases. I can't check logic of your script, that's your turn. But i can see you have no error checking and i'am wondering about

If ControlCommand("", "", "[CLASS:WindowsForms10.Window.8.app.0.21093c0_r12_ad1; NAME:panelMsgBox]", "IsEnabled", "") Then

you are using ControlCommand without Title/Hwnd, so maybe the result is wrong.

Link to comment
Share on other sites

Ok it's working now :)
I've wrote current program window into handler, changed it everywhere and fixed few "sleep" times - works fine now.
It does actually check for errors. On every move / sum / enter, there's "CheckProduct" function - which actually works with every "warning" message box this program produce (same control class). So now it's perfect!

Thanks alot! :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...