Not sure if someone is still looking to find out how to best hand code the Coded UI tests but imo going to the record and playback route is going to be disappointing later on! Best way is to create an automation framework which defines individual objects which you want to interact with and have the page objects to handle your business logic. If you are testing web applications you can define objects using generic UITestControls or HtmlControls. For example:
public static UITestControl EditBox_Password
{
get
{
if ( mEditBox_Password == null || ! mEditBox_Password.Exists )
{
mEditBox_Password = new UITestControl (browserWindow );
mEditBox_Password.TechnologyName = "Web";
mEditBox_Password.SearchProperties.Add (UITestControl.PropertyNames.ControlType , "Edit");
mEditBox_Password.SearchProperties.Add ( UITestControl.PropertyNames.Name , "TxtPassword");
}
return mEditBox_Password ;
}
}
If you are testing Windows-based applications then you can define objects using WinControls or WpfControls.
I recently bought a book on Amazon (Hand Coding Coded UI) which clearly defines how to setup the framework and create an easily maintainable code. Not sure if it is available in any book store but here is the link on Amazon if you want to have a look
https://www.amazon.com/dp/1547000856/ref=sr_1_1?s=books&ie=UTF8&qid=1496767488&sr=1-1&keywords=1547000856
I hope it is helpful.
Updated: Just googled it and there is a discount code for the book at http://www.arkenstone-ltd.com/testing-with-coded-ui/