-
-
Notifications
You must be signed in to change notification settings - Fork 752
[WIP] Database Helper - Initial work #557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This was causing the SeleniumWebdriver tests to fail as the window size isn't reset after prior tests.
|
Thanks for the pull request. However, I need to understand it a bit more |
|
Hey 😄. Loki is just a mongoDB like in memory document store, the main reason I chose it is because it's really lightweight and provides a lot of functionality for it's footprint. The reason I ended up using it was because I needed to effectively store some variables between tests to validate against in a later scenario. At the time I figured I could just use the filesystem helper, but static files proved insufficient for the task. I think the best explanation would be to give you a more concise version of how I've used it in my own tests. I've added commentary inline: Feature("Order - User Details");
let user, claimId;
Scenario("Enter user Details", function* (I) {
//Here I am retrieving some user form data that I seeded before the test execution.
//The arguments are the document store I am querying 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("Document 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("addressLine1", user.address1);
I.dontSee("Address1 is required");
I.fillField("postCode", user.postcode);
I.dontSee("Postcode is required");
I.fillField("phoneNumber", user.number);
I.dontSee("Telephone number is required");
I.fillField("email", user.email);
I.dontSee("Must be a valid email");
});
Scenario("Save & Continue", function* (I) {
I.click("Save & Continue");
//Custom helper function to grab the order id from the url.
claimId = yield I.grabUrlPart(4);
});
AfterSuite((I) => {
//Here I create a new document store for orders before inserting relevant data from the tests I've just completed.
//This becomes queryable like users was above in later scenarios allowing me to validate against known values while still being able to use dynamic data to drive testing.
I.addCollection("orders");
I.insert("orders", {
orderId: claimId,
orderNumber: testId,
email: user.email,
fullName: `${user.firstname} ${user.surname}`,
});
});I hope this makes sense? If not, just let me know and I'll answer it as best I can. |
|
I was thinking on this and concluded that this module is too specific. |
|
Sure 😁, how would I go about doing that? Are there any examples of this having been done for codecept that I could use as a rough guide? I saw something about meta-packages, but I'm guessing that's not quite what I'm aiming for. |
|
Not meta-packages, they are just for simpler installations. So you extract your helper, then and create npm package, named like: 'codeceptjs-loki'. "helpers": {
"Loki": {
"require": "codeceptjs-loki"
}
}CodeceptJS will execute |
|
Hi 😄 So I've extracted it to it's own package and published it to npm here and it seems to work as mostly you've described above. The only difference is that it's necessary to give it an explicit path for some reason. I've tried to look at the config creation scripts to try and track down why this may happen, but I've not managed to follow it through. |
What does this contain?
What's outstanding?