Modify HTTP Headers
Introduction
There are situations where you need to modify the HTTP headers for a Web Test.
Since Endtest uses webdrivers to control browsers and interact with elements, and because webdrivers don’t offer a direct method for changing HTTP headers, you’ll need to include a Chrome Extension like ModHeader
in your Web Test to achieve this.
Steps
You can learn the basics of adding a Chrome Extension in your Web Test from the How to test Chrome Extensions chapter.
But the full process is explained here as well:
- Install the Chrome Extension Source Viewer in your own browser. You'll need it in order to download the
ModHeader Chrome Extension
. - In your own Chrome browser, go to the
Chrome Web Store
page for theModHeader Chrome Extension
:
- Open the menu from the
Chrome Extension Source Viewer
and click on theDownload as zip
button. - Upload that
zip
file to the Endtest Drive and copy theFile Download URL
. - Go to the
Advanced
section of theSettings
for your Test Suite and paste that copiedFile Download URL
in theAdd Chrome Extension
input. - Click on the
Save
button. Now your Test Suite will automatically load thatModHeader Chrome Extension
when you run it. - Add a
Set Variable - Set Value
step with the valuechrome://extensions/
. - Add a
Go to URL
step for that variable. - Add an
Execute JavaScript
step with this JavaScript code inside to enableDeveloper Mode
:
document.querySelector("body > extensions-manager").shadowRoot.querySelector("#toolbar").shadowRoot.querySelector("#devMode").shadowRoot.querySelector("#knob").click();
- Add another
Execute JavaScript
step with this JavaScript code inside to extract theChrome Extension ID
into a JavaScript variable:
chromeExtensionID = document.querySelector("body > extensions-manager").shadowRoot.querySelector("#items-list").shadowRoot.querySelector("extensions-item").shadowRoot.querySelector("#extension-id").innerText.split(":")[1].trim();
- Add a
Set Variable - Extract Value from JavaScript Variable
step to extract the value from thechromeExtensionID
JavaScript variable into an Endtest variable. - Add a
Go to URL
step to go to this link:chrome-extension://{{$chromeExtensionID}}/src/popup_v1.html
- You can now start adding your custom Headers by using
Write Text
steps. To find locators for the elements, you can add aMiscellaneous - Get Page Source
step to extract and view the HTML of theModHeader Chrome Extension
page.
Here are some of those locators:
Element | XPath |
---|---|
1st Header Name input | (//input[@name="header-name"])[1] |
1st Header Value input | (//input[@name="header-value"])[1] |
2nd Header Name input | (//input[@name="header-name"])[2] |
2nd Header Value input | (//input[@name="header-value"])[2] |
Add Request Header button | (//button[contains(@class, "mdc-button")])[1] |
- After that, you can verify that the custom Headers were added by using a
Go to URL
step to go to a website that displays the Headers used by the browser.
Because this approach relies on the
ModHeader Chrome Extension
, you can only add or modify headers in aWeb Test
that runs onChrome
.This chapter was written in June 2025. In the future, updates to the
ModHeader Chrome Extension
or theChrome Extensions
page may change their UI, which could cause the locators or JavaScript used here to stop working. You can still follow the same steps by identifying the updated locators in your own browser.