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 Storepage for theModHeader Chrome Extension:
- Open the menu from the
Chrome Extension Source Viewerand click on theDownload as zipbutton. - Upload that
zipfile to the Endtest Drive and copy theFile Download URL. - Go to the
Advancedsection of theSettingsfor your Test Suite and paste that copiedFile Download URLin theAdd Chrome Extensioninput. - Click on the
Savebutton. Now your Test Suite will automatically load thatModHeader Chrome Extensionwhen you run it. - Add a
Set Variable - Set Valuestep with the valuechrome://extensions/. - Add a
Go to URLstep for that variable. - Add an
Execute JavaScriptstep 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 JavaScriptstep with this JavaScript code inside to extract theChrome Extension IDinto 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 Variablestep to extract the value from thechromeExtensionIDJavaScript variable into an Endtest variable. - Add a
Go to URLstep to go to this link:chrome-extension://{{$chromeExtensionID}}/src/popup_v1.html - You can now start adding your custom Headers by using
Write Textsteps. To find locators for the elements, you can add aMiscellaneous - Get Page Sourcestep to extract and view the HTML of theModHeader Chrome Extensionpage.
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 URLstep 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 Testthat runs onChrome.This chapter was written in June 2025. In the future, updates to the
ModHeader Chrome Extensionor theChrome Extensionspage 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.
