Coded UI Testing SharePoint 2016 services with Visual Studio 2015 – Part 2

In Part 1 of this article, I explain a method that you can use to automate the testing of SharePoint 2016 services status in Central Administration with Visual studio 2015 Coded UI testing project. In part 2, I will continue on that platform to change the coded UI project to check the status of services of every server in SharePoint 2016 farm. If you need more information about the Coded UI testing, you can read the following articles on MSDN:

You can also use the same method to have the Coded UI testing on your SharePoint 2013 environment as well.

Step 1 – develop the XML files

You have to develop an XML file to act as the data source to your test method and put all the states of services in your SharePoint 2016 farm in one place. You can decide on the structure of your XML file, there is no predefined structure. But it is a good idea to develop a well-structured XML for this purpose.

all services

Here is my suggestion:

The above script works for SharePoint 2013 environment, you can develop one for your SharePoint 2016 environment as well. you have to change some text in order to use it for your SharePoint 2016 environment. For simplicity I just place the service state of two servers in this xml file. As you can see I have a <CentralAdmin> root node, below that I have <ServerServiceURL> node for each server in the SharePoint 2016 farm and I have an element for each service item. Inside the service item I placed the state of that service in the server which is available at the <URL> element. You have to develop the xml file for your own farm to continue the following steps.


Step 2 – Connect the XML file to the Coded UI test method

In order to connect your test method to the XML file to be able to check all servers in your SharePoint 2016 farm, you have to add this code before your method definition:

CA2016ServicesData.xml is the name of the xml file you created in the previous step. You have to add this file to your project and also change the properties of the file, so it will be copied to the output directory:


With the change you just made to your test method, you simply send the xml file as the data source to the test method and specify the xml element that should be iterated <ServerServiceURL>

Now if you run the test you see the test will be run two times for each node of <ServerServiceURL> in your xml file.

Step 3 – modify the test method and assertions

In order to test all the servers in your SharePoint 2016 farm, we have to change the method to read data from the XML file and pass those data to the corresponding assertion method. To do this I use the following code inside the test method:

By the above code, you can read information from your XML file in each iteration. You should have a separate string variable for every service you have in your farm and also a string variable to read the URL of the service page in the central administration.

Now you have to change the corresponding methods in the UIMap.cs file.

Browse UIMap.cs file, locate the test method, and set the URL parameter as the input parameter and change the method to read from the URL in order to navigate to the URL. The end result for this method should be something like this:

Now in the UIMap.cs file, you have to locate the assertion method for each service and change it accordingly. For example:

You have to do the following modifications to these methods:

  1. Define an input variable, this input variable will pass the inner text of the service status to the method
  2. Change the Assert.AreEqual method to check the actual value to this parameter, so you have to change the first parameter of this method to the input parameter
  3. Add the .Trim() to the InnerText of the second parameter

You have to do the above modifications to all the assertion methods in your UIMap.cs file. Here are some examples:

After completing the modifications of these methods you have to go back to your test method and send the values from the XML file to these methods, here are some examples:

After modifying this file, you can build your project and run your test. As you see the Coded UI test is now browse to every server in your SharePoint 2016 farm and check the status of services there. It is a very good idea to enable HTML logging of the Coded UI test in your Visual Studio 2015 project as well to have a visual confirmation of the test as well.

You can use the same method to automate the testing of other Central Administration pages in SharePoint 2016 as well. Moreover, this technic can be used in other versions of SharePoint as well.


MCSE, PMP, With more than 12 years experience in Microsoft technologies.

View all posts by

Leave a Reply