Reputation: 23
i'm doing some tests on a webpage using jmeter and selenium. What i need to do is to send some custom header request and i would like to do it by using a proxy server in local. For several reasons i can't use browsr plugins, and i cannot use the jmeter header customization because of the using of selenium.
So, I'm trying to deal by using apache, but i'm totally new at this and probably i'm doing something wrong. Here's the part of the code that i'm changing from the config file(the last istructions at the end of the file), but no headers are added:
###HEADER### RequestHeader set Host "summer-gc.snam.it" RequestHeader set X-Dynatrace_PerfTest "SN=SUMMER_TC01.jmx;RN=01_01_login;TRT=20210422- 100000;VU=2;DUR=120;MVU=3;RMP=1"
###PROXY### ProxyRequests Off
<Proxy *> Require all granted
#54.90.58.153 -> postmanecho ProxyPreserveHost On ProxyPass / http://172.25.36.197:80/ ProxyPassReverse / http://172.25.36.197:80/ Header add myheader "myvalue" RequestHeader set myheader "myvalue"
Also i've removed the comment from:
LoadModule headers_module modules/mod_headers.so
How i have to set the config file in order to send new headers? Also, since i'm not very skilled at this, i'm looking for a program (for windows) that allow me to do it easily? Thank's a lot
Upvotes: 1
Views: 1493
Reputation: 168082
I might have a better idea for you which is cross platform and doesn't require any software installation/configuration: consider using BrowserMob Proxy instead of Apache proxy server
Download BrowserMob proxy (inlcuding all dependencies) and drop the jars to JMeter Classpath
Add setUp Thread Group with 1 user/1 iteration
Add JSR223 Sampler and put the following code into "Script" area:
def proxy = new net.lightbody.bmp.BrowserMobProxyServer()
def proxyPort = 8080
proxy.setTrustAllServers(true)
proxy.addRequestFilter((request, contents, info) -> {
request.headers().add('foo', 'bar')
return null
})
proxy.start(proxyPort)
props.put('proxy', proxy)
Add "normal" Thread Group
Add JSR223 Sampler to this Thread Group and put the code to instantiate the browser and open the page you want to open (and do whatever else stuff you need to do)
System.setProperty('webdriver.chrome.driver', 'c:/apps/webdriver/chromedriver.exe')
def proxy = new org.openqa.selenium.Proxy()
proxy.setHttpProxy('localhost:8080')
def options = new org.openqa.selenium.chrome.ChromeOptions()
options.setCapability('proxy', proxy)
def driver = new org.openqa.selenium.chrome.ChromeDriver(options)
driver.get("http://example.com")
driver.quit()
at this stage the proxy will add header foo
with the value of bar
to each outgoing request from the browser
A good idea would be stopping the proxy in the tearDown Thread Group, again add a JSR223 Sampler and use the following code:
def proxy = props.get('proxy')
proxy.stop()
Demo:
Upvotes: 1