Jump to content

Working with Windows forms - sometimes it gets the controlID text from a control ID and sometimes it's empty?!


Recommended Posts

So in my testing pack for testing an application I have the below function which I use. 

It takes a window handle, controlID, Text that should appear in the Control ID and the field being tested. 

So implemented it looks like..

CheckFieldEquals($M2Window, "WindowsForms10.STATIC.app.0.3ce0bb8_r21_ad183", "Correspondence Address :", "Program > Case Create > Test screen 3 > Test field containing:Correspondence Address : -   ControlID: WindowsForms10.STATIC.app.0.3ce0bb8_r21_ad183")

And the function looks like..

Func CheckFieldEquals($WindowHandle, $ControlID, $InputDescription, $FieldBeingTested)
      Local $FieldControlIDText= ControlGetText($WindowHandle, "",$ControlID )
   Sleep(4000)
   if $FieldControlIDText == $InputDescription then
      MsgBox($MB_SYSTEMMODAL, "Test Result for field    " & $FieldBeingTested, "Test Passed:" & $FieldControlIDText & " " & $FieldBeingTested & "  matches the following value received "& $FieldControlIDText, 1)
      FileWrite($TestLog, @CRLF & " Test Passed: " & $FieldControlIDText & " " &  $FieldBeingTested & "      matches the value expected " & $FieldControlIDText)
      FileWrite($TestResults, @CRLF &  " Test Passed: " & $FieldControlIDText & " " &  $FieldBeingTested & "     matches the value expected ")
      ConsoleWrite(@CRLF &  " Test Passed: " & $FieldControlIDText & " " &  $FieldBeingTested & "    matches the value expected ")

   Else
      MsgBox($MB_SYSTEMMODAL, "Test Result  ", "Test Failed:" & $FieldControlIDText & " " &  $FieldBeingTested & " doesn't match following value received "& $FieldControlIDText & "", 1)
      FileWrite($TestLog, @CRLF & " Test Failed:"& $FieldControlIDText & " " & $FieldBeingTested & "     doesn't match the following value retrieved " & $FieldControlIDText)
      FileWrite($TestResults, @CRLF & " Test Failed:"& $FieldControlIDText & " " & $FieldBeingTested & "     doesn't match the following value retrieved ")
      ConsoleWrite(@CRLF & " Test Failed:"& $FieldControlIDText & " " & $FieldBeingTested & "    doesn't match the following value retrieved " & $FieldControlIDText)
        WriteToConsoleAndLog("ControlGetText variable equals: " & $FieldControlIDText) 
       Sleep(4000)
    EndIf

EndFunc

 

However in my console log I check it doesn't populate the variable, which means the variable is empty? 

Test Failed: Program > Case Create > Test screen 3 > Test field containing:Correspondence Address : -   ControlID: WindowsForms10.STATIC.app.0.3ce0bb8_r21_ad183     doesn't match the following value retrieved 
ControlGetText variable equals: 
Exit code: 0

However when I use the screen autoit tool the controlID is still correct (attaching a screenshot of the window info screen) 

So how is my function not picking up the text via the ControlGetText function? 

image.png.301401f325141cfccf2ba6104c4d78fd.png

Link to comment
Share on other sites

Also to clarify I ran the test again and the test passed 

Test Passed: Correspondence Address : Visual files > Case Create > Test screen 3 > Test field containing:Correspondence Address : -   ControlID: WindowsForms10.STATIC.app.0.3ce0bb8_r21_ad183   matches the value expected

So trying to figure out why it fails a bunch of times and sometimes passes?

 

Also any tips on improving my function is appreciated!

Link to comment
Share on other sites

By value of the forms control do you mean the variable of ControlGetText

$FieldControlIDText= ControlGetText($WindowHandle, "",$ControlID )

That is logged toward end of the function on this line (my custom function just does a console write line and also writes to a text file 

WriteToConsoleAndLog("ControlGetText variable equals: " & $FieldControlIDText)

The value of the $FieldControlIDText when it fails is empty in the console and log. (Unless you meant something different that I should also be logging)

Link to comment
Share on other sites

are you waiting for the control to actually exist? it may fail if the form is not fully loaded and functional

 

i use a while loop and monitor for the existence of said control

Edited by Earthshine

My resources are limited. You must ask the right questions

 

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...