Skip to content

Conversation

@HughZurname
Copy link
Contributor

What does this contain?

What's outstanding?

  • Unit tests
  • More documentation and examples.

@HughZurname HughZurname changed the title Database Helper initial work Database Helper - Initial work Jun 16, 2017
@HughZurname HughZurname changed the title Database Helper - Initial work [WIP] Database Helper - Initial work Jun 16, 2017
@DavertMik
Copy link
Contributor

Thanks for the pull request. However, I need to understand it a bit more
I never used LokiJS so I don't understand the use cases for it. Could you explain how do you use it?
Why Loki?

@HughZurname
Copy link
Contributor Author

HughZurname commented Jun 21, 2017

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.

@DavertMik
Copy link
Contributor

I was thinking on this and concluded that this module is too specific.
I'm not sure how useful it can be for wide audience.
So I'd propose to publish this helper as standalone package and I will add a link to it into Data Management chapter of documentation (which I'm currently writing)

@HughZurname
Copy link
Contributor Author

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.

@DavertMik
Copy link
Contributor

DavertMik commented Jun 25, 2017

Not meta-packages, they are just for simpler installations.

So you extract your helper, then and create npm package, named like: 'codeceptjs-loki'.
Then anyone can install this package and include your helper like:

"helpers": {
  "Loki": {
    "require": "codeceptjs-loki"
  }
}

CodeceptJS will execute require('codeceptjs-loki') to load the helper.
That's all!

@HughZurname
Copy link
Contributor Author

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.

"helpers": {
  "Loki": {
    "require": "node_modules/codeceptjs-loki"
  }
}

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.

@HughZurname HughZurname deleted the feature/database branch July 5, 2017 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] - Database Helper saveScreenshot() doesn't work for failed scenarios using PhantomJS

2 participants