如何使用browsermob-proxy和nightwatch.js监视HTTP调用?

我正在使用Nightwatch.js框架为SPA应用程序编写testing用例。 一个要求来了,我们必须监视HTTP调用,并获得该网站的性能结果。 这可以通过使用JMeter轻松实现。

使用自动化testing工具,我们可以通过使用browsermob-proxy和selenium来完成。

使用Nightwatch.js和browsermob-proxy可以做同样的事吗?

还有什么是相同的步骤。

要一起使用Nightwatchjs和browsermob-proxy,请查看此回购 ,其中包含有关browsermob-proxy的NodeJS绑定信息,并以编程方式生成HAR(HTTP归档)文件。

如果你满足于使用Nightwatchjs, 这个回购在testing目录中的代码如下:

  • 自定义命令来获取到目前为止的请求
  • 自定义断言,用于检查给定filter和查询string参数的请求是否存在。

您可能需要了解如何将自定义命令和断言添加到Nightwatch项目中,但在此之后,您应该开始设置!

您可以使用browsermob-proxy-api只需下载browsermob-proxy服务器,然后通过npm命令npm install browsermob-proxy-api --save-devnpm install browsermob-proxy-api --save-dev在desiredCapabilites中configuration您的夜视:

 'test_settings': { 'default': { 'launch_url': 'http://localhost:3000', 'screenshots': { 'enabled': true, // if you want to keep screenshots 'path': './screenshots' // save screenshots here }, 'globals': { 'waitForConditionTimeout': 30000 // sometimes internet is slow so wait. }, 'desiredCapabilities': { // use Chrome as the default browser for tests 'browserName': 'chrome', 'proxy': { 'proxyType': 'manual', 'httpProxy': 'localhost:10800' }, 'acceptSslCerts': true, 'javascriptEnabled': true, // turn off to test progressive enhancement } }, 

然后从这里下载index.js: https : //github.com/jmangs/node-browsermob-proxy-api ,如果您使用小黄瓜或describe步骤,则将示例代码添加到您的step_definitions