我可以使用 Selenium-webdriver for Ruby 自动阻止 Chrome 请求吗? [英] Can I automate Chrome request blocking using Selenium-webdriver for Ruby?

查看:35
本文介绍了我可以使用 Selenium-webdriver for Ruby 自动阻止 Chrome 请求吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名 QA 自动化分析师,负责测试多平台网上银行应用程序.对于我们的自动化测试,我们将 RubyMine 套件与 Gherkin/Cucumber、Ruby 脚本步骤和 Selenium-webdriver、Watir 和页面对象 gems/库一起使用.

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, Ruby-scripted steps and Selenium-webdriver, Watir and page-object gems/libraries.

我有许多脚本,如果没有人工干预,我无法完全自动化,其中包括通过 Telerik Fiddler 阻止某些网络调用以生成警告页面或错误消息等.我们自动化的未来将通过 RubyMine 来实现而不是 Fiddler 用于网络阻塞.我知道有一种方法可以在 Chrome 中使用 Inspect Element 和 Network 菜单使用 启用请求阻止.但是,我想不出一种通过 Ruby/Selenium 强制 Chrome 阻止给定请求的方法.唯一的方法是自己手动完成,因此我实际上无法根据需要自动执行这些操作.

I have a number of scripts that I cannot automate completely without manual intervention, and these include blocking certain network calls through Telerik Fiddler to produce warning pages or error messages, etc. The future of our automation would be to do this through RubyMine instead of Fiddler for network blocking. I know there is a way to do this in Chrome using Inspect Element and the Network menu using enable request blocking. However, I cannot figure out a way to force Chrome through Ruby/Selenium to block a given request. The only way is do manually do it myself, and therefore I can't actually automate these as wanted.

那么,我的问题——这是否有可能使用 Selenium-webdriver 自动阻止请求?如果是这样,我应该从哪里开始寻求帮助?

So, my question -- is this a possibility to automate request-blocking with Selenium-webdriver? And, if so, where should I begin to look for help with this?

谢谢.

推荐答案

使用 DevTool API 阻止使用 Selenium 加载 URL:

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")

这篇关于我可以使用 Selenium-webdriver for Ruby 自动阻止 Chrome 请求吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