Microsoft Visual Studio 2012 provides complete record and play support through Coded UI for performing UI validations on Sharepoint 2010 applications.
Recording and playing back on a sharepoint application is no different from recording on any webpage on Internet Explorer as internally the Coded UI IE plugin is being used. This blog assumes that you are familiar with Coded UI Tests and know how to record, generate code and play it back. For further details on how to achieve the same, please take a look at the link provided.
While all actions recorded on Sharepoint 2010 should playback seamlessly, this blog enumerates a few minor workarounds that you may need for achieving the same.
- Working with Excel on Sharepoint 2010
- Recording actions on Visio\Powerpoint controls
- SharePoint Silverlight controls
1. Working with Excel on SharePoint 2010
With Visual Studio 2012, you can now record actions, generate code and play it back on Office 2010 controls within SharePoint 2010 as well. If you’re working on enabling automation for Office 2010 web parts then there are a few points to keep in mind.
Working with Excel, there are some limitations but they can be worked around by making minor changes in the code:-
If you are recording actions on an empty cell, then this action can be handcoded by double clicking on the cell and then performing a set text operation. This is needed because a click on the cell, followed by any keyboard action essentially activates the textarea within the cell. Simply recording a setvalue on the empty cell would search for the textarea which is in fact not present until the cell is clicked on. If you record a click followed by a setvalue, changing the Click to a DoubleClick in the generated code should do the trick.
Code
Eg:-
Mouse.DoubliClick(uiItemCell,new Point(31,14));
uiGridKeyboardInputEdit.Text=value;
If you are recording on a non-empty cell, then it gets a little more complicated, this is because the moment you add text to a cell, a new
- Go to cell initialization and make Row & Column Indexes as primary properties. These are in fact the best and most unique way to search for any cell.
this.mUIItemCell.SearchProperties[HtmlCell.PropertyNames.RowIndex]= "3";
this.mUIItemCell.SearchProperties[HtmlCell.PropertyNames.ColumnIndex]= "3";
2. Find the "HtmlDiv" child of this cell, you can use “InnerText” and “Class” properties for this.
private UITestControl
getControlToDoubleClick(HtmlCell cell)
{
if (String.IsNullOrEmpty(cell.InnerText))
return cell;
HtmlDiv pane = new HtmlDiv(cell);
pane.FilterProperties[HtmlDiv.PropertyNames.InnerText]= cell.InnerText;
// Class is an important property in finding pane
pane.FilterProperties[HtmlDiv.PropertyNames.Class]= "cv-nwr";
UITestControlCollection panes =pane.FindMatchingControls();
return panes[0];
}
3. Code Double-click on HtmlDiv. ( Eg: Mouse.DoubleClick(uIItemPane, new Point(31, 14)); )
4. SetText on TextArea. (Eg: uIGridKeyboardInputEdit.Text = value; } )
Known Issue:- Trying to record an action where we set some value to any cell, followed by an arrow key to navigate will fail to playback correctly.
2. Recording actions on Visio\PowerPoint controls
Recording on Visio\PowerPoint controls is currently not supported.
3. SharePoint Silverlight Controls
If your SharePoint application contains Silverlight web parts then the approach to test the same is slightly different. Visual Studio 2012 itself does not support Silverlight testing, but you can install a Silverlight plugin from VS Gallery to test the same.
Steps involved in setting up your machine for testing Silverlight Web parts in Sharepoint 2010:-
- Ensure that your machine has Visual Studio 2012 installed.
- Install the MicrosoftVisual Studio UI Test Plugin for Silverlight
- Install Fiddler. This is nothing but a tool to capture the http traffic and logs it.
- Download the fiddlerXap project given at the end of this document. Unzip it, build it and run the “CopySLHelper.bat” script to install the helper dlls required to test Silverlight web parts using the fiddler tool.
With this your machine setup is done. To start testing on any Silverlight application, all you need to do is this:-
- Setup the machine like mentioned above.
- Start fiddler.
- Clear browser cache.
- Launch the webpage.
- Start the recorder and generate code as you would for a regular web application testing.
- You would see that the generated code references the Microsoft.VisualStudio.TestTools.UITest.Extension.Silverlight.dll.
For more details on how Recording on Silverlight controls work, you can refer to the following:-
- Understanding the Search logic for Silverlight controls in Coded UI Test
- Fetching Property of a Silverlight control
- Content Index for Coded UI Test