如何将标头或参数添加到使用Selenium Webdriver处理的HTTP请求中? [英] How to add headers or parameters to an HTTP request handled with Selenium Webdriver?

查看:1550
本文介绍了如何将标头或参数添加到使用Selenium Webdriver处理的HTTP请求中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium Webdriver进行Web应用程序的单元测试。它在JUnit测试中使用尽管广泛阅读可用文档并进行搜索,但我找不到一种方法:

I'm using Selenium Webdriver for unit testing of a web application. It's used in JUnit tests Despite reading the available documentation extensively and searching around, I could not find a way to:


  • 向HTTP添加标头驱动程序传递的请求。

  • 为这样的请求添加参数,就像驱动程序在提交表单后获得目标URL一样。

可以创建一个具有适当形式的测试网页,并让Webdriver反弹以自动获取这些参数,但这是一个非常难看的黑客。我想避免它,特别是为了测试原子性。 (这是单元测试。)

It would be possible to create a test web page with an appropriate form and have Webdriver bounce off it to get those parameters automatically, but this is quite an ugly hack. I would like to avoid it, especially for the sake of test atomicity. (This is unit testing.)

在Wendriver之前,我使用Spring的MockHttpServletRequest和MockHttpServletResponse来做到这一点,这就像一个魅力,但我想用力量Webdriver断言目标页面的内容。

Before Wendriver, I was using Spring's MockHttpServletRequest and MockHttpServletResponse to do this, which worked like a charm, but I would like to use the power of Webdriver to assert the target page's contents.

推荐答案

您可以尝试评估browsermob-proxy。它有助于操纵标题。
https://github.com/webmetrics/browsermob-proxy 。与webdriver集成很简单。您只需要设置代理值即可启动驱动程序。

You can try evaluating browsermob-proxy. It helps in manipulating the headers. https://github.com/webmetrics/browsermob-proxy. Integrating with webdriver is simple. You just need to start the driver with the proxy values set.

这篇关于如何将标头或参数添加到使用Selenium Webdriver处理的HTTP请求中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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