In the previous chapters of the book we discussed automation of functional testing using Selenium and Visual Studio and getting the test automations running with CI/CD pipelines. For any application, it is essential to go through load and performance testing, before getting it to the production. Ideally these tests should be performed in an environment similar to the production environment in order to identify any issues in the pre-production stage.
However, the focus of this chapter is to guide you to get you started on the load and performance testing in cloud. For authoring and executing these tests, we would be using Visual Studio, Azure, and Azure DevOps. Furthermore, you can learn how to generate load from multiple regions and test your application by using real world scenarios.
Lesson 7.01: Load Test with Visual Studio and Azure DevOps
In this lesson, let’s author the load tests with Visual Studio and run them as cloud-based load testing using Azure DevOps.
Prerequisites: You need to run Visual Studio 2017 on Windows 10 or on Windows Server 2012 R2 or a newer version of the Windows server. You must have an Azure DevOps account. You must be familiar with Azure DevOps and using the Team Explorer in Visual Studio.
Install Web Performance and Load Testing Tools Components in Visual Studio 2017
You can install web performance and load test components while you Install Visual Studio. If you haven’t installed this component yet, you can install as described here:
1.
Launch Visual Studio Installer.
2.
In the Visual Studio Installer, move to Individual components and select web performance and load testing tools under the Debugging and testing section (see Figure 7-1).
3.
Click on the Modify button to apply the changes to the Visual Studio.
Setting Up Visual Studio Web Performance and Load Test Project
Let’s begin with setting up Visual Studio web performance and loading the test project following the steps described here.
1.
In Visual Studio 2017, select Files ➤ New ➤ Project
2.
In the New Project pop-up window, select Test under Visual Studio C#, and select Web Performance and Load Test project from the test project list. Give a Name to the Project, specify a Solution Name, select Location, and click on the OK button. Leaving Create directory for solution checked will allow you to have a new directory created for the new solution in the selected location (see Figure 7-2).
3.
After creating a new web performance test project, you can find project items in the Solution Explorer as follows (see Figure 7-3).
4.
Now we can record a web performance test. To record the performance of the web application, the Internet Explorer browser is configured as the default browser. If the Web Test Recorder add-on in the browser is disabled, recording action cannot be performed. So, let’s enable the Web Test Recorder add-on in the browser before we proceed into the next steps. Open the Internet Explorer browser and open the Manage add-ons in browser settings (see Figure 7-4).
5.
The Manage Add-on window will be displayed. Select the web test recorder and enable it by clicking the Enable button (see Figure 7-5).
6.
With the Web Test Recorder enabled, let’s try to record user actions in the web application. To do that, open Web Test1.webtest file.
After you click on the Add Recording icon, the browser will open and give the URL of the web application that needs to be tested.
8.
Perform the test steps and click on the stop icon to stop recording (see Figure 7-7).
9.
After you click on the stop icon, you can see the web test is created with a list of http requests (see Figure 7-8).
10.
Now you can change the web properties according to performance goals and save properties (see Figure 7-9). Note that we can set the response time goals as well if they are required to be set (see Figure 7-9).
11.
After setting the performance goals, run the web test (see Figure 7-10).
In this sample web test:
We should set the Response time of a specific request to be 2 seconds to achieve performance goals.
After the test execution is complete, the test result status is given as fail. But it still indicates the web request found the requested page.
You can select failed request and see all the relevant details. In the Details tab, you would be able to find the reason for failure as The response time (3.070 seconds) exceeded the response time goal of 2 seconds (see Figure 7-11).
It indicates that this test has failed because it took more time than our expected performance time goal.
Now you know how to create a web performance test and set performance goals. Likewise, you can change different properties and identify performance problems with the application.
Let’s add a load test file to this project. To add a load test file to the project, right-click on the project in the Solution Explorer and select Add ➤ Load Test (See Figure 7-12).
The load test wizard will be opened. Select Cloud-based load test and click on the Next button (see Figure 7-13). It is important for you to have the connection made to the required Team Project in Azure DevOps in the Visual Studio Team Explorer window. Based on the selected team Project in a given Azure DevOps organization, the Azure DevOps organization URL is auto-selected as Account in this Wizard step.
Note
On-premises load testing is deprecated in Visual Studio.
Then you can select the geographical location of the data center that is going to generate load in the tests. This is especially useful when you want to generate the load to your application from the geographical location of your application users, so that you measure the performance that would be experienced by your application end-users (see Figure 7-14).
You would be able to add different test settings throughout the wizard. You can add Test Mix, Network Mix, and Browser Mix along with other settings. In the wizard, you will find a page that allows you to add the web tests to the load test scenario. Click on the Add button (see Figure 7-15).
After you click on the Add button, the Add Tests pop-up will open. Select Test from the available test box and click on the arrow to put the test into the selected tests box (see Figure 7-16).
Continue wizard and click on Finish to create the load test. Now we have created a basic load test with a single web test. Let’s run the load test by right-clicking on the load test and selecting the Run Load Test (see Figure 7-17).
You can see that load test starts running. You will be able to see a window with all the graphical analysis charts (see Figure 7-18).
After the test run is complete, you will be able to see the summary window with all the analyzed data of the load test. The load test that we have run in this lesson actually runs in Azure DevOps, as we have specified it as a cloud-based load test (see Figure 7-19). The load test is created in the Azure DevOps Team Project, which is connected in the Team Explorer of the Visual Studio instance that you are using for this lesson.
In this lesson, we have explored how to author a load test using Visual Studio and run it as a cloud load test from the Visual Studio.
Lesson 7.02: Load Testing with Azure DevOps
This lesson will explain how to load test your application using the Azure DevOps URL-based load test option.
Prerequisites: You need to have Visual Studio Enterprise Subscription for the account you have used to log on to your Azure DevOps organization. You are familiar with using Azure DevOps.
To create a URL-based load test, open an Azure DevOps team project. Click on Load Test under Test Plan tab (see Figure 7-20).
Select New ➤ URL-based test to create a new load test (see Figure 7-21).
Add a name for the load test. Enter the URL you are going to test and keep HTTP method as GET. You can add multiple URLs as per your requirements and set different HTTP methods. If you want to send header values and query strings as part of the request, you can find the section where you can add the header values and the query string parameters (see Figure 7-22).
Select the Settings tab. Load test parameters can be set here. You can configure, run duration, number of users, browser mix, geo location, and other settings (see Figure 7-23).
After setting the parameters, save the load test. Then click on the Run Test to start the test execution (see Figure 7-24).
The test will start and you will be able to see the live test run information (see Figure 7-25).
After the test run is completed, you can see the summary page with the load test run results (see Figure 7-26).
Further, you will be able to see the test run results as charts. Move to the Charts tab to see the test results in the charts (see Figure 7-27).
Next to the Charts tab you can see the Diagnostics tab. Move to Diagnostics tab to see details of the test errors (see Figure 7-28).
You can find the log file of the load test run inside the Logs tab (see Figure 7-29).
We have explored how to author and run Cloud-based load tests in Azure DevOps in this lesson.
Lesson 7.03: Load Testing in the Azure Portal
This lesson explains how to do load tests using the Azure portal.
Prerequisites: You need to have an Azure subscription and be familiar with using the Azure portal. You must have a web application running in Azure App services. You need an Azure DevOps organization and be familiar with working with Azure DevOps.
Log in to the Azure portal and select App Services from the side menu (see Figure 7-30).
Select the web application from the App Services window. If you do not have an application running in Azure App services, create a Visual Studio sample ASP.NET application and deploy it to the Azure app services (see Figure 7-31).
Select the Performance test under the Development tools section (see Figure 7-32).
Now you need to connect with your Azure DevOps organization to keep the performance test history details.
To connect with Azure DevOps, click on Set Organization link (see Figure 7-33).
If you already have an Azure DevOps organization, select it or you can create a new one (see Figure 7-34).
Click on New to create a new performance test (see Figure 7-35).
You can add performance settings and click on Run Test to run the test (see Figure 7-36). Additionally, you can set multiple URLs for performance testing by selecting Configure Test Using in this step. You have the option to upload a Web Test file authored in Visual Studio to enable multiple URL testing, which we will omit in this lesson for simplicity. You can experiment with creating multiple URLs with performance tests as a further learning exercise.
After you click on the Run test, you can see the performance test has triggered as shown in Figure 7-37.
Select the PerfTest01 and you can see live test run progress. After the test run is complete, you can see a detailed report of the test run in the Azure portal (see Figure 7-38).
In this lesson, we have explored load test authoring with the Azure Portal, which is available as a preview feature at the time of writing this book.
Lesson 7.04: Comparing Load Test Results
This lesson will explain how to compare load test run results.
Prerequisites: You need to have an Azure DevOps organization that has been used to practice the previous lessons. You need to have completed previous lessons and have run the load tests as instructed in the lessons.
Go to Azure DevOps and select Load Test under the Test Plan section.
You will be able to see all available load test runs. You can filter the relevant load tests using filters (see Figure 7-39).
You can compare two load tests to verify how application performances have increased or decreased. To compare two tests, select both tests and click Compare two runs link (see Figure 7-40).
Then you can see the comparison details, which you can analyze to identify how the application being tested performs with load over time (see Figure 7-41).
In this lesson, you have learned how to compare load test run results in Azure DevOps.
Summary
In this chapter, we have explored options of authoring and running Cloud-based load tests involving Azure DevOps as the test running facilitator. You can use this knowledge to make sure you are delivering applications to your production environment after doing thorough analysis of the performance of the applications under real traffic and load.
In this book, we have learned wiring functional test automation using Selenium and Visual Studio. You have used C# and Python to author tests and have used few frameworks, such as MAQS and, SpecFlow to make test automation authoring more stable. Getting the tests integrated with CI/CD pipelines will come in handy as you will be able to leverage capabilities of Azure DevOps to achieve real benefits of functional test automations, which will bring your organization one more step toward being a DevOps-enabled organization. Further, the theoretical explanations and hands-on lessons in this book have given you essential knowledge for implementing functional test automations. Finally, we have explored the load testing options as well to help you implement applications that can handle real-world usage needs.