0

Using the recorder with Coded UI we test our UI for continuous integration purposes but we have hit a snag in that one of the actions we want to test is a delete action.

We check the list item we are going to delete exists, we then press delete, the delete command removes it from the collection that is being bound too, we assert that the list item no longer exists but it still says it does

We thought it might of took a few seconds to fully get rid of the object so we put a 20 second wait before asserting but still says it exists

The automation id's for the listitems are truly unique, they are made up of a string + the id of the number in the list + the value of the textblock in the list item, so it is definitely not getting confused with another element

Any thought's on this would be greatly appreciated?

Greg Stewart
  • 49
  • 1
  • 7
  • Well step one is to run the application and see if the delete button is removing objects (visually or whatnot). If your automation is checking to see if the object still exists in memory then either something else is still referencing it, or the garbage collector hasn't gotten to it yet, the former being a potentially larger issue – Gordon Allocman Mar 29 '16 at 17:38
  • What does the test do between delete and assert? Is the UI Map refreshed? Might the assert be finding old data? – AdrianHHH Mar 29 '16 at 21:01
  • @GordonAllocman The delete button is working as expected, it deletes the item from the observable collection and the view is updated as expected through the binding to the observable collection. As for maybe staying in memory - that was our initial thought hence the 20 second delay – Greg Stewart Mar 30 '16 at 17:07
  • @GregStewart waiting 20 seconds doesn't guarantee it will have been collected, it could stay around for much longer than that depending on how to program works and the exact implementation of garbage collection C# uses – Gordon Allocman Mar 30 '16 at 17:09
  • @AdrianHHH It does nothing between the delete and the assert, the view is updated automatically through the binding to the observable collection, other actions like updating a list item works and the assertions get the new value – Greg Stewart Mar 30 '16 at 17:11
  • @GordonAllocman We don't do anything extra with garbage collecting, just default behaviour. I thought this might be the case so wrote a method to garbage collect through out all generations once the delete is done and this still gives the same behaviour – Greg Stewart Mar 30 '16 at 17:13
  • @GregStewart are you sure you aren't referencing the object elsewhere? If it has truly been removed and collected then there is something wrong with your coded-ui tests in which case we couldn't give you a real answer without seeing the exact test or some code – Gordon Allocman Mar 30 '16 at 17:18
  • 1
    Have you tried refreshing the UI Map between delete and assert? – AdrianHHH Mar 30 '16 at 18:39
  • @AdrianHHH Thank you for both of your help and time, refreshing the ui map between the action makes this work, new lesson learned for the future. – Greg Stewart Mar 31 '16 at 10:35
  • @GordonAllocman Thank you for your help and time – Greg Stewart Mar 31 '16 at 10:36

1 Answers1

2

The UI Map in Coded UI keeps a cache of things it has seen before. Often this works well because it reduces the amount of searching that is need to find things. Sometimes the cache holds on to things that have been deleted. This appears to be the case with this question.

Refreshing the UI Map clears the cache and forces subsequent UI Map accesses to do another search. Thus repopulating the cache.

It is not necessary to clear the entire cache. Often just part of needs to be refreshed and that can be done by calling the ...Find() method on the relevant UI Control.

A similar problem is covered here in Stack Overflow and it also shows a way of understanding which part of the UI Map needs refreshing.

Community
  • 1
  • 1
AdrianHHH
  • 13,492
  • 16
  • 50
  • 87