© Chaminda Chandrasekara, Pushpa Herath 2019
Chaminda Chandrasekara and Pushpa HerathHands-On Functional Test Automationhttps://doi.org/10.1007/978-1-4842-4411-1_7

7. Load and Performance Testing

Chaminda Chandrasekara1  and Pushpa Herath2
(1)
Dedigamuwa, Sri Lanka
(2)
Hanguranketha, Sri Lanka
 

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.

For load and performance testing, Selenium can only be used with some open source and paid third-party tools and frameworks. One such tool is Selenium Grid ( https://github.com/SeleniumHQ/selenium/wiki/Grid2 ) and another limited free and paid option to use is WebLoad ( https://www.radview.com/selenium-performance-testing/ ).

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

    Launch Visual Studio Installer.

     
  2. 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).
    ../images/473577_1_En_7_Chapter/473577_1_En_7_Fig1_HTML.jpg
    Figure 7-1

    Web performance and load testing tool component in Visual Studio Installer

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

    In Visual Studio 2017, select Files ➤ New ➤ Project

     
  2. 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).
    ../images/473577_1_En_7_Chapter/473577_1_En_7_Fig2_HTML.jpg
    Figure 7-2

    Create new web performance test project

     
  3. 3.
    After creating a new web performance test project, you can find project items in the Solution Explorer as follows (see Figure 7-3).
    ../images/473577_1_En_7_Chapter/473577_1_En_7_Fig3_HTML.jpg
    Figure 7-3

    Solution Explorer view of web performance test project

     
  4. 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).
    ../images/473577_1_En_7_Chapter/473577_1_En_7_Fig4_HTML.jpg
    Figure 7-4

    Select Manage add-ons from Internet Explorer settings

     
  5. 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).
    ../images/473577_1_En_7_Chapter/473577_1_En_7_Fig5_HTML.jpg
    Figure 7-5

    Enable the Web Test Recorder add-on

     
  6. 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.

     
  7. 7.
    Click on the Add Recording icon (see Figure 7-6).
    ../images/473577_1_En_7_Chapter/473577_1_En_7_Fig6_HTML.jpg
    Figure 7-6

    Click on Add Recording icon

     
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.
  1. 8.
    Perform the test steps and click on the stop icon to stop recording (see Figure 7-7).
    ../images/473577_1_En_7_Chapter/473577_1_En_7_Fig7_HTML.jpg
    Figure 7-7

    Recording actions performed on web application

     
  2. 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).
    ../images/473577_1_En_7_Chapter/473577_1_En_7_Fig8_HTML.jpg
    Figure 7-8

    Web Test1.webtest file with a list of web requests

     
  3. 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).
    ../images/473577_1_En_7_Chapter/473577_1_En_7_Fig9_HTML.jpg
    Figure 7-9

    Edit test properties

     
  4. 11.
    After setting the performance goals, run the web test (see Figure 7-10).
    ../images/473577_1_En_7_Chapter/473577_1_En_7_Fig10_HTML.jpg
    Figure 7-10

    Run the web performance test

     
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).
    ../images/473577_1_En_7_Chapter/473577_1_En_7_Fig11_HTML.jpg
    Figure 7-11

    Web test run results

  • 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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig12_HTML.jpg
Figure 7-12

Add a load test file

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.
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig13_HTML.jpg
Figure 7-13

Select On-premises option

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig14_HTML.jpg
Figure 7-14

Select geo location

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig15_HTML.jpg
Figure 7-15

Add test mix

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig16_HTML.jpg
Figure 7-16

Select test from available test

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig17_HTML.jpg
Figure 7-17

Run load test

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig18_HTML.jpg
Figure 7-18

Load test running

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.
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig19_HTML.jpg
Figure 7-19

Load test running

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig20_HTML.jpg
Figure 7-20

Select Load test

Select New ➤ URL-based test to create a new load test (see Figure 7-21).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig21_HTML.jpg
Figure 7-21

Select URL-based test

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig22_HTML.jpg
Figure 7-22

Add URL to test

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig23_HTML.jpg
Figure 7-23

Add load test settings

After setting the parameters, save the load test. Then click on the Run Test to start the test execution (see Figure 7-24).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig24_HTML.jpg
Figure 7-24

Click on Run test

The test will start and you will be able to see the live test run information (see Figure 7-25).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig25_HTML.jpg
Figure 7-25

Live test run view

After the test run is completed, you can see the summary page with the load test run results (see Figure 7-26) .
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig26_HTML.jpg
Figure 7-26

Load test run result

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig27_HTML.jpg
Figure 7-27

Load test result charts

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig28_HTML.jpg
Figure 7-28

Diagnostics page

You can find the log file of the load test run inside the Logs tab (see Figure 7-29).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig29_HTML.jpg
Figure 7-29

Logs file

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig30_HTML.jpg
Figure 7-30

Select App services from side menu

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig31_HTML.jpg
Figure 7-31

Select the web app

Select the Performance test under the Development tools section (see Figure 7-32).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig32_HTML.jpg
Figure 7-32

Select performance test

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig33_HTML.jpg
Figure 7-33

Click on Set Organization

If you already have an Azure DevOps organization, select it or you can create a new one (see Figure 7-34).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig34_HTML.jpg
Figure 7-34

Select Azure DevOps subscription

Click on New to create a new performance test (see Figure 7-35).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig35_HTML.jpg
Figure 7-35

Click on New link

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.
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig36_HTML.jpg
Figure 7-36

Add test run settings

After you click on the Run test, you can see the performance test has triggered as shown in Figure 7-37.
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig37_HTML.jpg
Figure 7-37

Queued performance test

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig38_HTML.jpg
Figure 7-38

Test run result

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig39_HTML.jpg
Figure 7-39

Load test filters

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig40_HTML.jpg
Figure 7-40

Compare two tests

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).
../images/473577_1_En_7_Chapter/473577_1_En_7_Fig41_HTML.jpg
Figure 7-41

Performance comparison

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.42.208