Skip to content

Instantly share code, notes, and snippets.

@Xotabu4
Created March 13, 2016 15:57
Show Gist options
  • Select an option

  • Save Xotabu4/e84ef362d2d7abbbefde to your computer and use it in GitHub Desktop.

Select an option

Save Xotabu4/e84ef362d2d7abbbefde to your computer and use it in GitHub Desktop.
Custom jasmine matchers with waiting
describe('Protractor Experiments', function () {
beforeEach(function () {
var customMatchers = {
toAppear: function () {
return {
compare: function(actual, expected) {
return {
pass: actual.ptor_.wait(protractor.ExpectedConditions.visibilityOf(actual), 2000)
.thenCatch((err) => false),
message: 'OLOLO FAILED! ' + actual.parentElementArrayFinder.locator_.toString()
}
}
};
},
toDissapear: function () {
return {
compare: function(actual, expected) {
return {
pass: actual.ptor_.wait(protractor.ExpectedConditions.invisibilityOf(actual), 5000).then(undefined, err=> false),
message: 'OLOLO FAILED! ' + actual.parentElementArrayFinder.locator_.toString()
};
}
};
}
};
jasmine.addMatchers(customMatchers);
});
fit('creating custom jasmine matcher function with wait', function () {
browser.get('http://www.protractortest.org/testapp/ng1/#/form');
//expect($('body')).toAppear();
let nonexit = $('nonexist');
//Тут весь фокус - нужно передавать промис а не ElementFinder :)
expect(protractor.promise.fulfilled(nonexit)).toAppear();
expect(protractor.promise.fulfilled(nonexit)).toAppear();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment