November 1st, 2012

UI Testing SharePoint 2010 with Visual Studio 2012

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.

 

  1. Working with Excel on Sharepoint 2010
  2. Recording actions on Visio\Powerpoint controls
  3. 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 <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:-

  1. 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:-

  1. Ensure that your machine has Visual Studio 2012 installed.
  2. Install the MicrosoftVisual Studio UI Test Plugin for Silverlight
  3. Install Fiddler. This is nothing but a tool to capture the http traffic and logs it.
  4. Download the fiddlerXap project given at the end of this document. Unzip it, build it.
  5. 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.
  6. 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:-

  1. Setup the machine like mentioned above.
  2. Start fiddler.
  3. Clear browser cache.
  4. Launch the webpage.
  5. Start the recorder and generate code as you would for a regular web application testing.
  6. 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:-

  1. Understanding the Search logic for Silverlight controls in Coded UI Test
  2. Fetching Property of a Silverlight control
  3. Content Index for Coded UI Test

 

FiddlerXapProxy.zip

Category
DevOpsTest

0 comments

Discussion are closed.