Velocity Cucumber - Help with Lookups via TEST Database

I’m trying to do something very trivial with velocity and cucumber:

  • Sign user up via cucumber steps
  • Look in db for the saved user

The user is being saved to the test database as I would expect. I have verified this through running a query on db.users in the cucumber db via terminal.

The problem is when I try to lookup the user in my cucumber step via Meteor.users.find() it’s giving me a bunch of unexpected gobbledygook (which I’ve pasted at the end of this post). Can someone please help me run a query on my data from my Cucumber step?

CUCUMBER STEP - JUST TRYING TO CONSOLE.LOG THE SAVED USER

    this.Then(/^I should go to the dashboard for that user$/, function (callback) {
      var theUser = Meteor.users.find({});
      console.log(theUser);
      callback();
    });

OUTPUT

{ _mongo:
I20150404-13:23:03.222(-5)?    { _observeMultiplexers:
I20150404-13:23:03.222(-5)?       { '{"ordered":false,"collectionName":"velocityMirrors","selector":{"framework":"cucumber","state":"ready"},"options":{"transform":null}}': [Object],
I20150404-13:23:03.222(-5)?         '{"ordered":false,"collectionName":"meteor_accounts_loginServiceConfiguration","selector":{},"options":{"transform":null,"fields":{"secret":0}}}': [Object],
I20150404-13:23:03.222(-5)?         '{"ordered":false,"collectionName":"velocityTestFiles","selector":{},"options":{"transform":null}}': [Object],
I20150404-13:23:03.222(-5)?         '{"ordered":false,"collectionName":"velocityFixtureFiles","selector":{},"options":{"transform":null}}': [Object],
I20150404-13:23:03.222(-5)?         '{"ordered":false,"collectionName":"velocityTestReports","selector":{},"options":{"transform":null}}': [Object],
I20150404-13:23:03.222(-5)?         '{"ordered":false,"collectionName":"velocityAggregateReports","selector":{},"options":{"transform":null}}': [Object],
I20150404-13:23:03.223(-5)?         '{"ordered":false,"collectionName":"velocityLogs","selector":{},"options":{"transform":null}}': [Object],
I20150404-13:23:03.223(-5)?         '{"ordered":false,"collectionName":"velocityMirrors","selector":{},"options":{"transform":null}}': [Object],
I20150404-13:23:03.223(-5)?         '{"ordered":false,"collectionName":"velocityTestFiles","selector":{"targetFramework":"cucumber"},"options":{"transform":null}}': [Object] },
I20150404-13:23:03.223(-5)?      _onFailoverHook: { nextCallbackId: 9, callbacks: [Object] },
I20150404-13:23:03.223(-5)?      db:
I20150404-13:23:03.223(-5)?       { domain: null,
I20150404-13:23:03.224(-5)?         _events: {},
I20150404-13:23:03.225(-5)?         _maxListeners: 10,
I20150404-13:23:03.225(-5)?         databaseName: 'meteor',
I20150404-13:23:03.225(-5)?         serverConfig: [Object],
I20150404-13:23:03.225(-5)?         options: [Object],
I20150404-13:23:03.225(-5)?         _applicationClosed: false,
I20150404-13:23:03.226(-5)?         slaveOk: false,
I20150404-13:23:03.226(-5)?         bufferMaxEntries: -1,
I20150404-13:23:03.226(-5)?         native_parser: false,
I20150404-13:23:03.226(-5)?         bsonLib: [Object],
I20150404-13:23:03.226(-5)?         bson: [Object],
I20150404-13:23:03.226(-5)?         bson_deserializer: [Object],
I20150404-13:23:03.227(-5)?         bson_serializer: [Object],
I20150404-13:23:03.227(-5)?         _state: 'connected',
I20150404-13:23:03.227(-5)?         pkFactory: [Object],
I20150404-13:23:03.227(-5)?         forceServerObjectId: false,
I20150404-13:23:03.227(-5)?         safe: false,
I20150404-13:23:03.227(-5)?         notReplied: {},
I20150404-13:23:03.228(-5)?         isInitializing: true,
I20150404-13:23:03.228(-5)?         openCalled: true,
I20150404-13:23:03.228(-5)?         commands: [],
I20150404-13:23:03.228(-5)?         logger: [Object],
I20150404-13:23:03.228(-5)?         tag: 1428171705676,
I20150404-13:23:03.229(-5)?         eventHandlers: [Object],
I20150404-13:23:03.229(-5)?         serializeFunctions: false,
I20150404-13:23:03.229(-5)?         raw: false,
I20150404-13:23:03.229(-5)?         recordQueryStats: false,
I20150404-13:23:03.229(-5)?         retryMiliSeconds: 1000,
I20150404-13:23:03.229(-5)?         numberOfRetries: 60,
I20150404-13:23:03.230(-5)?         readPreference: [Object] },
I20150404-13:23:03.230(-5)?      _primary: '127.0.0.1:3001',
I20150404-13:23:03.230(-5)?      _oplogHandle:
I20150404-13:23:03.230(-5)?       { _oplogUrl: 'mongodb://127.0.0.1:3001/local',
I20150404-13:23:03.230(-5)?         _dbName: 'meteor',
I20150404-13:23:03.231(-5)?         _oplogLastEntryConnection: [Object],
I20150404-13:23:03.231(-5)?         _oplogTailConnection: [Object],
I20150404-13:23:03.231(-5)?         _stopped: false,
I20150404-13:23:03.231(-5)?         _tailHandle: [Object],
I20150404-13:23:03.231(-5)?         _readyFuture: [Object],
I20150404-13:23:03.231(-5)?         _crossbar: [Object],
I20150404-13:23:03.232(-5)?         _baseOplogSelector: [Object],
I20150404-13:23:03.232(-5)?         _catchingUpFutures: [],
I20150404-13:23:03.232(-5)?         _lastProcessedTS: [Object],
I20150404-13:23:03.232(-5)?         _onSkippedEntriesHook: [Object],
I20150404-13:23:03.232(-5)?         _entryQueue: [Object],
I20150404-13:23:03.232(-5)?         _workerActive: false },
I20150404-13:23:03.233(-5)?      _docFetcher: { _mongoConnection: [Circular], _callbacksForCacheKey: {} } },
I20150404-13:23:03.233(-5)?   _cursorDescription:
I20150404-13:23:03.233(-5)?    { collectionName: 'users',
I20150404-13:23:03.233(-5)?      selector: {},
I20150404-13:23:03.234(-5)?      options: { transform: null } },
I20150404-13:23:03.234(-5)?   _synchronousCursor: null }
I20150404-13:23:03.234(-5)? ..

