如何在 nightwatch.js 中发送 ajax 获取请求

How to send ajax get request in nightwatch.js

我在 UI 自动化测试项目中工作,我需要向我的服务器发送 ajax 请求,但在 Nighwatch.js 香草 javascript 和 JQuery 函数不可接受,

所以如果有人有在 nightwatch.js 环境中向服务器发送 Ajax get 请求的经验,请给我一些 info/suggestions.

经过长时间的研究,我发现 request.js 一个节点模块,我通过安装 "request" node module 解决了我的问题。安装后,我可以在 Nightwatch 环境中对我的服务器执行 "GET" 和 "POST" 请求。我正在编写一段代码,它工作起来很有魅力。

/* jshint expr: true */
module.exports = {
'@tags' : ['book'],
beforeEach : function (client) {

},
after : function (client) {
    client.end();
},
wGroup: {
    book_url: "https://example.myApi.mycompany.in"
},

userSettings: Array(),

"Get all settings": function (client, done) {
    var widget = this.wGroup;
    client.getreq( widget.book_url + "/api/store", widget, function (response) {
        client.assert.equal(response.statusCode, 200, "201 Created");
        var objects = response.body.objects;
        client.userSettings = objects;
        console.log( 'Found number of settings: ' + client.userSettings.length );
        client.end();
    });
},

"Remove settings": function (client, done) {
    var widget  = this.wGroup;
    var objects = client.userSettings;
    for( i=0; i<objects.length; i++ ) {
        var obj = objects[i];
        console.log('Removing user settings id ' + obj.id );
        client.deletereq( widget.book_url: l + "/api/store" + obj.id, widget, function (resp) {
            client.assert.equal(resp.statusCode, 204, "204 Created");
            client.end();
        });
     }
   },
};