在运行自动化测试用例时,需要从浏览器捕获网络流量。
下面看到了post,但不确定它是否包含在Watir 7中。请了解是否有任何使用Watir访问devtools和捕获网络流量(如api调用)的例子。谢谢!!
发布于 2022-04-21 19:28:06
Watir目前并没有包装这些特性。您可以通过使用#wd方法获取selenium驱动程序来访问所有内容。就像这样:
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
发布于 2022-04-23 00:16:10
如果你也对回应感兴趣的话,这应该是可行的
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确实起作用了,但是有什么例外
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'```https://stackoverflow.com/questions/71959632
复制相似问题