3

I am trying to use a proxy of LocalHost and port 8080. I have written the following code in Robot Framework but the IP is not changing once the browser opens:

*** Settings ***
Documentation           This is a simple test with Robot Framework
Library                 Selenium2Library


*** Variables ***
${SERVER}                   http:/demo.testfire.net
${BROWSER}                  firefox
${DELAY}                    0



*** Keywords ***

Open Browser To Demo       
${proxy}=      Evaluate     sys.modules['selenium.webdriver'].Proxy()  sys, selenium.webdriver
${proxy.http_proxy}=         Set Variable  localhost:8080
Create Webdriver  Firefox       proxy=${proxy}
Go To  ${Server}


*** Test Cases ***
Valid Login
    Open Browser To Demo

Can anyone give me a fix to this so that IP address in Firefox changes to 127.0.0.1 without using Firefox Profiles?

1 Answers1

1

The example code in the Selenium2Library documentation was also not working for me, so I wrote this to start firefox with a proxy without setting up a whole new profile.

*** Settings ***
Library  Collections

*** Keywords ***
Open firefox browser with proxy  
    ${caps}=  Evaluate  sys.modules['selenium.webdriver'].DesiredCapabilities.FIREFOX  sys, selenium.webdriver
    ${proxy}=  Create dictionary  proxyType=MANUAL  httpProxy=YOUR-PROXY-URL:PORT
    Set to dictionary  ${caps}  proxy=${proxy}
    Open Browser  browser=headlessfirefox  desired_capabilities=${caps}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Guillaume
  • 77
  • 8
  • Thanks I was going crazy with the example from the doc, it clearly also wasn't working for me. Side note for future readers: to open a https URL it will need to be sslProxy: `Create dictionary proxyType=MANUAL sslProxy=localhost:8181` – C. Ramseyer Aug 10 '21 at 09:17