Can I automate Chrome request blocking using Selenium-webdriver for Ruby?

后端 未结 3 2005
无人共我
无人共我 2020-12-09 23:27

I am a QA automation analyst responsible for testing a multi-platform online banking application. For our automation testing we use RubyMine suite with Gherkin/Cucumber, Rub

相关标签:
3条回答
  • 2020-12-09 23:45

    To block URLs from loading with Selenium with the DevTool API:

    def send_cmd(driver, cmd, params={})
      bridge = driver.send(:bridge)
      resource = "session/#{bridge.session_id}/chromium/send_command_and_get_result"
      response = bridge.http.call(:post, resource, {'cmd':cmd, 'params': params})
      raise response[:value] if response[:status]
      return response[:value]
    end
    
    send_cmd(driver, "Network.setBlockedURLs", {'urls': ["*"]})
    send_cmd(driver, "Network.enable")
    
    0 讨论(0)
  • 2020-12-09 23:55

    Try https://github.com/lightbody/browsermob-proxy

    I dont know if it can satisfy your requirement as I am no way a network expert, I do use browsermob-proxy extensively to capture network request along with selenium and there is a method to blacklist certain request

    https://browsermob-proxy-py.readthedocs.io/en/stable/client.html#browsermobproxy.Client.blacklist

    How to disable loading external urls on seleniumlibrary/robotframework

    0 讨论(0)
  • 2020-12-10 00:00

    It's not very well documented, but you can also implement request blocking by passing the host-resolver-rules option to chrome and mapping the domain to localhost or an invalid IP. Something like this should work for you:

    options = Selenium::WebDriver::Chrome::Options.new
    options.add_argument('--host-resolver-rules=MAP www.google-analytics.com 127.0.0.1')
    driver = Selenium::WebDriver.for :chrome, options: options
    
    0 讨论(0)
提交回复
热议问题