request.js
请求的header配置
request.prototype.get = function(uri){
var ts = new Date().getTime();
var nonce = ts * 1000;
var ts_nonce = ts +"+"+nonce;
var data = uri+"+"+ts_nonce;
var token = 'tDHnYcg==-zjlzlkbiZac=';
var x_req_sig = utils.calculateHMAC(data,'aa79c5bad0ab');
return supertest.get(uri)
.set('x-vino-http-key',token)
.set('x-ts-header',ts_nonce)
.set('x-req-sig',x_req_sig)
.set('User-Agent','Android o/f869e7k2zlh/st/1.4.1/0')
.set('Accept-encoding','gzip');
};
request.prototype.post = function(uri){
var ts = new Date().getTime();
var nonce = ts * 1000;
var ts_nonce = ts +"+"+nonce;
var data = uri+"+"+ts_nonce;
var token = 'dPT1UMkbiZac=';
var x_req_sig = utils.calculateHMAC(data,'aad0ab');
return supertest.post(uri)
.type('form')
.set('x-vino-http-key',token)
.set('x-ts-header',ts_nonce)
.set('x-req-sig',x_req_sig)
.set('User-agent','Android o/f869e2zlh/st/1.4.1/0')
.set('Accept-encoding','gzip');
};
token
是通过/account/p-login-done.do
接口获得的
utils.calculateHMAC(data,'aa79c5bad0ab');
传递的值是deviceID
,也可以通过接口获得.
User-agent
等信息可以通过Charles抓取,参考填写
packages.json
"scripts": {
"test": "mocha -R mochawesome try.test.js"
},
需要变更为当前的测试脚本js
test.js
var request = require('./lib/request'),
should = require('should'),
fs = require('fs'),
path = require('path'),
utils = require('./lib/utils'),
async = require('async');
const addContext = require('mochawesome/addContext');
request = request('http://rrr.1o.cn');
describe('测试', function() {
var testData = utils.getTestData('../data/cart.xlsx'); //读取excel case
testData.forEach(function(data) {//每次读取都执行以下内容
describe(data.description, function() {
it('Case ' + data.caseID + ' ' + data.description, function(done) {
request.get('/order/show.do?status=0') //发送请求
.send({
user_id=0000,
})
.expect(200)
.end(function(err, res) { //结果验证
if (err) return done(err);
utils.assertEqual('测试state', res.body.state, 'ok'); //断言
done();
})
})
});
});
})