I want to add "iv-user" request header to log into web app.
I'm using the newest ChromeDriver.
Using extensions like ModHeader or ModifyHeaders is not working in this case. Fiddler is working, but I need a solution that will allow me to change accounts during the test case execution.
Can someone help me with this, please?
Now, I'm trying to use BrowserMob Proxy in Embedded mode, to achieve it, but something is not working. Proxy is running and ChromeDriver too, request header is set and sent to the app server, but after checking network log in browser, this custom header is not received by it.
Class Case:
@BeforeEach
public void setUp() throws Exception {
LOGER.setLevel(Level.WARNING);
loadProperties();
if (driver != null) {
driver.quit();
}
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.start(0);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
proxy.addRequestFilter((request, contents, messageInfo)->{
request.headers().add("iv-user", "login");
System.out.println(request.headers().entries().toString());
return null;
});
chromeOptions = new ChromeOptions();
String proxyOption = "--proxy-server=" + seleniumProxy.getHttpProxy();
chromeOptions.addArguments(proxyOption);
chromeOptions.addArguments("-incognito");
chromeOptions.addArguments("disable-infobars");
chromeOptions.setCapability(CapabilityType.PLATFORM_NAME, Platform.WINDOWS);
chromeOptions.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
chromeOptions.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
System.setProperty("webdriver.chrome.driver", CHROMEDRIVER_PATH);
driver = new ChromeDriver(chromeOptions);
actions = new Actions(driver);
driver.manage().timeouts().implicitlyWait(IMPLICITLY_WAIT_TIME_OUT, TimeUnit.SECONDS);
driver.manage().window().maximize();
new WebDriverWait(driver, 30);
wait = new FluentWait<WebDriver>(driver)
.withTimeout(ConstConfig.FLUENTWAIT_TIMEOUT_SEC, TimeUnit.SECONDS)
.pollingEvery(1, TimeUnit.SECONDS)
.ignoring(StaleElementReferenceException.class)
.ignoring(NoSuchElementException.class)
.ignoring(ElementNotVisibleException.class);
jsExecutor = (JavascriptExecutor) driver;
}
Class Test:
public class Test_Proxy extends Case {
@Test
public void test_Proxy() throws Exception {
try{
driver.get(TESTAPP_URL);
MainMenu mainMenu = new MainMenu();
//..........
} finally {//....................}}}