Is it possible to create a reusable jasmine matcher that would assert a function to run for less than N seconds?
Sample expectation style:
expect(someFunction, [arg1, arg2]).toBeCompletedForLessThan(3);
expect(obj.someMethod, [arg1, arg2]).toBeCompletedForLessThan(5);
We'd like to tie this up with Protractor and custom performance tests where we want to assert that certain UI execution steps don't go beyond the time limit.
I would measure the elapsed time with a custom timer and then assert the result with .toBeLessThan
:
var timer = Timer();
$("#mytext").getText().then(function(text){
console.log(text);
});
expect(timer.elapsed).toBeLessThan(1000); // to be under 1 second
The timer:
var Timer = function() {
var starttime = 0;
browser.controlFlow().execute(function() {
starttime = Date.now()
});
return {
get elapsed() {
return browser.controlFlow().execute(() => Date.now() - starttime);
}
};
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With