I have a method where if the a specific dialog box is VisibleOnScreen it will click the ok button and carry on else it just carries on as normal. This dialog box is just a warning that the software being tested was closed incorrectly last time it was used. It not guaranteed to show up every time you run a test but it will only ever appear at this one specific time I run this method.
The issue occurs when the dialog box does not appear but since I have a variable which is set to that dialog box, if gives an error since it couldnt get the dialog box and carries on with the rest of the test. How do I get around this issue. Here is an example of what I mean.
Sub OKClick
Set DialogBox = Sys.Process("softwareBeingTested")....etc
If DialogBox.VisibleOnScreen Then
'click ok button
Else Log.Message "No dialog box appeared
End If
End Sub
Solved! Go to Solution.
Replace
If Sys.Process("SoftwareBeingTested").WPFObject("HwndSource: PopupRoot", "").WPFObject("PopupRoot", "", 1).WPFObject("Decorator", "", 1).WPFObject("NonLogicalAdornerDecorator", "", 1).WPFObject("Grid", "", 1).Exists
with
If Sys.Process("SoftwareBeingTested").WPFObject("HwndSource: PopupRoot", "").WPFObject("PopupRoot", "", 1).WPFObject("Decorator", "", 1).WPFObject("NonLogicalAdornerDecorator", "", 1).WaitWPFObject("Grid", "", 1, 20000).Exists
Again, same deal... WPFObject("Grid", "", 1), if it doesn't exist, doesn't even have the property "Exists". You can't check a property of an object where there is no object... so, you need to utilize code to return something FIRST to determine if it exists.
Your "Set" call... are you using anything like a WaitChild or FindChild or anything to find the Dialog box? The reason I ask is that you cannot call the "VisibleOnScreen" property of an object that does not exist. Your Set call, if the dialog isn't actually extant in memory of your application, will return a Null value which HAS no properties. You should always check for "Exists" before you attempt to interact.
No, what I have in my example is exactly what I have in my method. So would the following work
Set U=Sys.Process("softwareName").WPFObject("HwndSource: PopupRoot", "").WPFObject("PopupRoot", "", 1).WPFObject("Decorator", "", 1).WPFObject("NonLogicalAdornerDecorator", "", 1).WPFObject("Grid", "", 1).WaitChild("softwareName",2000)
If U.VisibleOnScreen Then
Sys.Process("softwareName").WPFObject("HwndSource: PopupRoot", "").WPFObject("PopupRoot", "", 1).WPFObject("Decorator", "", 1).WPFObject("NonLogicalAdornerDecorator", "", 1).WPFObject("Grid", "", 1).WPFObject("messagecontent").WPFObject("grid1").WPFObject("Border", "", 1).WPFObject("StackPanel", "", 1).WPFObject("StackPanel", "", 1).WPFObject("left").Click()
Log.Message" Button was clicked"
Else Log.Message" Button was not clicked"
End If
Hi,
Robert just said what you need, even you check the "exists" then the "visible" in a nested condition, even you use wait methods that accepts to wait for objects that may not exist.
No, it will still not work. If WaitChild returns and fails to find the designatated object, WaitChild returns an empty object which has no methods and only a single property, that being the "Exists" property set to False. So, you cannot check "VisibleOnScreen" on the result of WaitChild... you should still check for "Exists" first before you do any additional checks or processes.
Ok, I think I understand better, I was overcomplicating it prior. This is what I currently have, I am checking if the dialogbox exists and if it does then it checks is it visible and if so clicks the button else carries on as normal.
If Sys.Process("SoftwareBeingTested").WPFObject("HwndSource: PopupRoot", "").WPFObject("PopupRoot", "", 1).WPFObject("Decorator", "", 1).WPFObject("NonLogicalAdornerDecorator", "", 1).WPFObject("Grid", "", 1).Exists Then
Set U=Sys.Process("SoftwareBeingTested").WPFObject("HwndSource: PopupRoot", "").WPFObject("PopupRoot", "", 1).WPFObject("Decorator", "", 1).WPFObject("NonLogicalAdornerDecorator", "", 1).WPFObject("Grid", "", 1)
If U.VisibleOnScreen Then
Sys.Process("SoftwareBeingTested").WPFObject("HwndSource: PopupRoot", "").WPFObject("PopupRoot", "", 1).WPFObject("Decorator", "", 1).WPFObject("NonLogicalAdornerDecorator", "", 1).WPFObject("Grid", "", 1).WPFObject("messagecontent").WPFObject("grid1").WPFObject("Border", "", 1).WPFObject("StackPanel", "", 1).WPFObject("StackPanel", "", 1).WPFObject("left").Click()
Log.Message" Button was clicked"
Else Log.Message"Button was clicked"
End If
Else Log.Message" Dialog box did not exist"
End If
But even with checking at the very beginning if the dialog box exists I am still getting an error whenever I start the test and the dialog box does not appear, the code works fine if it does appear.
Replace
If Sys.Process("SoftwareBeingTested").WPFObject("HwndSource: PopupRoot", "").WPFObject("PopupRoot", "", 1).WPFObject("Decorator", "", 1).WPFObject("NonLogicalAdornerDecorator", "", 1).WPFObject("Grid", "", 1).Exists
with
If Sys.Process("SoftwareBeingTested").WPFObject("HwndSource: PopupRoot", "").WPFObject("PopupRoot", "", 1).WPFObject("Decorator", "", 1).WPFObject("NonLogicalAdornerDecorator", "", 1).WaitWPFObject("Grid", "", 1, 20000).Exists
Again, same deal... WPFObject("Grid", "", 1), if it doesn't exist, doesn't even have the property "Exists". You can't check a property of an object where there is no object... so, you need to utilize code to return something FIRST to determine if it exists.
Just as a side note... is there some reason why you're coding using the full name of the object and not utilizing NameMapping?
I have replaced the line of code with yours and I am still getting an error on that specific line which states "Unable to find the object WPFObject("HwndSource: PopupRoot", ""). " when the dialog box does not appear.
And to answer your side note I dont use name mapping on the recommendation of my project manager. Apparently there were issues or complications with it before so they just have decided against using it.
OK... then the existance problem is not with the final object in the object tree but with the first object off the application root. This is the danger with using the fullname like this in the absence of other engines built in to test complete. You still need to wait for objects to exist before proceeding. In this case, in a general outline, here's how I would code this.
1) I'm assuming there's an action that generates the popup in the first place. Perform that action
2) After the action is performed, put in place code that will detect using WaitNNN functionality or FindChild or other similar code (see previous links) to wait for the popup object to appear.
3) If the Popup appears within the designated wait time, proceed on to the rest of the code
4) If it does not, generate an error indicating the popup did not appear in the designated time
5) If Step 3 passes, you may still need to account for delays in object rendering for additional objects. Continue to use WaitNNN and Find functionality to detect objects before interaction.
Now.... all this MIGHT be moot if NameMapping is implemented. NameMapping automatically builds in the code for the "Auto-Wait Timeout" designated in Options | Current Project Properties | Playback. The methods you're using do not automatically wait, they assume the object is already available, hence the need for WaitNNN methods for processing.
I'd be curious to know what limitations or problems your project manager found with NameMapping to preclude it's use.
Subject | Author | Latest Post |
---|---|---|