Using protractor to disable an attribute on a button does not work

I am trying to get attr disabled on a button, it should be "disabled", but I don't seem to get the value. New for angular and protractor!

When I look at the page, this is what the HTML that I get for the button showing disabled is disabled, for example, on the page:

<button type="submit" class="button primary inverse" ng-disabled="!comment.$dirty && comment.$valid" disabled="disabled">Save</button> 

In the transporter test, below returns the value "Expected null equal to disabled"

  var btnSave = element(by.css('.primary')); expect(btnSave.isPresent()).toBeTruthy(); var attr = element(by.css('.primary')).getAttribute('disabled'); expect(attr).toEqual("disabled"); 

When I try, I expect `` equal to disabled.

 expect(attr).toEqual("disabled"); 

Any ideas I'm wrong about?

thanks

+5
source share
1 answer

getAttribute() The function in the transporter returns a value in the form of a promise. Thus, you either waited for it to return, and then performed validation, or you can pass the function to the expectation function, which, in turn, will resolve the promise. The disabled html attribute is a boolean attribute, and therefore the return value is either true or false . Here's how -

 element(by.css('.primary')).getAttribute('disabled').then(function(attr){ expect(attr).toBe(true); }); 

OR

 expect(element(by.css('.primary')).getAttribute('disabled')).toBe(true); 

Hope this helps.

+7
source

Source: https://habr.com/ru/post/1241809/


All Articles