【发布时间】:2017-04-03 15:55:44
【问题描述】:
首先,编码对我来说是新事物。到目前为止,我是 Java 应用程序的手动测试员。 现在,我的任务是学习做“自动化的事情”,但我遇到了一个问题。
我正在尝试从 MongoDB 获取数据并将其与测试数据进行比较。测试是量角器和黄瓜的混合体。
我认为问题在于我不理解或我还不知道。
在 mongoDB 我有:
{
"_id" : 123456,
"mykey" : 2
}
IDE 中的代码:
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
const expect = chai.expect;
module.exports = function () {
this.Then(/^Data should be same$/, function (callback) {
// Connection to mongoDB
const MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:8517/fpl').then(function(db) {
const collection = db.collection('test');
// Test data
const testData = [{
_id: 123456,
mykey: 2
}];
// Query to DB for data
const a = collection.find({_id: 123456}).toArray();
// "is data from DB == test data?"
return expect(a).to.eventually.equal(testData).notify(callback);
}).catch((err) => {
console.log(err);
});
结果我收到了消息:
Message:
AssertionError: expected [ { _id: 123456, mykey: 2 } ] to equal [ { _id: 123456, mykey: 2 } ]
1 scenario (1 failed)
1 step (1 failed)
0m00.094s
AssertionError: expected [ { _id: 123456, mykey: 2 } ] to equal [ { _id: 123456, mykey: 2 } ]
message: 'expected [ { _id: 123456, mykey: 2 } ] to equal [ { _id: 123456, mykey: 2 } ]',
showDiff: true,
actual: [ { _id: 123456, mykey: 2 } ],
expected: [ { _id: 123456, mykey: 2 } ] }
[14:22:34] I/local - Shutting down selenium standalone server.
[14:22:34] I/launcher - 0 instance(s) of WebDriver still running
[14:22:34] I/launcher - chrome #01 failed 1 test(s)
[14:22:34] I/launcher - overall: 1 failed spec(s)
[14:22:34] E/launcher - Process exited with error code 1
任何想法我做错了什么?
【问题讨论】:
标签: node.js mongodb typescript protractor cucumber