Added isChecked method to verify the status of checkbox widget (#5173)

* added method to assert on checkbox widget, isChecked

* removed unnecessary method

* added method in checkboxWidget

* moved the method to checkbox widget
This commit is contained in:
Geeta Mandakini Ayyalasomayajula
2019-10-22 15:38:55 +01:00
committed by Eugenio Romano
parent 9f69a7d4ee
commit b7ec525b62

View File

@@ -16,14 +16,15 @@
*/
import { FormFields } from '../formFields';
import { BrowserActions } from '../../../utils/public-api';
import { by, element } from 'protractor';
import { BrowserActions, BrowserVisibility } from '../../../utils/public-api';
import { by, element, Locator } from 'protractor';
import { ElementFinder } from 'protractor';
export class CheckboxWidget {
formFields: FormFields = new FormFields();
checkboxLabel: ElementFinder = element(by.css('span[class*="mat-checkbox-label"]'));
checkboxLocator: Locator = by.css('mat-checkbox');
getCheckboxLabel(): Promise<string> {
return BrowserActions.getText(this.checkboxLabel);
@@ -41,4 +42,14 @@ export class CheckboxWidget {
async isCheckboxHidden(fieldId): Promise<void> {
await this.formFields.checkWidgetIsHidden(fieldId);
}
async isCheckboxChecked(fieldId): Promise<boolean> {
let isChecked: boolean = false;
const checkboxWidget: ElementFinder = await (await this.formFields.getWidget(fieldId)).element(this.checkboxLocator);
await BrowserVisibility.waitUntilElementIsVisible(checkboxWidget);
await checkboxWidget.getAttribute('class').then((attributeValue) => {
isChecked = attributeValue.includes('mat-checkbox-checked');
});
return isChecked;
}
}