Introducing All You Can Test When You Capture Network Traffic
We all wonder what happens behind the scene.
In the world of software, the various flows happening after we click on a button are hardly visible. But we have to access them to ensure they are working properly using test automation.
The browser network traffic enables access to valuable information of the user experience: which APIs are called, the loading time and even the size of the loaded content.
In this article, we share the various testing use-cases available once you capture the network traffic. We will use Cerberus Testing to simplify our journey. You can read this introductory article on how to unlock the network traffic capture.
Let’s share the repeatable structure you can then reuse.
Understand the repeatable structure
The network traffic is a mine of various information where the data can be hardly usable at first. Cerberus Testing helps you by providing a clear data interface and test structure.
The data interface is the main source of information to build the various verifications. Cerberus Testing formats the data to ease your testing journey. Global and detailed indicators are available for each network traffic capture.
The test structure decouples each area of automated tests. The actions and controls are the building blocks of the actions to be performed. Then, the data properties enable to decouple the of actions and data. Lastly, the libraries of objects, steps and data are available transversally.
Our network capture case can be built on this structure :
- Define actions to capture the network traffic
- Set data properties to collect specific information
- Add controls depending on your verifications
First, you use “waitNetworkTrafficIdle” and “setNetworkTrafficContent” to actually collect the network traffic:
Second, you can define a property using the native JSON parser:
Then, you can add a control based on the retrieve data:
You can reuse that exact structure for a variety of uses-cases shared hereafter.
Verify a specific partner interaction
A click on a button triggers a whole set of interactions behind the scenes. Verifying these flows is essential to ensure the associated functions run correctly. Our first use case is to test for the effective call to a partner.
You can achieve that in two ways using Cerberus Testing:
- Collect all network traffic and verify the API call using the control “verifyElementPresent” on “$.stat.thirdparty.<partner>”
- Filter the network traffic content first on the “setNetworkTrafficContent” parameter, to then verify the number of calls is greater than one for that partner
The second case is shown below. The first one is only different for the control.
You can rely on that technique to test any API calls, internal or external. The case of testing for privacy is a mandatory one with the new consent regulation. Access the full article here.
We can enrich our tests by verifying the various return codes.
Check the API call return status
The reliability of the user experience is a game-changer for digital organizations. The response time, stability and reactivity are criteria now impacting the SEO and ranking of websites. It is therefore important to verify the return codes.
You can leverage the same structure with Cerberus Testing. The only difference is the control to define. Cerberus Testing provides you with a counter for each return code that your control can be based on.
You can systematically use control for each test using the assertion library and the simplified JSON locator:
- Ensure that no errors 500 happen with “x.stat.total.requests.nb5XX” equals to 0
- Ensure no errors for internal calls with “x.stat.internal.requests.nbError” equals to 0
- Verify the Kargo partner don’t have 1xx error code with “x.stat.thirdparty.Kargo.requests.nb1XX” equals to 0
You can continue to grow your test suite by accessing different counters, for example on the loading time.
Ensure page load remains under a threshold
The loading time of a user interface is critical. The users have no time to lose and you must guarantee the response time remains under control. You can achieve that by adding controls on the loading time.
You can equally leverage the Cerberus Testing ecosystem with control of different response time counters such as “x.stat.total.time.avg” for the average loading time. Here’s the entire set of counters available:
These controls are very helpful in CI/CD and production monitoring scenarios. You can ensure the loading time remains acceptable during software changes and in the actual user experience. For more details, you can consult this article on how to test for speed.
Bit by bit, your library is ready for scalable test automation.
Make the difference with an end-to-end framework
The repeatable structure with a simplified interface is what enables you to accelerate. You have no time to lose in your test automation effort for coding the network traffic capture, the JSON parser or the control library.
You can truly accelerate your software delivery and quality using a ready-to-use test automation framework. Your team needs your support to ensure reliable software changes. You can make a difference by building an awesome test automation library.
Cerberus Testing exists to let the teams focus on what matters for the business. The fully open-source model enables you to access a mature product that is continuously evolving and maintained.
Stop coding and start testing for Free.