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 0c329d4132..7379bdb770 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 @@ -14,6 +14,7 @@ import io.github.com.pages.ProgressSpinnerPage; import io.github.com.pages.RadioButtonPage; import io.github.com.pages.SlideTogglePage; +import io.github.com.pages.FormFieldsPage; @JSite("https://jdi-testing.github.io/jdi-light/angular-page/#/") public class StaticSite { @@ -53,4 +54,7 @@ public class StaticSite { @Url("slide_toggle") public static SlideTogglePage slideTogglePage; + + @Url("form_field") + public static FormFieldsPage formFieldPage; } diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/FormFieldsPage.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/FormFieldsPage.java new file mode 100644 index 0000000000..b6662490d5 --- /dev/null +++ b/jdi-light-angular-tests/src/main/java/io/github/com/pages/FormFieldsPage.java @@ -0,0 +1,30 @@ +package io.github.com.pages; + +import com.epam.jdi.light.angular.elements.common.Checkbox; +import com.epam.jdi.light.angular.elements.complex.FormField; +import com.epam.jdi.light.angular.elements.complex.radiobuttons.RadioButton; +import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI; + +public class FormFieldsPage extends NewAngularPage { + + public static FormField formFieldSubscriptSizingFixed; + public static FormField formFieldSubscriptSizingDynamic; + public static FormField formFieldAppearanceInputLegacy; + public static FormField formFieldAppearanceInputStandard; + public static FormField simpleFormFieldInput; + public static FormField simpleFormFieldSelect; + public static FormField simpleFormFieldTextarea; + public static FormField formFieldWithLabelInputSimplePlaceholder; + public static FormField formFieldWithLabelInputSimplePlaceholderAndLabel; + public static FormField formFieldWithLabelSelect; + public static FormField formFieldExampleContainerInputLimited; + public static FormField formFieldExampleContainerDropdown; + public static FormField formFieldEmailInput; + public static FormField prefixSuffixFormFieldPassword; + public static FormField modifiedLayoutFormFieldColor; + public static FormField formFieldDisabled; + @UI("mat-checkbox[id*='mat-mdc-checkbox']") + public static Checkbox hideRequiredMarker; + @UI("mat-radio-button[value='always']") + public static RadioButton alwaysFloatLabel; +} diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/FormFieldsSection.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/FormFieldsSection.java deleted file mode 100644 index 2948b4e78f..0000000000 --- a/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/FormFieldsSection.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.github.com.pages.sections; - -import com.epam.jdi.light.angular.elements.complex.FormField; -import com.epam.jdi.light.elements.composite.Section; - -public class FormFieldsSection extends Section { - public static FormField simpleFormFieldInput; - public static FormField formFieldWithLabelInputSimplePlaceholder; - public static FormField formFieldAppearanceInputLegacy; - public static FormField formFieldExampleContainerInputLimited; - public static FormField formFieldEmailInput; - public static FormField prefixSuffixFormFieldPassword; - public static FormField modifiedLayoutFormFieldColor; -} diff --git a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/FormFieldTests.java b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/FormFieldTests.java index db7609f607..1891cccf94 100644 --- a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/FormFieldTests.java +++ b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/FormFieldTests.java @@ -2,132 +2,158 @@ import io.github.epam.TestsInit; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Ignore; import org.testng.annotations.Test; -import static io.github.com.StaticSite.angularPage; -import static io.github.com.pages.sections.FormFieldsSection.*; -import static io.github.epam.site.steps.States.shouldBeLoggedIn; +import java.util.List; + +import static com.jdiai.tools.Timer.waitCondition; +import static io.github.com.StaticSite.formFieldPage; +import static io.github.com.pages.FormFieldsPage.alwaysFloatLabel; +import static io.github.com.pages.FormFieldsPage.formFieldAppearanceInputLegacy; +import static io.github.com.pages.FormFieldsPage.formFieldAppearanceInputStandard; +import static io.github.com.pages.FormFieldsPage.formFieldDisabled; +import static io.github.com.pages.FormFieldsPage.formFieldEmailInput; +import static io.github.com.pages.FormFieldsPage.formFieldExampleContainerDropdown; +import static io.github.com.pages.FormFieldsPage.formFieldExampleContainerInputLimited; +import static io.github.com.pages.FormFieldsPage.formFieldSubscriptSizingDynamic; +import static io.github.com.pages.FormFieldsPage.formFieldSubscriptSizingFixed; +import static io.github.com.pages.FormFieldsPage.formFieldWithLabelInputSimplePlaceholder; +import static io.github.com.pages.FormFieldsPage.formFieldWithLabelInputSimplePlaceholderAndLabel; +import static io.github.com.pages.FormFieldsPage.formFieldWithLabelSelect; +import static io.github.com.pages.FormFieldsPage.hideRequiredMarker; +import static io.github.com.pages.FormFieldsPage.modifiedLayoutFormFieldColor; +import static io.github.com.pages.FormFieldsPage.prefixSuffixFormFieldPassword; +import static io.github.com.pages.FormFieldsPage.simpleFormFieldInput; +import static io.github.com.pages.FormFieldsPage.simpleFormFieldSelect; +import static io.github.com.pages.FormFieldsPage.simpleFormFieldTextarea; import static org.hamcrest.Matchers.containsString; -// TODO Move to the new page -@Ignore public class FormFieldTests extends TestsInit { @BeforeMethod(alwaysRun = true) public void before() { - shouldBeLoggedIn(); - angularPage.shouldBeOpened(); + formFieldPage.open(); + waitCondition((() -> formFieldPage.isOpened())); + formFieldPage.checkOpened(); } @Test public void simpleFormFieldTest() { simpleFormFieldInput.show(); - simpleFormFieldInput.has().inputLabel(1, "Input"); - simpleFormFieldInput.has().textAreaLabel(1, "Textarea"); - simpleFormFieldInput.has().dropdownLabel(1, "Select"); - simpleFormFieldInput.set(1, "Test input value"); - simpleFormFieldInput.has().value(1, "Test input value"); - simpleFormFieldInput.set(2, "Option"); - simpleFormFieldInput.has().value(2, "Option"); - simpleFormFieldInput.set(3, "Test text area value"); - simpleFormFieldInput.has().value(3, "Test text area value"); - simpleFormFieldInput.input(1, "Input value"); - simpleFormFieldInput.has().inputText(1, "Input value"); - simpleFormFieldInput.has().inputText(1, containsString("Input")); - simpleFormFieldInput.select(1, "Option"); - simpleFormFieldInput.has().dropdownText(1, "Option"); - simpleFormFieldInput.has().dropdownText(1, containsString("tion")); - simpleFormFieldInput.setTextArea(1, "Text area value"); - simpleFormFieldInput.has().textAreaText(1, "Text area value"); - simpleFormFieldInput.has().textAreaText(1, containsString(" area v")); - simpleFormFieldInput.clearTextArea(1); - simpleFormFieldInput.has().textAreaText(1, ""); - simpleFormFieldInput.set(3, "Another text area value"); - simpleFormFieldInput.has().value(3, "Another text area value"); - simpleFormFieldInput.clear(1); - simpleFormFieldInput.has().value(1, ""); - simpleFormFieldInput.clear(3); - simpleFormFieldInput.has().value(3, ""); + simpleFormFieldInput.has().label("Input"); + simpleFormFieldTextarea.has().label("Textarea"); + simpleFormFieldSelect.has().label("Select"); + simpleFormFieldInput.set("Test input value"); + simpleFormFieldInput.has().value("Test input value"); + simpleFormFieldInput.has().value(containsString("st inp")); + simpleFormFieldSelect.is().empty(); + simpleFormFieldSelect.set("Option"); + simpleFormFieldSelect.has().value("Option"); + simpleFormFieldSelect.has().value(containsString("Option")); + simpleFormFieldSelect.is().notEmpty(); + simpleFormFieldTextarea.set("Test text area value"); + simpleFormFieldTextarea.has().value("Test text area value"); + simpleFormFieldTextarea.has().value(containsString("area v")); + simpleFormFieldInput.clear(); + simpleFormFieldInput.has().value(""); + simpleFormFieldTextarea.clear(); + simpleFormFieldTextarea.has().value(""); } @Test public void formFieldWithLabelTest() { formFieldWithLabelInputSimplePlaceholder.show(); - formFieldWithLabelInputSimplePlaceholder. - has().inputPlaceholder(1, "Simple placeholder"); - formFieldWithLabelInputSimplePlaceholder. - has().inputPlaceholder(2, "Simple placeholder"); - formFieldWithLabelInputSimplePlaceholder. - has().placeholder(1, "Simple placeholder"); - formFieldWithLabelInputSimplePlaceholder. - has().placeholder(2, "Simple placeholder"); - formFieldWithLabelInputSimplePlaceholder. - has().label(2, "Both a label and a placeholder"); - formFieldWithLabelInputSimplePlaceholder. - has().label(3, "favorite Fancy label"); - formFieldWithLabelInputSimplePlaceholder.input(1, "First input value"); - formFieldWithLabelInputSimplePlaceholder. - has().value(1, containsString("t input v")); - formFieldWithLabelInputSimplePlaceholder.input(2, "Second input value"); - formFieldWithLabelInputSimplePlaceholder.select(1, "Option"); - formFieldWithLabelInputSimplePlaceholder. - has().value(2, "Second input value"); - formFieldWithLabelInputSimplePlaceholder. - has().value(3, "Option"); + formFieldWithLabelInputSimplePlaceholder.has().placeholder("Simple placeholder"); + formFieldWithLabelInputSimplePlaceholderAndLabel.has().placeholder("Simple placeholder"); + formFieldWithLabelInputSimplePlaceholderAndLabel.has().label("Both a label and a placeholder"); + formFieldWithLabelSelect.has().label("favorite Fancy label"); + formFieldWithLabelInputSimplePlaceholder.set("First input value"); + formFieldWithLabelInputSimplePlaceholder.has().value(containsString("t input v")); + formFieldWithLabelInputSimplePlaceholderAndLabel.set("Second input value"); + formFieldWithLabelInputSimplePlaceholderAndLabel.has().value("Second input value"); + formFieldWithLabelSelect.set("Option"); + formFieldWithLabelSelect.has().value("Option"); } @Test public void formFieldAppearanceVariantsTest() { formFieldAppearanceInputLegacy.show(); - formFieldAppearanceInputLegacy.input(1, "Input 1 value"); - formFieldAppearanceInputLegacy.has().value(1, "Input 1 value"); - formFieldAppearanceInputLegacy.has().fieldIcon(1, "sentiment_very_satisfied"); + formFieldAppearanceInputLegacy.doubleClick(); + formFieldAppearanceInputLegacy.set("Input 1 value"); + formFieldAppearanceInputLegacy.has().value( "Input 1 value"); + formFieldAppearanceInputLegacy.has().fieldIcon("sentiment_very_satisfied"); + formFieldAppearanceInputLegacy.is().filled(); + formFieldAppearanceInputStandard.is().outlined(); } @Test public void formFieldWithErrorMessageTest() { formFieldEmailInput.show(); - formFieldEmailInput.input(1, "test@"); + formFieldEmailInput.set("test@"); formFieldEmailInput.focusOut(); - formFieldEmailInput.has().inputError(1, "Not a valid email"); - formFieldEmailInput.clearInput(1); - formFieldEmailInput.has().inputError(1, "You must enter a value"); - formFieldEmailInput.has().error(1, "You must enter a value"); - formFieldEmailInput.set(1, "test@test.com"); - formFieldEmailInput.has().value(1, "test@test.com"); - formFieldEmailInput.clear(1); - formFieldEmailInput.has().inputError(1, "You must enter a value"); + formFieldEmailInput.has().error("Not a valid email"); + formFieldEmailInput.set(" "); + formFieldEmailInput.has().error("You must enter a value"); + formFieldEmailInput.set("test@test.com"); + formFieldEmailInput.has().value( "test@test.com"); + formFieldEmailInput.set(" "); + formFieldEmailInput.has().error("You must enter a value"); } @Test public void formFieldsWithHintsTest() { formFieldExampleContainerInputLimited.show(); - formFieldExampleContainerInputLimited.has().hint(1, "0/10"); - formFieldExampleContainerInputLimited.has().hint(2, "Here's the dropdown arrow ^"); - formFieldExampleContainerInputLimited.set(1, "12345678901"); - formFieldExampleContainerInputLimited.has().hint(1, "10/10"); - formFieldExampleContainerInputLimited.has().inputHint(1, "10/10"); - formFieldExampleContainerInputLimited.has().value(1, "1234567890"); + formFieldExampleContainerInputLimited.has().hints(List.of("Max 10 characters", "0/10")); + formFieldExampleContainerDropdown.has().hint("Here's the dropdown arrow ^"); + formFieldExampleContainerInputLimited.set("12345678901"); + formFieldExampleContainerInputLimited.has().hint("10/10"); + formFieldExampleContainerInputLimited.has().value( "1234567890"); } @Test public void formFieldsPrefixSuffixTest() { prefixSuffixFormFieldPassword.show(); - prefixSuffixFormFieldPassword.input(1, "Password"); - prefixSuffixFormFieldPassword.clickIcon(1); - prefixSuffixFormFieldPassword.has().value(1, "Password"); - prefixSuffixFormFieldPassword.set(1, "AnotherPassword"); - prefixSuffixFormFieldPassword.has().value(1, "AnotherPassword"); - prefixSuffixFormFieldPassword.clickIcon(1); - prefixSuffixFormFieldPassword.has().value(1, "AnotherPassword"); + prefixSuffixFormFieldPassword.set("Password"); + prefixSuffixFormFieldPassword.clickIcon(); + prefixSuffixFormFieldPassword.has().value( "Password"); + prefixSuffixFormFieldPassword.set("AnotherPassword"); + prefixSuffixFormFieldPassword.has().value( "AnotherPassword"); + prefixSuffixFormFieldPassword.clickIcon(); + prefixSuffixFormFieldPassword.has().value( "AnotherPassword"); } @Test public void formFieldsThemesTest() { modifiedLayoutFormFieldColor.show(); - modifiedLayoutFormFieldColor.set(1, "Accent"); - modifiedLayoutFormFieldColor.has().color(1, "rgba(0, 0, 0, 0.87)"); - modifiedLayoutFormFieldColor.set(2, "20"); - modifiedLayoutFormFieldColor.has().font(2, containsString("20px")); + modifiedLayoutFormFieldColor.set("Accent"); + modifiedLayoutFormFieldColor.has().color("rgba(0, 0, 0, 0.87)"); + } + + @Test + public void formFieldsRequiredTest() { + formFieldWithLabelSelect.show(); + formFieldWithLabelSelect.is().required(); + hideRequiredMarker.click(); + formFieldWithLabelSelect.is().notRequired(); + } + + @Test + public void formFieldsFloatLabelTest() { + formFieldWithLabelSelect.show(); + alwaysFloatLabel.click(); + formFieldWithLabelSelect.has().alwaysFloatLabel(); + } + + @Test + public void formFieldsDisabledTest() { + formFieldDisabled.show(); + formFieldDisabled.is().disabled(); + formFieldEmailInput.is().notDisabled(); + } + + @Test + public void formFieldsSubscriptSizingTest() { + formFieldSubscriptSizingFixed.show(); + formFieldSubscriptSizingFixed.has().notDynamicSubscriptSizing(); + formFieldSubscriptSizingDynamic.has().dynamicSubscriptSizing(); } } diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/FormFieldsAssert.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/FormFieldsAssert.java index e1f1b59479..1560b469d7 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/FormFieldsAssert.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/FormFieldsAssert.java @@ -7,144 +7,129 @@ import org.hamcrest.Matcher; import org.hamcrest.Matchers; +import java.util.List; + import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert; public class FormFieldsAssert extends UIAssert implements HasAssert { - @JDIAction(value = "Assert that '{name}' input with index {0} has value {1}", isAssert = true) - public FormFieldsAssert inputText(int index, String expected) { - jdiAssert(element().getInputValue(index), Matchers.is(expected)); - return this; - } - - @JDIAction(value = "Assert that '{name}' input with index {0} contains value {1}", isAssert = true) - public FormFieldsAssert inputText(int index, Matcher condition) { - jdiAssert(element().getInputValue(index), condition); - return this; - } - - @JDIAction(value = "Assert that {name} text area with index {0} has value {1}", isAssert = true) - public FormFieldsAssert textAreaText(int index, String expected) { - jdiAssert(element().getTextAreaValue(index), Matchers.is(expected)); - return this; - } - @JDIAction(value = "Assert that {name} text area with index {0} contains value {1}", isAssert = true) - public FormFieldsAssert textAreaText(int index, Matcher condition) { - jdiAssert(element().getTextAreaValue(index), condition); + @JDIAction(value = "Assert that {name} has label {0}", isAssert = true) + public FormFieldsAssert label(String expected) { + jdiAssert(element().label(), Matchers.is(expected)); return this; } - @JDIAction(value = "Assert that {name} dropdown with index {0} value is {1}", isAssert = true) - public FormFieldsAssert dropdownText(int index, String expected) { - jdiAssert(element().getDropdownValue(index), Matchers.is(expected)); + @JDIAction(value = "Assert that {name} has value {0}", isAssert = true) + public FormFieldsAssert value(String expected) { + jdiAssert(element().value(), Matchers.is(expected)); return this; } - @JDIAction(value = "Assert that {name} dropdown with index {0} value contains {1}", isAssert = true) - public FormFieldsAssert dropdownText(int index, Matcher condition) { - jdiAssert(element().getDropdownValue(index), condition); + @JDIAction(value = "Assert that {name} contains value {0}", isAssert = true) + public FormFieldsAssert value(Matcher condition) { + jdiAssert(element().value(), condition); return this; } - @JDIAction(value = "Assert that {name} input with index {0} has placeholder {1}", isAssert = true) - public FormFieldsAssert inputPlaceholder(int index, String expected) { - jdiAssert(element().inputPlaceholder(index), Matchers.is(expected)); + @JDIAction(value = "Assert that {name} has hint {0}", isAssert = true) + public FormFieldsAssert hint(String expected) { + jdiAssert(element().hints(), Matchers.containsInRelativeOrder(expected)); return this; } - @JDIAction(value = "Assert that {name} input with index {0} contains placeholder {1}", isAssert = true) - public FormFieldsAssert inputPlaceholder(int index, Matcher condition) { - jdiAssert(element().inputPlaceholder(index), condition); + @JDIAction(value = "Assert that {name} has all hints {0}", isAssert = true) + public FormFieldsAssert hints(List expected) { + jdiAssert(element().hints(), Matchers.is(expected)); return this; } - @JDIAction(value = "Assert that {name} input with index {0} has label {1}", isAssert = true) - public FormFieldsAssert inputLabel(int index, String expected) { - jdiAssert(element().inputLabel(index), Matchers.is(expected)); + @JDIAction(value = "Assert that {name} has icon {0}", isAssert = true) + public FormFieldsAssert fieldIcon(String expected) { + jdiAssert(element().icon(), Matchers.is(expected)); return this; } - @JDIAction(value = "Assert that {name} text area with index {0} has label {1}", isAssert = true) - public FormFieldsAssert textAreaLabel(int index, String expected) { - jdiAssert(element().textAreaLabel(index), Matchers.is(expected)); + @JDIAction(value = "Assert that {name} has color {0}", isAssert = true) + public FormFieldsAssert color(String expected) { + jdiAssert(element().color(), Matchers.is(expected)); return this; } - @JDIAction(value = "Assert that {name} dropdown with index {0} has label {1}", isAssert = true) - public FormFieldsAssert dropdownLabel(int index, String expected) { - jdiAssert(element().dropdownLabel(index), Matchers.is(expected)); + @JDIAction(value = "Assert that {name} has placeholder {0}", isAssert = true) + public FormFieldsAssert placeholder(String expected) { + jdiAssert(element().placeholder(), Matchers.is(expected)); return this; } - @JDIAction(value = "Assert that {name} input with index {0} has hint {1}", isAssert = true) - public FormFieldsAssert inputHint(int index, String expected) { - jdiAssert(element().inputHint(index), Matchers.is(expected)); + @JDIAction(value = "Assert that {name} has error {0}", isAssert = true) + public FormFieldsAssert error(String expected) { + jdiAssert(element().error(), Matchers.is(expected)); return this; } - @JDIAction(value = "Assert that {name} input with index {0} has error {1}", isAssert = true) - public FormFieldsAssert inputError(int index, String expected) { - jdiAssert(element().inputError(index), Matchers.is(expected)); + @JDIAction(value = "Assert that {name} is required", isAssert = true) + public FormFieldsAssert required() { + jdiAssert(element().isRequired(), Matchers.is(true), "Field is not required"); return this; } - @JDIAction(value = "Assert that {name} with index {0} has value {1}", isAssert = true) - public FormFieldsAssert value(int index, String expected) { - jdiAssert(element().value(index), Matchers.is(expected)); + @JDIAction(value = "Assert that {name} is not required", isAssert = true) + public FormFieldsAssert notRequired() { + jdiAssert(element().isRequired(), Matchers.is(false), "Field is required"); return this; } - @JDIAction(value = "Assert that {name} with index {0} contains value {1}", isAssert = true) - public FormFieldsAssert value(int index, Matcher condition) { - jdiAssert(element().value(index), condition); + @JDIAction(value = "Assert that {name} appearance attribute is fill", isAssert = true) + public FormFieldsAssert filled() { + jdiAssert(element().appearance(), Matchers.is("fill"), "Appearance is not filled"); return this; } - @JDIAction(value = "Assert that {name} with index {0} has hint {1}", isAssert = true) - public FormFieldsAssert hint(int index, String expected) { - jdiAssert(element().hint(index), Matchers.is(expected)); + @JDIAction(value = "Assert that {name} appearance attribute is outline", isAssert = true) + public FormFieldsAssert outlined() { + jdiAssert(element().appearance(), Matchers.is("outline"), "Appearance is not outlined"); return this; } - @JDIAction(value = "Assert that {name} with index {0} has icon {1}", isAssert = true) - public FormFieldsAssert fieldIcon(int index, String expected) { - jdiAssert(element().icon(index), Matchers.is(expected)); + @JDIAction(value = "Assert that {name} has always float label", isAssert = true) + public FormFieldsAssert alwaysFloatLabel() { + jdiAssert(element().hasAlwaysFloatLabel(), Matchers.is(true), "Float label is not always"); return this; } - @JDIAction(value = "Assert that {name} with index {0} has font {1}", isAssert = true) - public FormFieldsAssert font(int index, String expected) { - jdiAssert(element().font(index), Matchers.is(expected)); + @JDIAction(value = "Assert that {name} is required", isAssert = true) + public FormFieldsAssert disabled() { + jdiAssert(element().isDisabled(), Matchers.is(false), "Field is not disabled"); return this; } - @JDIAction(value = "Assert that {name} with index {0} font contains {1} property", isAssert = true) - public FormFieldsAssert font(int index, Matcher condition) { - jdiAssert(element().font(index), condition); + @JDIAction(value = "Assert that {name} is not required", isAssert = true) + public FormFieldsAssert notDisabled() { + jdiAssert(element().isEnabled(), Matchers.is(true), "Field is disabled"); return this; } - @JDIAction(value = "Assert that {name} with index {0} has color {1}", isAssert = true) - public FormFieldsAssert color(int index, String expected) { - jdiAssert(element().color(index), Matchers.is(expected)); + @JDIAction(value = "Assert that select field {name} is empty", isAssert = true) + public FormFieldsAssert empty() { + jdiAssert(element().isEmpty(), Matchers.is(true), "Select field is not empty"); return this; } - @JDIAction(value = "Assert that {name} with index {0} has placeholder {1}", isAssert = true) - public FormFieldsAssert placeholder(int index, String expected) { - jdiAssert(element().placeholder(index), Matchers.is(expected)); + @JDIAction(value = "Assert that select field {name} is not empty", isAssert = true) + public FormFieldsAssert notEmpty() { + jdiAssert(element().isEmpty(), Matchers.is(false), "Select field is empty"); return this; } - @JDIAction(value = "Assert that {name} with index {0} has label {1}", isAssert = true) - public FormFieldsAssert label(int index, String expected) { - jdiAssert(element().label(index), Matchers.is(expected)); + @JDIAction(value = "Assert that select field {name} has fixed SubscriptSizing", isAssert = true) + public FormFieldsAssert dynamicSubscriptSizing() { + jdiAssert(element().isDynamicSubscriptSizing(), Matchers.is(true), "Select field has fixed SubscriptSizing"); return this; } - @JDIAction(value = "Assert that {name} with index {0} has error {1}", isAssert = true) - public FormFieldsAssert error(int index, String expected) { - jdiAssert(element().error(index), Matchers.is(expected)); + @JDIAction(value = "Assert that select field {name} has dynamic SubscriptSizing", isAssert = true) + public FormFieldsAssert notDynamicSubscriptSizing() { + jdiAssert(element().isDynamicSubscriptSizing(), Matchers.is(false), "Select field has dynamic SubscriptSizing"); return this; } } diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/FormField.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/FormField.java index f2cb3836c5..bb463d76f2 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/FormField.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/FormField.java @@ -5,208 +5,67 @@ import com.epam.jdi.light.common.JDIAction; import com.epam.jdi.light.elements.base.UIBaseElement; import com.epam.jdi.light.elements.common.UIElement; -import com.epam.jdi.light.elements.complex.WebList; -import com.jdiai.tools.map.MapArray; import org.openqa.selenium.By; -import org.openqa.selenium.Keys; import org.openqa.selenium.WebElement; import java.util.List; +import java.util.stream.Collectors; import static com.epam.jdi.light.common.TextTypes.VALUE; -import static com.epam.jdi.light.driver.WebDriverFactory.getDriver; import static com.epam.jdi.light.settings.WebSettings.logger; +import static org.openqa.selenium.Keys.TAB; /** To see an example of FormField web element please visit https://material.angular.io/components/form-field/overview#form-field-appearance-variants **/ public class FormField extends UIBaseElement { - private String matFormFieldPrefix = "//mat-form-field[@"; - private String autocompleteAttrPrefix = "_ngcontent-"; - private String containerAttribute; - private String getContainerAttribute() { - final String[] curAttr = {""}; - MapArray attributesAndValues = this.core().getAllAttributes(); - List attributes = attributesAndValues.keys(); - attributes.forEach(attr -> { - boolean doesContain = attr.contains(autocompleteAttrPrefix); - if (doesContain) { - curAttr[0] = attr; - } - }); - return curAttr[0]; - } - - private UIElement getContainer() { - containerAttribute = getContainerAttribute(); - WebElement element = null; - try { - element = getDriver().findElement(By.xpath("//form[@" + containerAttribute + "]")); - } catch (Exception e) { - try { - element = getDriver().findElement(By.xpath("//div[@" + containerAttribute + "]")); - } catch (Exception exception) { - logger.error(exception.toString()); - } - } - return new UIElement(element); - } - - public WebList getInputs() { - return getContainer().finds(By.xpath(matFormFieldPrefix + containerAttribute + "]//input")); - } - - public WebList getDropdowns() { - return getContainer().finds(By.xpath(matFormFieldPrefix + containerAttribute + "]//mat-select")); - } - - public WebList getTextAreas() { - return getContainer().finds(By.xpath(matFormFieldPrefix + containerAttribute + "]//textarea")); - } - - @JDIAction("Input value {1} for input in '{name}' with index {0}") - public void input(int index, String value) { - getInputs().get(index).input(value); - } - - @JDIAction("Select value {1} for dropdown '{name}' with index {0}") - public void select(int index, String value) { - getDropdowns().get(index).click(); - MaterialSelectorContainer cdkOverlayContainer = new MaterialSelectorContainer(); - cdkOverlayContainer.select(value); - } - - @JDIAction("Input value {1} for text area in '{name}' with index {0}") - public void setTextArea(int index, String value) { - getTextAreas().get(index).input(value); - } - - @JDIAction("Get value for input with index {0} in '{name}'") - public String inputText(int index) { - return getInputs().get(index).text(VALUE); - } - - @JDIAction("Get value for input with index {0} in '{name}'") - public String getInputValue(int index) { - return inputText(index); - } - - @JDIAction("Get value for text area with index {0} in '{name}'") - public String textAreaText(int index) { - return getTextAreas().get(index).text(VALUE); - } - - @JDIAction("Get value for text area with index {0} in '{name}'") - public String getTextAreaValue(int index) { - return textAreaText(index); - } - - @JDIAction("Get value for dropdown with index {0} in '{name}'") - public String getDropdownValue(int index) { - return getDropdowns().get(index).getText(); - } - - @JDIAction("Get placeholder for input in '{name}' with index {0}") - public String inputPlaceholder(int index) { - String placeholder = "placeholder"; - return (getInputs().get(index).hasAttribute(placeholder)) ? getInputs().get(index).getAttribute(placeholder) : ""; - } - - @JDIAction("Get label for input in '{name}' with index {0}") - public String inputLabel(int index) { - UIElement label = getInputs(). - get(index).find(By.xpath("//ancestor::mat-form-field[@" + containerAttribute + "]//mat-label")); - return label.getText(); - } - - @JDIAction("Get label for text area in '{name}' with index {0}") - public String textAreaLabel(int index) { - UIElement label = getTextAreas() - .get(index).find(By.xpath("//ancestor::mat-form-field[@" + containerAttribute + "]//mat-label")); - return label.getText(); + @JDIAction("Get placeholder for input in '{name}'") + public String placeholder() { + return getActualElement().placeholder(); } - @JDIAction("Get label for dropdown in '{name}' with index {0}") - public String dropdownLabel(int index) { - UIElement label = getDropdowns() - .get(index).find(By.xpath("//ancestor::mat-form-field[@" + containerAttribute + "]//mat-label")); - return label.getText(); + @JDIAction("Get label for '{name}'") + public String label() { + return core().find(By.cssSelector("mat-label")).getText(); } - @JDIAction("Get hint for input in '{name}' with index {0}") - public String inputHint(int index) { - UIElement hint = getInputs(). - get(index).find(By.xpath("//ancestor::mat-form-field[@" + containerAttribute + "]//mat-hint")); + @JDIAction("Get hint for '{name}'") + public String hint() { + UIElement hint = core().find(By.cssSelector("mat-hint")); return hint.getText(); } - @JDIAction("Get hint for '{name}' with index {0}") - public String hint(int index) { - UIElement hint = getFormFields().get(index).find(By.cssSelector("mat-hint")); - return hint.getText(); - } - - @JDIAction("Get placeholder for '{name}' with index {0}") - public String placeholder(int index) { - String placeholder = "placeholder"; - String type = getType(index); - WebElement element = getFormFields().get(index).find(By.xpath("//" + type)); - UIElement actualElement = new UIElement(element); - return (actualElement.hasAttribute(placeholder)) ? actualElement.getAttribute(placeholder) : ""; - } - - @JDIAction("Get label for '{name}' with index {0}") - public String label(int index) { - UIElement label = getFormFields().get(index).find(By.xpath("//mat-label")); - return label.getText(); - } - - @JDIAction("Get error for input in '{name}' with index {0}") - public String inputError(int index) { - UIElement error = getInputs(). - get(index).find(By.xpath("//ancestor::mat-form-field[@" + containerAttribute + "]//mat-error")); - return error.getText(); + @JDIAction("Get all hints for '{name}'") + public List hints() { + List hints = core().finds(By.cssSelector("mat-hint")); + return hints.stream().map(UIElement::getText).collect(Collectors.toList()); } - @JDIAction("Get error for '{name}' with index {0}") - public String error(int index) { - UIElement error = getFormFields().get(index).find(By.xpath("//mat-error")); + @JDIAction("Get error for '{name}'") + public String error() { + UIElement error = core().find(By.cssSelector("mat-error")); return error.getText(); } @JDIAction("Get focus out from '{name}'") public void focusOut() { - getContainer().click(); + getActualElement().sendKeys(TAB); } - @JDIAction("Clear value from input in '{name}' with index {0}") - public void clearInput(int index) { - getInputs().get(index).sendKeys(Keys.chord(Keys.CONTROL, "a", Keys.DELETE)); - focusOut(); - } - - @JDIAction("Clear value from text area in '{name}' with index {0}") - public void clearTextArea(int index) { - getTextAreas().get(index).sendKeys(Keys.chord(Keys.CONTROL, "a", Keys.DELETE)); - focusOut(); - } - - private String getType(int index) { + private String getType() { String type = ""; - getContainer(); - String currentXpath = "(" + matFormFieldPrefix + containerAttribute + "])[" + index + "]"; try { - getDriver().findElement(By.xpath(currentXpath + "//input")); + core().find(By.cssSelector("input")).get(); type = "input"; } catch (Exception e1) { try { - getDriver().findElement(By.xpath(currentXpath + "//mat-select")); + core().find(By.cssSelector("mat-select")).get(); type = "mat-select"; } catch (Exception e2) { try { - getDriver().findElement(By.xpath(currentXpath + "//textarea")); + core().find(By.cssSelector("textarea")).get(); type = "textarea"; } catch (Exception e3) { logger.error(e3.toString()); @@ -216,15 +75,10 @@ private String getType(int index) { return type; } - private WebList getFormFields() { - return getContainer().finds(By.xpath(matFormFieldPrefix + containerAttribute + "]")); - } - - @JDIAction("Set value {1} for '{name}' with index {0}") - public void set(int index, String value) { - String type = getType(index); - WebElement element = getFormFields().get(index).find(By.xpath("//" + type)); - UIElement actualElement = new UIElement(element); + @JDIAction("Set value {0} for '{name}'") + public void set(String value) { + String type = getType(); + UIElement actualElement = getActualElement(); switch (type) { case "input": actualElement.input(value); @@ -242,12 +96,11 @@ public void set(int index, String value) { } } - @JDIAction("Get value for '{name}' with index {0}") - public String value(int index) { + @JDIAction("Get value for '{name}'") + public String value() { String value = ""; - String type = getType(index); - WebElement element = getFormFields().get(index).find(By.xpath("//" + type)); - UIElement actualElement = new UIElement(element); + String type = getType(); + UIElement actualElement = getActualElement(); switch (type) { case "input": value = actualElement.text(VALUE); @@ -264,44 +117,67 @@ public String value(int index) { return value; } - @JDIAction("Clear value from '{name}' with index {0}") - public void clear(int index) { - String type = getType(index); - WebElement element = getFormFields().get(index).find(By.xpath("//" + type)); - UIElement actualElement = new UIElement(element); - actualElement.sendKeys(Keys.CONTROL + "a"); - actualElement.sendKeys(Keys.DELETE); - focusOut(); + @JDIAction("Clear value from '{name}'") + public void clear() { + UIElement actualElement = getActualElement(); + actualElement.clear(); } - @JDIAction("Click icon in '{name}' with index {0}") - public void clickIcon(int index) { - WebElement element = getFormFields().get(index).find(By.xpath("//mat-icon")); + @JDIAction("Click icon in '{name}'") + public void clickIcon() { + WebElement element = core().find(By.xpath("//mat-icon/ancestor::button")); UIElement actualElement = new UIElement(element); actualElement.click(); } - @JDIAction("Get icon text in '{name}' with index {0}") - public String icon(int index) { - WebElement element = getFormFields().get(index).find(By.xpath("//mat-icon")); + @JDIAction("Get mat-icon text in '{name}'") + public String icon() { + WebElement element = core().find(By.cssSelector("mat-icon")); UIElement actualElement = new UIElement(element); return actualElement.getText(); } - @JDIAction("Get font attributes in '{name}' with index {0}") - public String font(int index) { - String type = getType(index); - WebElement element = getFormFields().get(index).find(By.xpath("//" + type)); - UIElement actualElement = new UIElement(element); - return actualElement.getCssValue("font"); + @JDIAction("Get color attribute in '{name}'") + public String color() { + UIElement actualElement = getActualElement(); + return actualElement.getCssValue("color"); } - @JDIAction("Get color attribute in '{name}' with index {0}") - public String color(int index) { - String type = getType(index); - WebElement element = getFormFields().get(index).find(By.xpath("//" + type)); - UIElement actualElement = new UIElement(element); - return actualElement.getCssValue("color"); + @JDIAction("Get appearance attribute in '{name}'") + public String appearance() { + return core().attr("appearance"); + } + + @JDIAction("Check if '{name}' is required") + public boolean isRequired() { + return core().find(By.cssSelector("span")).attr("class").contains("mat-mdc-form-field-required-marker"); + } + + private UIElement getActualElement() { + String type = getType(); + WebElement element = core().find(By.xpath("//" + type)); + return new UIElement(element); + } + + @JDIAction("Check if '{name}' has always float label") + public boolean hasAlwaysFloatLabel() { + return core().attr("class").contains("mat-mdc-form-field-label-always-float"); + } + + @Override + @JDIAction("Check if '{name}' is enabled") + public boolean isEnabled() { + return !core().find(By.cssSelector("[class*='mat-form-field-disabled']")).isExist(); + } + + @JDIAction("Check if select field '{name}' is empty") + public boolean isEmpty() { + return getActualElement().attr("class").contains("mat-mdc-select-empty"); + } + + @JDIAction("Check if select field '{name}' has dynamic subscriptSizing") + public boolean isDynamicSubscriptSizing() { + return !core().finds("//div[contains(@class,'mat-mdc-form-field-subscript-dynamic-size')]").getWebElements().isEmpty(); } @Override diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/interfaces/IFormField.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/interfaces/IFormField.java new file mode 100644 index 0000000000..980f5abcc5 --- /dev/null +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/interfaces/IFormField.java @@ -0,0 +1,64 @@ +package com.epam.jdi.light.angular.elements.interfaces; + +import com.epam.jdi.light.common.JDIAction; +import com.epam.jdi.light.elements.base.UIBaseElement; +import com.epam.jdi.light.elements.common.Label; +import com.epam.jdi.light.elements.common.UIElement; +import com.epam.jdi.light.elements.interfaces.base.ICoreElement; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; +import java.util.stream.Collectors; + +public interface IFormField extends ICoreElement { + + String placeholder(); + Label label(); + String value(); + String color(); + boolean isEmpty(); + + @JDIAction("Get hint for '{name}'") + default String hint() { + return core().find(By.cssSelector("mat-hint")).getValue(); + } + + @JDIAction("Get all hints for '{name}'") + default List hints() { + List hints = core().finds(By.cssSelector("mat-hint")); + return hints.stream().map(UIElement::getText).collect(Collectors.toList()); + } + + @JDIAction("Get error for '{name}'") + default String error() { + return core().find(By.cssSelector("mat-error")).getText(); + } + + @JDIAction("Get icon with '{name}'") + default UIElement icon() { + WebElement element = core().find(By.xpath("//mat-icon/ancestor::button")); + return new UIElement(element); + } + + @JDIAction("Check if '{name}' is required") + default boolean isRequired() { + return core().find(By.cssSelector("span.mat-mdc-form-field-required-marker")).isExist(); + } + + @JDIAction("Check if '{name}' has always float label") + default boolean hasAlwaysFloatLabel() { + return core().attr("class").contains("mat-mdc-form-field-label-always-float"); + } + + @Override + @JDIAction("Check if '{name}' is enabled") + default boolean isEnabled() { + return core().attr("class").contains("mat-form-field-disabled"); + } + + @JDIAction("Check if select field '{name}' has dynamic subscriptSizing") + default boolean isDynamicSubscriptSizing() { + return core().find("//div[contains(@class,'mat-mdc-form-field-subscript-dynamic-size')]").isExist(); + } +}