Codecept Helper with in memory databse (provided by loki.js) for data driven testing and result capturing.
npm install codeceptjs-loki- Intro
- Config
- Loki
- constructor
- addCollection
- findCollection
- removeCollection
- insert
- clear
- find
- findOne
- findAndUpdate
- findAndRemove
- importData
- Example
Codecept Helper with in memory databse (provided by loki.js) for data driven testing and result capturing. An example scenario can be found below
Add to codecept.conf.js with:
``javascript`
exports.config = {
helpers: {
Nightmare: {
url: "http://localhost"
},
Loki: {
"require": "node_modules/codeceptjs-loki",
"dbName": "db.json",
"dbSeed": true
}
}
/...some config/
}
or to codecept.json with:
`json`
{
"helpers": {
"Nightmare": {
"url": "http://localhost"
},
"Loki": {
"require": "node_modules/codeceptjs-loki",
"dbName": "db.json",
"dbSeed": true
}
}
}
Extends Helper
Helper with in memory databse for data driven testing and result capturing.
Parameters
- config
Parameters
- config Object configuration can be overridded by values found in \codecept.json
Will check for an existing collection of the same name and return that, if it already exists.
Parameters
- collection string creates a collection with supplied name.
Parameters
- collection string name of desired collection.
Removes a matching collection.
Parameters
- collection string finds a collection that matches the supplied name
Inserts records from the supplied data to a matching collection.
Parameters
- collection string name of desired collection.
- data Array takes an array of objects as records for the destination collection.
Clears data from a matching collection.
Parameters
- collection string name of desired collection.
Searches the Users colection for matching values.
Parameters
- collection string name of desired collection.
- query Object used in searching the destination collection for matching values.
Examples
``javascript`
// Searches for a user with an email of "someone@email.com"
I.find("Users",{email: "someone@email.com"})
Returns Array Returns an array of objects that match.
Effectively the same as find() but returns a single object rather than an array.
Parameters
- collection string name of desired collection.query
- Object used in searching the destination collection for matching values.
Finds a list of values based on the supplied query and runs an update function on each result.
Parameters
- collection string name of desired collection.query
- Object used in searching the destination collection for matching values.updateFunction
- function executes against each of the results in the result array.
Examples
`javascript`
// Before {email: "someone@email.com", firstname: "Some", surname: "One", address1: "1 Some Place"}
I.findAndUpdate("users",{email: "someone@email.com"},(res)=>{res.number = "01234567890"})
// Find updated record
I.findOne("Users",{email: "someone@email.com"})
// After {email: "someone@email.com", firstname: "Some", surname: "One", address1: "1 Some Place", number:01234567890}
Like findAndUpdate() but finds a record in a collection and removes it.
Parameters
- collection string name of desired collection.query
- Object used in searching the destination collection for matching values.
Imports data from a directory into a collection. Uses file names to create a collection of the same name and imports the contents of the file as records to the destination.
Parameters
- dir string takes a directory as a string.
`javascript${user.firstname} ${user.surname}
Feature("Order - User Details");
let user, claimId;
Scenario("User Details", function (I) {
//Retrieving some user form data that was seeded before the test execution.
//The arguments are the document store being queried and the query object itself.
//The first matching value is selected, but this can just as easily be used to randomise the selected user.
user = yield I.findOne("users", {
email: "someguy@email.com"
});
//testId is generated elsewhere per run
I.fillField("orderNumber", testId);
I.dontSee("Order number is required");
I.fillField("firstName", user.firstname);
I.dontSee("First name is required");
I.fillField("surname", user.surname);
I.dontSee("Surname is required");
I.fillField("address", user.address);
I.dontSee("Address is required");
I.fillField("email", user.email);
I.dontSee("Must be a valid email");
I.click("Save");
//Example custom helper function to grab the "order id" from the url.
claimId = yield I.grabUrlPart(4);
});
AfterSuite((I) => {
//Create a new document store for orders before inserting relevant data from the test above.
//This becomes queryable in later scenarios/features, like users was above. Thus allowing validation against known values while still allowing the use dynamic data to drive testing.
I.addCollection("orders");
I.insert("orders", {
orderId: claimId,
orderNumber: testId,
email: user.email,
fullName: ,``
});
});