This repository was archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
Custom matchers does not wait for promise in result.pass to be resolved #3020
Copy link
Copy link
Closed
Labels
Description
- Node Version: 4.2.3 && 4.2.2
- Protractor Version: 3.1.1 , jasminewd 0.8
- Browser(s): Chrome, Firefox
- Operating System and Version MacOS and Windows
- Your protractor configuration file
exports.config = {
directConnect: true,
framework: 'jasmine2',
specs: ['script.js'],
capabilities: {
'browserName': 'chrome'
},
onPrepare: function() {
}
};
- A relevant example test
describe('Protractor Experiments', function () {
beforeEach(function () {
var customMatchers = {
toDisappear: function () {
return {
compare: function (actual, expected) {
var result = {};
//i have to deal with 2 browsers same time, so to not pass aditional parameter i use ptor_
result.pass = actual.ptor_.wait(protractor.ExpectedConditions.invisibilityOf(actual), 2000)
.then(() => {
result.message = 'invisible!';
return true
}, err => {
result.message = 'visible!';
return false
}
);
return result;
}
};
},
};
jasmine.addMatchers(customMatchers);
});
it('creating custom jasmine matcher function with wait', function () {
browser.get('http://www.protractortest.org/testapp/ng1/#/form');
let nonexist = $('nonexist');
let exist = $('body');
expect(nonexist).toDisappear();
expect(exist).toDisappear(); //this passes without failure.
});
- Output from running the test:
> protractor_experiment@1.0.0 test D:\protractor_experiment
> node ./node_modules/protractor/bin/protractor config.js
Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
Started
.
Ran 1 of 4 specs
1 spec, 0 failures
Finished in 4.153 seconds
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed
Process finished with exit code 0
Problem:
Hi guys! I really apreciate what you are doing! I was trying to extend jasminewd matchers a little, but got a problem that my matchers does not fail if condition does not meet - i think that because jasminewd does not wait for promise to resolve, and use result in result.pass as it is, so it always True.
Please see my test code in example.
Also i see when i pass promise instead ElementFinder to expect() function it works fine with my matcher, but i would be happy to avoid that wrapping to promise.
let nonexist = $('nonexist');
let exist = $('body');
expect(protractor.promise.fulfilled(nonexist)).toDisappear();
expect(protractor.promise.fulfilled(exist)).toDisappear(); //correctly fails.