用守夜人看网络

watch network with nightwatch

我正在使用 nightwatch 来测试应用程序的前端。 我正在测试某些按钮是否可点击。

能不能用nightwatch,知道有没有网络 点击请求,或更一般地说,观看网络。

Is it possible with nightwatch, to know if there was a network request made by the click, or more generally, to watch the network.

不,不是。

你不能用普通的守夜人。这可以通过 browsermob 来完成,它可以记录您的浏览器请求并以 HAR 格式保存。您必须集成 browsermob-proxy。我已经回复了另一个类似的post。检查这个。

https://groups.google.com/forum/#!msg/nightwatchjs/NFBi0fnQNT8/Dp9t1-CDBQAJ

是的,您可以使用 https://www.npmjs.com/package/nightwatch-xhr 来监视来自 Nightwatch.js 的 Ajax 请求。

(我是维护者之一)

以下是捕获 XHR 流量的解决方案:

https://github.com/Bugazelle/nightwatch-capture-network-traffic

工作原理

  1. 利用 ajaxListener.js

    The js is forked from https://gist.github.com/icodejs/3183154

    此 hack 会将所有 XHR 请求作为警告日志发送到控制台

    {
        "type": "response",
        "syncMode": this.syncMode,
        "method": this.method,
        "url": this.url,
        "requestData": this.requestData,
        "readyState": this.readyState,
        "responseText": this.responseText,
        "responseCode": this.status,
        "responseHeader": this.getAllResponseHeaders()
    }
  1. 那就好好利用守夜人API.getLog

    .getLog可以为我们捕获控制台警告日志