Note:

If I write the query with findOne instead, the console just logs undefined

try Meteor.users.find().fetch(). You’re outputting the cursor from Mongo :slight_smile:

Hi Sam! Thanks for answering despite how busy you must be with your book.

If I append .fetch() nothing is output to the terminal.

Cucumber step

     this.Then(/^I should go to the dashboard for that user$/, function (callback) {
      var theUser = Meteor.users.find().fetch();
      console.log("the user is: ",theUser);
      callback();
    });

Terminal Output

I20150404-14:38:20.882(-5)? [14:38:20]:  SET SESSION ID 2668afd0-db02-11e4-a40c-0b8bcb6b2d31
I20150404-14:38:21.504(-5)? ........the user is:  []
I20150404-14:38:21.509(-5)? ..

When I check the cucumber db through:

  • meteor mongo,
  • use cucumber
  • then running db.users.find()

The test user that was created in my cuke is returned. So I know that my cuke is definitely saving my test user(s). Is it possible that when I run my query it’s doing it in the Dev database rather than the Test? When I log process.env.NODE_ENV it returns development Don’t know if that means anything or not.

You’re right, cucumber steps run in the main app. I should have mentioned that. You can do a DDP call from cucumber to the mirror if you want, or you can have a fixture that allows you to do run code inside the mirror. One good pattern is to put methods in your fixture and call them with DDP from the cukes.

I’m rewriting meteor-cucumber as we speak. It’s almost there and it no longer runs in the meteor context. It’s a completely separate process now so DDP calls is the way to ensure forward compatibility for your test code. Expect an announcement soon!

Thanks a ton of your help and all the hard work! I really appreciate it. Looking forward to the announcement.

Cucumber rewrite is in rc.7, could you please try it:

Thanks for reaching out! Will take a look tonight.

Rob Walsh
Sent with Airmail

Hey Sam!

I took a look last night and i did a test just console.log-ing some data and it is def coming from where I would expect (the test database instead of development). Thanks for being so responsive to the community. We appreciate it!

Awesome, glad to hear it worked and thanks for the kind words

Hey @sam one quick thing.

Not sure if I’m writing this incorrectly or not but since my cucumber upgrade my webdriver.io ‘click’ steps aren’t working anymore.

Whether I write them

   this.When(/^I click "([^"]*)"$/, function (arg1, callback) {
    this.browser.
      waitForExist('#sign-up', 7000).
      click('#sign-up').
      call(callback);
});

or

this.When(/^I click "([^"]*)"$/, function (arg1, callback) {
  this.browser.
    waitForExist('#sign-up', 7000).
    click('#sign-up').
    and.notify(callback)
});

they always return with the following error:

 RuntimeError: RuntimeError
 (NoSuchElement:7) An element could not be located on the page using the given search parameters.
 Problem: Unable to find element with id 'sign-up'

 Callstack:
 -> element("#sign-up")
 -> click("#sign-up")

I’m 99.9% sure this element is on the page. Are there any gotchas that I should know about the update that might not be in the docs?

you can try two things. One is to pause(1000) before the click, and the other is to saveScreenshot() to be sure it’s visible