diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java b/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java index 25d5b152cc..07ea854102 100644 --- a/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java +++ b/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java @@ -7,6 +7,7 @@ import io.github.com.pages.BadgePage; import io.github.com.pages.ButtonTogglePage; import io.github.com.pages.ButtonsPage; +import io.github.com.pages.CheckBoxPage; import io.github.com.pages.ProgressBarPage; import io.github.com.pages.ProgressSpinnerPage; @@ -33,4 +34,7 @@ public class StaticSite { @Url("autocompletes") public static AutocompletePage autocompletePage; + + @Url("checkbox") + public static CheckBoxPage checkBoxPage; } diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/enums/CheckBoxAlignPosition.java b/jdi-light-angular-tests/src/main/java/io/github/com/enums/CheckBoxAlignPosition.java new file mode 100644 index 0000000000..cf99a06a73 --- /dev/null +++ b/jdi-light-angular-tests/src/main/java/io/github/com/enums/CheckBoxAlignPosition.java @@ -0,0 +1,15 @@ +package io.github.com.enums; + +public enum CheckBoxAlignPosition { + BEFORE("before"), + AFTER("after"); + private final String alignPosition; + + CheckBoxAlignPosition(String alignPosition) { + this.alignPosition = alignPosition; + } + + public String getAlignPosition() { + return this.alignPosition; + } +} diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/AngularPage.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/AngularPage.java index 8aaf06a478..40c0bbbc09 100644 --- a/jdi-light-angular-tests/src/main/java/io/github/com/pages/AngularPage.java +++ b/jdi-light-angular-tests/src/main/java/io/github/com/pages/AngularPage.java @@ -17,7 +17,6 @@ public class AngularPage extends WebPage { public static BottomSheet bottomSheet; public static Dialog dialog; public static RadioButtonSection radioButtonSection; - public static CheckboxSection checkboxSection; public static ToolbarSection toolbarSection; public static SlideToggleSection slideToggleSection; public static InputSection inputSection; diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/CheckBoxPage.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/CheckBoxPage.java new file mode 100644 index 0000000000..02b3bfc500 --- /dev/null +++ b/jdi-light-angular-tests/src/main/java/io/github/com/pages/CheckBoxPage.java @@ -0,0 +1,39 @@ +package io.github.com.pages; + +import com.epam.jdi.light.angular.elements.common.Checkbox; +import com.epam.jdi.light.angular.elements.complex.RadioButtons; +import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI; +import com.epam.jdi.light.ui.html.elements.common.Text; + +public class CheckBoxPage extends NewAngularPage { + @UI("#basic-checkbox") + public static Checkbox basicCheckbox; + + @UI("#indeterminate-checkbox") + public static Checkbox indeterminateCheckbox; + + @UI("#disabled-checkbox") + public static Checkbox disabledCheckbox; + + @UI("#result-checkbox") + public static Checkbox resultCheckbox; + + @UI(".mat-mdc-radio-group") + public static RadioButtons modeRadioGroup; + + @UI("#checkbox-color1") + public static Checkbox primaryColorCheckbox; + + @UI("#checkbox-color2") + public static Checkbox accentColorCheckbox; + + @UI("#checkbox-color3") + public static Checkbox warnColorCheckbox; + + @UI("#checkbox-required-option") + public static Checkbox requiredCheckbox; + + @UI("//*[@class='error']") + public static Text requiredCheckboxText; + +} diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/CheckboxSection.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/CheckboxSection.java deleted file mode 100644 index b9d8fa39b1..0000000000 --- a/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/CheckboxSection.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.github.com.pages.sections; - -import com.epam.jdi.light.angular.elements.common.Checkbox; -import com.epam.jdi.light.elements.composite.Section; -import com.epam.jdi.light.ui.html.elements.common.Button; - -public class CheckboxSection extends Section { - public static Checkbox basicCheckbox; - public static Checkbox checkedCheckbox; - public static Checkbox indeterminateCheckbox; - public static Checkbox disabledCheckbox; - public static Checkbox resultCheckbox; - - public static Button alignBeforeRadioButton; - public static Button alignAfterRadioButton; -} diff --git a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/common/CheckboxTests.java b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/common/CheckboxTests.java index e34752be17..3333000b41 100644 --- a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/common/CheckboxTests.java +++ b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/common/CheckboxTests.java @@ -1,57 +1,104 @@ package io.github.epam.angular.tests.elements.common; +import com.epam.jdi.light.angular.elements.enums.AngularColors; import io.github.epam.TestsInit; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Ignore; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import static io.github.com.StaticSite.angularPage; -import static io.github.com.pages.sections.CheckboxSection.*; -import static io.github.epam.site.steps.States.shouldBeLoggedIn; +import static io.github.com.enums.CheckBoxAlignPosition.AFTER; +import static io.github.com.enums.CheckBoxAlignPosition.BEFORE; +import static com.jdiai.tools.Timer.waitCondition; + +import static io.github.com.StaticSite.checkBoxPage; +import static io.github.com.pages.CheckBoxPage.accentColorCheckbox; +import static io.github.com.pages.CheckBoxPage.basicCheckbox; +import static io.github.com.pages.CheckBoxPage.disabledCheckbox; +import static io.github.com.pages.CheckBoxPage.indeterminateCheckbox; +import static io.github.com.pages.CheckBoxPage.modeRadioGroup; +import static io.github.com.pages.CheckBoxPage.primaryColorCheckbox; +import static io.github.com.pages.CheckBoxPage.requiredCheckbox; +import static io.github.com.pages.CheckBoxPage.requiredCheckboxText; +import static io.github.com.pages.CheckBoxPage.resultCheckbox; +import static io.github.com.pages.CheckBoxPage.warnColorCheckbox; -// TODO Move to the new page -@Ignore public class CheckboxTests extends TestsInit { - @BeforeMethod(alwaysRun = true) + @BeforeClass(alwaysRun = true) public void before() { - shouldBeLoggedIn(); - angularPage.open(); - disabledCheckbox.show(); + checkBoxPage.open(); + waitCondition((() -> checkBoxPage.isOpened())); + checkBoxPage.checkOpened(); } - @Test - public void checkLabelValue() { + @Test(description = "Test verifies label value of checkbox") + public void checkLabelValueTest() { basicCheckbox.label().has().value("Check me!"); resultCheckbox.label().has().value("I'm a checkbox"); } - @Test - public void basicCheckboxValidation() { + @Test(description = "Test verifies initial checkbox state and selection") + public void basicCheckboxValidationTest() { + basicCheckbox.show(); basicCheckbox.is().displayed().and().enabled().and().deselected(); - } - - @Test - public void checkBasicCheckbox() { basicCheckbox.check(); basicCheckbox.is().selected(); + basicCheckbox.uncheck(); } - @Test - public void indeterminateTest() { - indeterminateCheckbox.click(); + @Test(description = "Test verifies checkbox feature: indeterminate") + public void indeterminateCheckBoxTest() { + indeterminateCheckbox.show(); + indeterminateCheckbox.check(); resultCheckbox.is().indeterminate(); + indeterminateCheckbox.uncheck(); + basicCheckbox.is().notIndeterminate(); } - @Test - public void disabledOption() { - disabledCheckbox.click(); + @Test(description = "Test verifies checkbox disabled state") + public void disabledOptionCheckBoxTest() { + disabledCheckbox.check(); resultCheckbox.is().disabled(); + disabledCheckbox.uncheck(); + resultCheckbox.is().enabled(); } - @Test - public void configurableCheckboxTest() { - indeterminateCheckbox.check(); - alignBeforeRadioButton.click(); - resultCheckbox.is().indeterminate().and().cssClass("mat-checkbox-label-before"); + @Test(description = "Test verifies checkbox align positions") + public void alignPositionsCheckboxTest() { + modeRadioGroup.click(BEFORE.getAlignPosition()); + resultCheckbox.is().alignedBefore(); + modeRadioGroup.click(AFTER.getAlignPosition()); + resultCheckbox.is().alignedAfter(); + } + + @Test(description = "Test verifies checkbox feature: required option") + public void isRequiredCheckboxTest() { + requiredCheckbox.show(); + requiredCheckbox.is().required(); + requiredCheckboxText.has().text("Checkbox should be checked!"); + requiredCheckbox.check(); + requiredCheckboxText.is().notVisible(); + requiredCheckbox.uncheck(); + basicCheckbox.is().notRequired(); + warnColorCheckbox.is().notRequired(); + } + + @Test(description = "Verifies checkbox colors as Angular colors") + public void angularColorCheckBoxTest() { + //Check color for checkboxes with attribute 'color' + primaryColorCheckbox.has().angularColor(AngularColors.PRIMARY); + accentColorCheckbox.has().angularColor(AngularColors.ACCENT); + warnColorCheckbox.has().angularColor(AngularColors.WARN); + //Check color for checkbox without attribute 'color' + requiredCheckbox.has().angularColor(AngularColors.ACCENT); } + + @Test(description = "Verifies checkbox colors as strings") + public void colorCheckBoxTest() { + //Check color for checkboxes with attribute 'color' + primaryColorCheckbox.has().color("primary"); + accentColorCheckbox.has().color("accent"); + warnColorCheckbox.has().color("warn"); + //Check color for checkbox without attribute 'color' + requiredCheckbox.has().color("accent"); + } + } diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/CheckboxAssert.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/CheckboxAssert.java index 6a8367d547..7e061774a2 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/CheckboxAssert.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/CheckboxAssert.java @@ -1,6 +1,7 @@ package com.epam.jdi.light.angular.asserts; import com.epam.jdi.light.angular.elements.common.Checkbox; +import com.epam.jdi.light.angular.elements.enums.AngularColors; import com.epam.jdi.light.asserts.generic.UIAssert; import com.epam.jdi.light.common.JDIAction; import org.hamcrest.Matchers; @@ -10,33 +11,76 @@ public class CheckboxAssert extends UIAssert { @JDIAction("Assert that '{name}' is selected") public CheckboxAssert selected() { - jdiAssert(element().isSelected(), Matchers.is(true)); + jdiAssert(element().isSelected(), Matchers.is(true), "Checkbox is not selected"); return this; } @JDIAction("Assert that '{name}' is not selected") public CheckboxAssert deselected() { - jdiAssert(element().isSelected(), Matchers.is(false)); + jdiAssert(element().isSelected(), Matchers.is(false), "Checkbox is selected"); return this; } @JDIAction("Assert that '{name}' is indeterminate") public CheckboxAssert indeterminate() { - jdiAssert(element().isIndeterminate(), Matchers.is(true)); + jdiAssert(element().isIndeterminate(), Matchers.is(true), "Checkbox is determinate"); + return this; + } + + @JDIAction("Assert that '{name}' is not indeterminate") + public CheckboxAssert notIndeterminate() { + jdiAssert(element().isIndeterminate(), Matchers.is(false), "Checkbox is indeterminate"); return this; } @JDIAction("Assert that '{name}' is enabled") @Override public CheckboxAssert enabled() { - jdiAssert(element().isEnabled(), Matchers.is(true)); + jdiAssert(element().isEnabled(), Matchers.is(true), "Checkbox is disabled"); return this; } @JDIAction("Assert that '{name}' is disabled") @Override public CheckboxAssert disabled() { - jdiAssert(element().isDisabled(), Matchers.is(true)); + jdiAssert(element().isDisabled(), Matchers.is(true), "Checkbox is enabled"); + return this; + } + + @JDIAction("Assert that '{name}' is aligned in before position") + public CheckboxAssert alignedBefore() { + jdiAssert(element().isAlignedBefore(), Matchers.is(true), "Checkbox is aligned after"); + return this; + } + + @JDIAction("Assert that '{name}' is aligned in after position") + public CheckboxAssert alignedAfter() { + jdiAssert(element().isAlignedBefore(), Matchers.is(false), "Checkbox is aligned before"); + return this; + } + + @JDIAction("Assert that '{name}' is required") + public CheckboxAssert required() { + jdiAssert(element().isRequired(), Matchers.is(true), "Checkbox does not have feature: required"); + return this; + } + + @JDIAction("Assert that '{name}' is not required") + public CheckboxAssert notRequired() { + jdiAssert(element().isRequired(), Matchers.is(false), "Checkbox has feature: required"); return this; } + + @JDIAction("Assert that '{name}' angular color is '{0}'") + public CheckboxAssert angularColor(AngularColors expectedColor) { + jdiAssert(element().color(), Matchers.is(expectedColor)); + return this; + } + + @JDIAction("Assert that '{name}' color is '{0}'") + public CheckboxAssert color(String expectedColor) { + jdiAssert(element().color().getColor(), Matchers.is(expectedColor)); + return this; + } + } diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/Checkbox.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/Checkbox.java index 1dc2d0993c..acafa3ccf2 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/Checkbox.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/Checkbox.java @@ -1,6 +1,7 @@ package com.epam.jdi.light.angular.elements.common; import com.epam.jdi.light.angular.asserts.CheckboxAssert; +import com.epam.jdi.light.angular.elements.enums.AngularColors; import com.epam.jdi.light.common.JDIAction; import com.epam.jdi.light.elements.base.UIBaseElement; import com.epam.jdi.light.elements.common.Label; @@ -9,6 +10,7 @@ import com.epam.jdi.light.elements.interfaces.base.HasCheck; import com.epam.jdi.light.elements.interfaces.base.HasClick; import com.epam.jdi.light.elements.interfaces.base.HasLabel; +import org.openqa.selenium.By; import static com.epam.jdi.light.common.Exceptions.runtimeException; @@ -39,30 +41,38 @@ public void uncheck() { @Override public boolean isSelected() { boolean attribute = hasAttribute(ARIA_CHECKED) && attr(ARIA_CHECKED).equals("true"); - return hasClass("mat-checkbox-checked") || attribute || core().isSelected(); + return hasClass("mat-mdc-checkbox-checked") || attribute || core().isSelected(); } @JDIAction("Is '{name}' enabled") @Override public boolean isEnabled() { - if (hasClass("mat-checkbox-disabled")) { + if (hasClass("mdc-checkbox--disabled")) { return false; } else { return super.isEnabled(); } } - + @JDIAction("Is '{name}' disabled'") @Override public boolean isDisabled() { return !isEnabled(); } + @JDIAction("Is '{name}' text aligned in before position") + public boolean isAlignedBefore() { + UIElement element = core().find(By.cssSelector(".mdc-form-field")); + if (element != null) { + return element.hasClass("mdc-form-field--align-end"); + } else { + return false; + } + + } + @JDIAction("Get '{name}' label") @Override public Label label() { - if (core().label().isDisplayed()) { - return core().label(); - } UIElement input = core().find("input[type=checkbox]"); if (input.label().isDisplayed()) { return input.label(); @@ -70,19 +80,37 @@ public Label label() { throw runtimeException("Can't find label for element %s", this); } - @JDIAction("Click on '{name}'") - @Override - public void click() { - if (label().isDisplayed()) { - label().click(); - } else { - core().click(); - } + @JDIAction("Get if '{name}' indeterminate") + public boolean isIndeterminate() { + return core().find(By.cssSelector(".mdc-checkbox__native-control:indeterminate~.mdc-checkbox__background")) + .isExist(); } - @JDIAction("Is '{name}' indeterminate") - public boolean isIndeterminate() { - return hasClass("mat-checkbox-indeterminate") || attr(ARIA_CHECKED).equals("mixed"); + @JDIAction("Get if '{name}' is required") + public boolean isRequired() { + return attrs().has("required"); + } + + /** + * Get element color. + * If there is an attribute "color" - get by attribute, + * if there is no attribute "color" - get by class. + * @return Angular color + */ + @JDIAction(value = "Get '{name}' color") + public AngularColors color() { + if (core().hasAttribute("color")) { + return AngularColors.fromColor(core().getAttribute("color")); + } else { + if (core().hasClass("mat-primary")) { + return AngularColors.PRIMARY; + } + if (core().hasClass("mat-warn")) { + return AngularColors.WARN; + } else { + return AngularColors.ACCENT; + } + } } @Override