user3528748
user3528748

Reputation: 21

Stale objects in Coded UI

To remove the stale object issue(ie..when we run the test script for multiple input,it fails for the second iteration as the object is not cleared at the end of each run)in my script, I have added always search configuration in the designer file. After this my script runs successfully on multiple inputs, but if there is a need to add some objects newly to the same designer file then my designer file will be regenerated and the Always search configuration changes will be lost.

Is there any way to retain the always search configuration remain in the designer file ever even when the designer file is regenerated?

Upvotes: 1

Views: 492

Answers (1)

huppopotamus
huppopotamus

Reputation: 102

When you generate a UI map there are actually two files that come with it. Firstly, as you've discovered, there's a generated file with all the ugly code that's generated by the coded UI test builder. Of course, making any changes to this outside of the code will regenerate the file. The second file is a partial class that accompanies the generated designer class. This file does NOT get regenerated but as a partial contains all the same object references and properties as the designer file (it just looks empty). You can reference the control you want to add this property to here and it will not be regenerated.

The other alternative to this, albeit probably not a good idea, is to put

        Playback.PlaybackSettings.AlwaysSearchControls = true 

inside of your test method/class initialize/test initialize. This will force the test(s) to always search for each and every control. As you might imagine, this can have a significant performance impact though when you're dealing with large UI maps or particularly long test methods.

You might also set the control object's search configuration to always search. Keep in mind that this will do searching for this control and all of it's children so I would not advise putting it on a parent with several children, such as the document.

        aControl.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);

Upvotes: 1

Related Questions