[英]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 isn't a test end-to -end , would not be useful to use the Zombie.js
or Nightwatch.js
. 这不是端到端的测试 ,使用Zombie.js
或Nightwatch.js
不会有用。
Is there any possibility to fill the login form and making requests go after? 是否有可能填写登录表格并提出要求?
Have you seen Supertest? 你看过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);
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.