首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Watir访问浏览器开发工具并捕获网络流量

使用Watir访问浏览器开发工具并捕获网络流量
EN

Stack Overflow用户
提问于 2022-04-21 18:57:34
回答 2查看 603关注 0票数 2

在运行自动化测试用例时,需要从浏览器捕获网络流量。

下面看到了post,但不确定它是否包含在Watir 7中。请了解是否有任何使用Watir访问devtools和捕获网络流量(如api调用)的例子。谢谢!!

https://github.com/watir/watir/issues/721

EN

回答 2

Stack Overflow用户

发布于 2022-04-21 19:28:06

Watir目前并没有包装这些特性。您可以通过使用#wd方法获取selenium驱动程序来访问所有内容。就像这样:

代码语言:javascript
复制
requests = []
browser.wd.intercept do |request, &continue|
    requests << request
    continue.call(request)
end
browser.goto page
expect(requests).not_to be_empty

在有关这些的selenium文档中,没有一个很好的指南,但是下面是规范中的其他示例:https://github.com/SeleniumHQ/selenium/blob/trunk/rb/spec/integration/selenium/webdriver/devtools_spec.rb

票数 2
EN

Stack Overflow用户

发布于 2022-04-23 00:16:10

如果你也对回应感兴趣的话,这应该是可行的

代码语言:javascript
复制
log_name = "/path/to/logs/network.log"
log_file = File.open(log_name, 'w')
browser.wd.intercept do |request, &continue|
    continue.call(request) do |response|
      log_file << "#{request.id} \t
                   #{request.method} \t
                   #{response.code} \t
                   #{request.url} \n"
    end
end

确实起作用了,但是有什么例外

代码语言:javascript
复制
undefined method `each_with_object' for nil:NilClass
/selenium-webdriver-4.1.0/lib/selenium/webdriver/devtools/response.rb:38:in `from'
/selenium-webdriver-4.1.0/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb:109:in `intercept_response'
/selenium-webdriver-4.1.0/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb:68:in `block in intercept'
/selenium-webdriver-4.1.0/lib/selenium/webdriver/devtools.rb:155:in `block in callback_thread'```
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71959632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档