I need to check with Protractor if a button in my angular application is enabled, for so this is my test:
it('submit should not be enabled',function() {
var price = by.name('price'),
oldCategory = by.name('oldCategory'),
newCategory = by.name('newCategory'),
oldPayment = by.name('oldPayment'),
newPayment = by.name('newPayment'),
item = by.name('item'),
submit = by.id('submitButton');
expect(submit.isEnabled().toBe(false));
});
when I run the test, get this error:
TypeError: Object By.name("price") has no method 'isEnabled'
Use the disabled property to check if an element is disabled, e.g. if (element. disabled) {} . The disabled property returns true when the element is disabled, otherwise false is returned.
isEnabled() This method verifies if an element is enabled. If the element is enabled, it returns a true value. If not, it returns a false value. The code below verifies if an element with the id attribute value next is enabled.
toBe([true|false]); to accurately verify if something is enabled/disabled. If that isn't working for you, there's probably something else going on. Taylor is right, isEnabled() is the correct way to do it.
The parenthesis is misplaced in the expectation
:
expect(submit.isEnabled().toBe(false));
it should be :
expect(submit.isEnabled()).toBe(false);
And you misuse the protractor locator
:
submit = by.id('submitButton');
it should be :
submit = element(by.id('submitButton'));
You could find a lot of examples in the specs of protractor.
Try the following:
submit = element(by.id('submitButton'));
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