0

I need to add a new request header to chrome webdriver. In manual test, we are using ModHeader extension to add new custom request header to the browser.

I tried following option, but did not work.

${options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver\
Call Method       ${options}       add_argument        newheadername\=newheadervalue\
Create Webdriver    Chrome    chrome_options=${options}\
Go To    ${URL}

How do I launch the web application with a custom request header?

Can we add the customer request header to chrome options and create webdriver with the options?

Bence Kaulics
  • 7,066
  • 7
  • 33
  • 63
Govi
  • 1
  • 1

3 Answers3

0

Header name is x-iteration and a value has to be passed. For now, I have hardcoded the value.

I tried the following code in keyword, but still I do not see the 'x-iteration' header added in the launched browser request headers

[Arguments] ${URL}
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chrome_options} add_argument x-iteration=itr-dec-w2
${options}= Call Method ${chrome_options} to_capabilities
Open Browser ${URL} browser=chrome desired_capabilities=${options}

Govi
  • 1
  • 1
0

I used chrome extension modheader to achieve this like below.

Open Available Browser
...    about:blank
...    browser_selection=chrome
...    options=add_extension('modheader.crx');add_experimental_option('prefs',{"extensions.ui.developer_mode": True,})
Go To    https://webdriver.modheader.com/add?test=ModHeader%20Test
Go To    YourWebsite

Modheader has the selenium support which is explained here https://docs.modheader.com/advanced/selenium-webdriver

ajain
  • 194
  • 1
  • 7
-1

What is newheadervalue? Did you mean to supply a variable there such as ${newheadervalue}?

   ${chrome_options} =     Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver

Call Method    ${chrome_options}   add_argument    start-maximized
Call Method    ${chrome_options}   add_argument    newheadername=newheadervalue
Call Method    ${chrome options}   add_argument    window-size=1920,1080

${options}=     Call Method     ${chrome_options}    to_capabilities     
Open Browser     ${HOST_URL}    browser=chrome  desired_capabilities=${options}
Steve Rawlins
  • 350
  • 2
  • 10
  • Header name is x-iteration and a value has to be passed.For now, I have hardcoded the value. I tried the following code in keyword, but still I do not see the 'x-iteration' header added in the launched browser request headers [Arguments] ${URL} ${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver Call Method ${chrome_options} add_argument x-iteration\=itr-dec-w2 ${options}= Call Method ${chrome_options} to_capabilities Open Browser ${URL} browser=chrome desired_capabilities=${options} – Govi Feb 12 '21 at 03:58
  • Chrome doesn't support all of these arguments except start-maximized. In order to add or modify headers, chrome extensions came to my rescue. modehead.io is what used but you can use any of the openly available chrome extension. – ajain Feb 23 '23 at 06:25