CaptainBeardsEyesBeard Posted April 13, 2022 Share Posted April 13, 2022 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? Link to comment Share on other sites More sharing options...
CaptainBeardsEyesBeard Posted April 13, 2022 Author Share Posted April 13, 2022 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 More sharing options...
Earthshine Posted April 13, 2022 Share Posted April 13, 2022 when it fails, what is the value of the forms control? you should be logging everything to help you debug My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
CaptainBeardsEyesBeard Posted April 14, 2022 Author Share Posted April 14, 2022 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 More sharing options...
Earthshine Posted April 14, 2022 Share Posted April 14, 2022 (edited) 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 April 14, 2022 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
ad777 Posted April 16, 2022 Share Posted April 16, 2022 Try the following if didn't work: https://www.autoitscript.com/forum/topic/206871-not-able-to-read-test-in-tgroupbox-class-control/?do=findComment&comment=1493918 iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now