Search code examples
rubyautomationwatirsafaridriver

How to configure Safari webdriver to use .pac file


I am working on automation repo with Ruby and Watir framework. I found a ways to set the pac file for chrome and firefox webfrivers. Examples:

chrome: args << "--proxy-pac-url=#{pac_file_path}"

firefox: profile['network.proxy.autoconfig_url'] = pac_file_path

My question is how can I set it for Safari webdriver ?

Thanks !


Solution

  • Theoretically you should be using a proxy configuration in your capabilities. There was a bug with Selenium Options and Proxy until Selenium 4 beta 4, which was just released.

    I encourage everyone to upgrade to Watir 7 and Selenium 4 even though they are still technically in beta, they are more reliable than the latest release of 6.x and 3.x.

    With Watir 7.0.0.beta4 and Selenium 4.0.0.beta4 you should be able to do this:

    proxy = Selenium::WebDriver::Proxy.new(type: :pac,
                                           proxy_autoconfig_url: pac_file_path)
    
    Watir::Browser.new :safari, options: { proxy: proxy }
    

    Once I merge this PR and release Watir 7.0.0.beta5, then this will work:

    Watir::Browser.new :safari, proxy: {type: :pac,
                                        proxy_autoconfig_url: pac_file_path}