dalekjs / dalek

[unmaintained] DalekJS Base framework
MIT License
695 stars 63 forks source link

Feature request: create custom assertions via callback #123

Open krnlde opened 10 years ago

krnlde commented 10 years ago

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();
krnlde commented 10 years ago

Casper has what I am looking for: http://docs.casperjs.org/en/latest/modules/tester.html#asserteval

asciidisco commented 10 years ago

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

gskachkov commented 9 years ago

I've implemented small changes to support this feature in PR https://github.com/dalekjs/dalek/pull/141

ghost commented 9 years ago

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?

gskachkov commented 9 years ago

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

ghost commented 9 years ago

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

gskachkov commented 9 years ago

@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 
ghost commented 9 years ago

:+1: Thanks @gskachkov that early package works well.

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