Header
When you use PTS for performance testing, you can define headers to send special requests. This topic describes how to define headers in a scenario configuration.
Prerequisites
You have configured the basic request information for the API. For more information, see Basic Request Information.
Background information
In many performance testing scenarios, you must send specific requests. For example, when testing a web login scenario, you need to use authenticated requests. PTS sends all performance testing requests over the HTTP protocol. During scenario configuration, you can define the key and value of a header to specify these special requests. To specify requests with greater precision, you can define the request body. For more information, see Body.
You can define API headers in the following three ways to apply them at different scopes:
Set a header for a single API: The header applies only to the current API.
Set an API chain header: During performance testing, PTS automatically adds this header to all APIs in the current API chain.
Set a global header: During performance testing, PTS automatically adds this header to all APIs in the entire scenario.
If you define headers with the same
keyusing these methods, the header with the narrowest scope takes precedence.If all defined headers have unique keys, PTS applies all header definitions.
Set a header for a single API
To define headers for a single performance testing request, edit the Key and Value on the Header Definition tab for the API.
Log in to the PTS console. In the left navigation bar, select Performance Testing > Create Scenario, and then click PTS Stress Test.
On the Scenario Configuration tab, click the
icon to the right of the API. In the expanded section, click the Header Definition tab and configure the header parameters.
Parameter
Description
Value
You can enter a parameterized expression.
For advanced parameter construction, such as nesting functions and strings, see How do I combine and nest system functions and strings?.
Key
PTS performs fuzzy matching on common HTTP request headers based on your input to help you quickly select the target header.
Optional: Click Text Mode in the upper-right corner of the Header Definition tab to switch to text mode and view the entered Keys and Values. You can also add multiple headers in batches in text mode. An example is as follows:
token : 123abc Cookie : session=12345NoteYou must set the
Content-Typeheader on the Body Definition tab.
Set an API chain header
If multiple APIs in an API chain require the same header, you can set a single API chain header that applies to all of them.
For example, in an online course selection service, you might need to differentiate between first-grade and second-grade students. To run a performance test on this service, you can create a separate API chain for each grade and set a unique API chain header to distinguish the student type.
Follow these steps to set an API chain header:
On the Scenario Configuration tab, select Chain Header from the dropdown menu to the right of Add Directive.
Click the
icon to the right of the API chain header row. In the expanded section, set the Key and Value for the header.
Parameter
Description
Value
You can enter a parameterized expression.
For advanced parameter construction, such as nesting functions and strings, see How do I combine and nest system functions and strings?.
Key
PTS performs fuzzy matching on common HTTP request headers based on your input to help you quickly select the target header.
Optional: Click Text mode in the upper-right corner of the Header tab to switch to text mode and view the entered name and Value. You can also add multiple Headers in batches in Text mode. The following is an example:
Grade : 1 Cookie : abcNoteYou must set the
Content-Typeheader on the Body Definition tab.