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.
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 <div> control gets added as a child of the cell which contains the text entered. The recorder records actions on the div which, before the text gets entered, doesn’t exist. In case case, follow the below steps:-
- 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.
2. Find the “HtmlDiv” child of this cell, you can use “InnerText” and “Class” properties for this.
HtmlDiv pane = new HtmlDiv(cell);
// Class is an important property in finding pane
UITestControlCollection panes =pane.FindMatchingControls();
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.
- Once you have the UI Test Plugin for Silverlight installed, check %ProgramFiles(x86)%\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages\SilverlightUIAutomationHelper and copy the right version of the SilverlightUIAutomationHelper dll based on whether you want to test on Silverlight 4.0 or 5.0 into the Unzipped fiddlerXapProxy folder.
- Run the “CopySLHelperSL4.bat” or “CopySLHelperSL5.bat” script to install the helper dlls required to test Silverlight web parts using the fiddler tool. This script simply copies the relevant dlls into the Fiddler folders. If you have Fiddler installed in any location other than Program Files, copy the files mentioned in the script into the relevant folder.
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