Coded UI Tests : the recorder encountered a wrong control while recording the last action.

, , 1 Comment

One more quick post on Coded UI tests recording issue. Today, the coded UI test builder tool said to me “The recorder encountered a wrong control while recording the last action.” !

After some search in my app, I found out that it’is related to a ScrollViewer in a TabControl.

In this post we’ll see how I solved it…

The issue

The problem is easy to reproduce: inside a tabcontrol, add a TabItem and set its ContentTemplate with a DataTemplate containing a ScrollViewer. Then try to record any action inside the TabItem using the Coded UI Test Builder. You won’t be able to do it.

You can even set the ContentTemplate of the TabControl as pointed out on the Connect web site.

Here is an example of the XAML which does not work:
[xml]<TabControl Margin="0" x:Name="MainTabControl">
<TabItem Header="Tab">
<Button DockPanel.Dock="Bottom" Content="Youpi !"
Click="onButtonClick" />
<TextBox Text="a value " />

The solution

The solution is the same than for the TextBox issue : you have to create a fixed version of the ScrollViewer and use it instead of the standard one.

The fixed version simply provide an automation peer which returns true when the UI test framework ask him if it’s a ControlElement. Here is the regarding code :
[csharp]public class FixedScrollViewer : ScrollViewer
protected override AutomationPeer OnCreateAutomationPeer()
var peer = new FixedScrollViewerAutomationPeer(this);
return peer;

public class FixedScrollViewerAutomationPeer : ScrollViewerAutomationPeer
public FixedScrollViewerAutomationPeer(ScrollViewer target)
: base(target)

protected override bool IsContentElementCore()
var isContentElementCore = base.IsContentElementCore();
return isContentElementCore;

protected override bool IsControlElementCore()
//If in a template it returns false and it breaks the CUITB :'(
return true;

MS fix : Visual Studio 2011

This bug is on connect and Mathew Aniyan, the Visual Studio ALM program manager, noticed us that it will be fixed in the next version (VS2011 and Framework 4.5).



One Response

Comments are closed.