dalekjs/dalek

Feature request: create custom assertions via callback

krnlde opened this issue · 8 comments

It would be awesome to add custom assertions to a test similar to the .execute() function, like so

test.open('http://google.com/')
  .waitForElement('body')
  .assert.query('#someElement').evaluate(function () {
    return this.offsetLeft == 0;
  }, 'Your Message').end()
  .done();

Interesting approach, I never thought of it; could be very useful & seems intuitive.
We will consider it for the rewrite of the code base, that we are currently doing, you can check it here: https://github.com/dalekjs/skaro

I've implemented small changes to support this feature in PR #141

I've been needing something just like this so I upgraded to 0.0.9 today to test it out.

However, when I'm trying to run a test I'm getting { '0': [TypeError: Cannot call method 'apply' of undefined] } when trying to use test.assert.evaluate();

It looks like the method is not available on the driver. I am using Chrome driver (Chrome stable 39.0.2171.95).

Would this be an issue with the implementation of the evaluate method or an issue with the evaluate method not being available with the installed driver?

@timrnz Hmm, I can reproduce the issue. I'll check what is wrong little bit later today, and hope to provide solution tomorrow.

Thanks @gskachkov that's much appreciated. Looking forwards to finding out what might be causing the issue.

@timrnz It seems that it was my fault and small part of the fix from another module (dalek-driver-native) wasn't included into release. I'll create PR to fix this in future release.
I've created additional early package that allow to check this fix and avoid waiting until my PR will be merged and released inside of the dalek.

To install it run following command inside of the project folder:

npm install dalek-cli-early  -g
npm install dalekjs-early

To run test use following command

dalek-early folder_with_your_test/dalek-test.js 

👍 Thanks @gskachkov that early package works well.

Should hopefully be enough to convince @asciidisco to merge that PR for you and cut a release.