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

后端 未结 3 2015
无人共我
无人共我 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")
    

提交回复
热议问题