Coded UI testing is an automated test that drive your application through its user interface (UI) and gives you feedback about the health state of your application. SharePoint 2016 has a new feature which is called zero-downtime-patching; it simply means that you can patch your SharePoint 2016 servers without any downtime. You can use the same method to control the integrity of your SharePoint 2013 environment as well.
If you are an administrator of a large SharePoint farm, it is kind of hard to keep track of every services running on servers of your SharePoint 2016(or SharePoint 2013) farm. It is possible that after installing a patch on your SharePoint 2016 server in your farm, due to some conflicts, one of your services stop working. In this article I will introduce a method to create Automated UI testing via Coded UI testing project template of Visual Studio 2015. You can run these tests regularly on your farm after installing new patches and make sure that services remain intact while you upgrade.
This article assumes that you are already familiar with the Coded UI testing concepts. For more information about Coded UI testing, you can read the MSDN articles about this type of test: https://msdn.microsoft.com/en-us/library/dd286726.aspx
Step 1 – create the project
- Start Visual studio 2015 enterprise edition
- Click File -> New -> Project
- Expand Templates -> Visual C# , select Test and then select Coded UI test project, set name and location and hit OK
- “Generate Code for Coded UI test” dialog box appears, you can Cancel it at this stage
Now you have a ready project for Coded UI testing of SharePoint 2016 farm services!
I will briefly explain different sections of your test file:
/// Summary description for CodedUITest1
public class CodedUITest1
public void CodedUITestMethod1()
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
#region Additional test attributes
///Gets or sets the test context which provides
///information about and functionality for the current test run.
public TestContext TestContext
testContextInstance = value;
private TestContext testContextInstance;
Your test method default name is “CodedUITestMethod1”, you can change it to something more descriptive like “SharePoint2016ServicesCUIT” so you can better distinguish it among all of your other test cases. All of your tests and assertion method goes into this test method. You can add additional test methods just in case to test other parts of your SharePoint 2016 farm as well.
Step 2 – Create the coded UI test
Before we create the Coded UI test for SharePoint 2016 services, we have to grab the URL of the services page in SharePoint 2016 central administration. To do so, you have to:
- Browse to the Central Administration site
- Click on “Manage Services in this farm” under the “System Settings”
- Select Server and change your server to some other server (we do this to include the serverId query string in the URL”, you should have more than one sever in your farm for this item to appear)
- Copy the URL
The URL will be something like this:
Now we go back to the Visual Studio 2015 test project. To create the actual tests for SharePoint 2016 services, you have to right click inside your test method and select “Generate Code for Coded UI test” and then select “Use coded UI test builder”
- Click on the record button.
- Open the browser.
- Navigate to the service URL page in SharePoint 2016 central admin.(you already have this URL)
- Click on “pause the recording” button.
- Click on “Generate Code” button.
- Change the method name to a descriptive name like “SharePoint2016Services”
- Click on “Add and Generate” button
Step 3 – Assertion methods
Now you have to develop the assertion method to record the state of the services on your SharePoint 2016 environment. To do so:
- Drag the crosshair to the first service name on your list i.e. “Access Database Services” and release the mouse button over that. The selector selects the text of that cell.
- Use the “Move to parent control” button to select the whole row including the service name, status and action
- Select the “Inner Text” property. At this time it should be i.e. “your selected service name Started Stop” in SharePoint 2013 or “your selected service name Yes Manage Service Application Yes” in SharePoint 2016.
- Click on “Add Assertion” Button. Notice that the Comparator is AreEqual, and the comparison value is “Access Database Service Started Stop”
- Put some text in “Message on Assertion Failure” and click on OK
- Then click Generate Code button
- Give the method name a descriptive name like “AssertAccessService” and click on “Add and Generate” button
You have to repeat all the above 7 steps for all of your services in your SharePoint 2016 farm, let’s say if you have 17 services in your SharePoint 2016 server, you have to create 17 different assertion methods for every one of your services in SharePoint 2016. After completing all of your assertion methods, close the Coded UI test builder box to go back to visual studio.
Step 4 – Move codes
In this step, you will move the codes from UIMap box to UIMap.cs
- Double click on the UIMap.uitest file to open the dialog
- Select your first method from UI Actions section
- Review the steps, you can delete a step or do some modifications at this stage
- If everything is ok, click on Move code to UIMap.cs button
- Repeat the above steps for the next method
After moving all of your codes to the UIMap.cs, it is a good idea to run your test one time and see the result at this stage.
Now we have a complete Coded UI testing project to test the services in SharePoint 2016. This project can be used to keep track of the changes in services status of one server in SharePoint 2016 (or SharePoint 2013) farm. In the next post, I will change this project to add functionality to check the state of every server in the SharePoint 2016(or SharePoint 2013) farm.