简体   繁体   中英

How to set values in a form automatically with Node.js

I'm doing a lot of requests and want to see only the status code , there are areas that require to be authenticated to access which want to check.
This , would not be useful to use the Zombie.js or Nightwatch.js . ,使用Zombie.jsNightwatch.js不会有用。

Is there any possibility to fill the login form and making requests go after?

Have you seen Supertest?

npm install supertest --save-dev

You can use this to simulate request and check execution or status code.

var request = require('supertest')
  , express = require('express');

var app = express();

app.get('/user', function(req, res){
  res.send(200, { name: 'tobi' });
});

request(app)
  .get('/user')
  .expect('Content-Type', /json/)
  .expect('Content-Length', '20')
  .expect(200)
  .end(function(err, res){
    if (err) throw err;
  });

With Mocha:

describe('GET /users', function(){
  it('respond with json', function(done){
    request(app)
      .get('/user')
      .set('Accept', 'application/json')
      .expect('Content-Type', /json/)
      .expect(200, done);
  })
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM