Testing Angular - How can I test disabled field using Selenium Protractor?

73 Views Asked by At

In MEAN stack project I am using Selenium webdriver for frontend UI testing.

I have a field which is non editable. I have attached an image

Image

How can I test this field making sure it cannot be edited?


    it('not edit the field', () => {
        login('amazonuser');
        click(by.xpath('//mat-option[5]/span[contains(., "Amazon Id")]'));
        getElement(by.xpath('//id-number/div/mat-form-field[2]/div/div[1]/div/input')).sendKeys('0');
        logout();
    });
1

There are 1 best solutions below

3
JeffC On BEST ANSWER

You assert that the disabled attribute is on the INPUT.

var input = element(by.xpath('//id-number/div/mat-form-field[2]/div/div[1]/div/input'))
expect(input.isEnabled()).toBe(true);

See the HTML docs.
See the Protractor docs.