From 79a73c865d3506adc4399fae7045899b1e825073 Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Thu, 1 Feb 2024 21:09:38 +0100 Subject: [PATCH 01/14] 4908 updated formField --- .../main/java/io/github/com/StaticSite.java | 4 + .../io/github/com/pages/FormFieldsPage.java | 30 ++ .../com/pages/sections/FormFieldsSection.java | 14 - .../elements/complex/FormFieldTests.java | 197 ++++++------ .../angular/asserts/FormFieldsAssert.java | 139 ++++----- .../angular/elements/complex/FormField.java | 284 +++++------------- 6 files changed, 289 insertions(+), 379 deletions(-) create mode 100644 jdi-light-angular-tests/src/main/java/io/github/com/pages/FormFieldsPage.java delete mode 100644 jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/FormFieldsSection.java 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..5ffb7ba292 --- /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-mdc-checkbox-1") + public static Checkbox hideRequiredMarker; + @UI("#mat-radio-3") + 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..903989a508 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,161 @@ 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, ""); + simpleFormFieldTextarea.show(); + simpleFormFieldSelect.show(); + 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"); + formFieldWithLabelInputSimplePlaceholderAndLabel.show(); + formFieldWithLabelSelect.show(); + 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.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.check(); + 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..2e8105b107 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(true), "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().isDisabled(), Matchers.is(false), "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..77214670ac 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 disabled") + public boolean isDisabled() { + return core().attr("class").contains("mat-form-field-disabled"); + } + + @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 From a27de6ff2ce4c6a3477d2fc0690310b7e0bba4ad Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Sun, 18 Feb 2024 11:32:42 +0100 Subject: [PATCH 02/14] 4908 fix tests --- .../epam/angular/tests/elements/complex/FormFieldTests.java | 1 + 1 file changed, 1 insertion(+) 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 903989a508..8bf8324a12 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 @@ -142,6 +142,7 @@ public void formFieldsRequiredTest() { @Test public void formFieldsFloatLabelTest() { formFieldWithLabelSelect.show(); + alwaysFloatLabel.show(); alwaysFloatLabel.click(); formFieldWithLabelSelect.has().alwaysFloatLabel(); } From cbb3d524ce50980985033e6b33f37506df372219 Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Sun, 18 Feb 2024 11:41:55 +0100 Subject: [PATCH 03/14] 4908 fix tests --- .../epam/angular/tests/elements/complex/FormFieldTests.java | 1 + 1 file changed, 1 insertion(+) 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 8bf8324a12..af7fae554a 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 @@ -82,6 +82,7 @@ public void formFieldWithLabelTest() { public void formFieldAppearanceVariantsTest() { formFieldAppearanceInputLegacy.show(); formFieldAppearanceInputLegacy.set("Input 1 value"); + formFieldAppearanceInputLegacy.focusOut(); formFieldAppearanceInputLegacy.has().value( "Input 1 value"); formFieldAppearanceInputLegacy.has().fieldIcon("sentiment_very_satisfied"); formFieldAppearanceInputLegacy.is().filled(); From fab77c926db93c1cc1d0c317b23c60ee59c88c41 Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Sun, 18 Feb 2024 12:01:13 +0100 Subject: [PATCH 04/14] 4908 fix tests --- .../src/main/java/io/github/com/pages/FormFieldsPage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 5ffb7ba292..865159517b 100644 --- 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 @@ -25,6 +25,6 @@ public class FormFieldsPage extends NewAngularPage { public static FormField formFieldDisabled; @UI("#mat-mdc-checkbox-1") public static Checkbox hideRequiredMarker; - @UI("#mat-radio-3") + @UI("mat-radio-button[value='always']") public static RadioButton alwaysFloatLabel; } From 2b7d4db7bfea55641674f7332a616fdb38ed9c7a Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Sun, 18 Feb 2024 12:10:07 +0100 Subject: [PATCH 05/14] 4908 fix tests --- .../src/main/java/io/github/com/pages/FormFieldsPage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 865159517b..503ca51f2c 100644 --- 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 @@ -23,7 +23,7 @@ public class FormFieldsPage extends NewAngularPage { public static FormField prefixSuffixFormFieldPassword; public static FormField modifiedLayoutFormFieldColor; public static FormField formFieldDisabled; - @UI("#mat-mdc-checkbox-1") + @UI("mat-checkbox[id='mat-mdc-checkbox-1']") public static Checkbox hideRequiredMarker; @UI("mat-radio-button[value='always']") public static RadioButton alwaysFloatLabel; From a2a755791ed036df6e161af9610e0edf2146ca44 Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Sun, 18 Feb 2024 12:20:32 +0100 Subject: [PATCH 06/14] 4908 fix tests --- .../src/main/java/io/github/com/pages/FormFieldsPage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 503ca51f2c..082e2197a8 100644 --- 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 @@ -23,7 +23,7 @@ public class FormFieldsPage extends NewAngularPage { public static FormField prefixSuffixFormFieldPassword; public static FormField modifiedLayoutFormFieldColor; public static FormField formFieldDisabled; - @UI("mat-checkbox[id='mat-mdc-checkbox-1']") + @UI("//*[@id='mat-mdc-checkbox-1']") public static Checkbox hideRequiredMarker; @UI("mat-radio-button[value='always']") public static RadioButton alwaysFloatLabel; From ae44149e6da7230b6d4b061753c36540b5d48132 Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Sun, 18 Feb 2024 12:35:38 +0100 Subject: [PATCH 07/14] 4908 fix tests --- .../tests/elements/complex/FormFieldTests.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 af7fae554a..da493bc938 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 @@ -132,13 +132,13 @@ public void formFieldsThemesTest() { modifiedLayoutFormFieldColor.has().color("rgba(0, 0, 0, 0.87)"); } - @Test - public void formFieldsRequiredTest() { - formFieldWithLabelSelect.show(); - formFieldWithLabelSelect.is().required(); - hideRequiredMarker.check(); - formFieldWithLabelSelect.is().notRequired(); - } +// @Test +// public void formFieldsRequiredTest() { +// formFieldWithLabelSelect.show(); +// formFieldWithLabelSelect.is().required(); +// hideRequiredMarker.check(); +// formFieldWithLabelSelect.is().notRequired(); +// } @Test public void formFieldsFloatLabelTest() { From e2ab67bd49ca873d135de9a567c0419dec457a2e Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Sun, 18 Feb 2024 13:02:23 +0100 Subject: [PATCH 08/14] 4908 debug --- .../epam/jdi/light/angular/elements/complex/FormField.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 77214670ac..d772af01ac 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 @@ -57,16 +57,18 @@ public void focusOut() { private String getType() { String type = ""; try { - core().find(By.cssSelector("input")).get(); + WebElement el = core().find(By.cssSelector("input")).get(); type = "input"; + logger.debug("Type is input " + el); } catch (Exception e1) { try { core().find(By.cssSelector("mat-select")).get(); type = "mat-select"; } catch (Exception e2) { try { - core().find(By.cssSelector("textarea")).get(); + WebElement el = core().find(By.cssSelector("textarea")).get(); type = "textarea"; + logger.debug("Type is textarea " + el); } catch (Exception e3) { logger.error(e3.toString()); } From aa4de6c366625e862df2f39ef3680c6da8f30250 Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Sun, 18 Feb 2024 13:13:29 +0100 Subject: [PATCH 09/14] 4908 fixes --- .../src/main/java/io/github/com/pages/FormFieldsPage.java | 2 +- .../epam/angular/tests/elements/complex/FormFieldTests.java | 3 ++- .../epam/jdi/light/angular/elements/complex/FormField.java | 6 ++---- 3 files changed, 5 insertions(+), 6 deletions(-) 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 index 082e2197a8..865159517b 100644 --- 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 @@ -23,7 +23,7 @@ public class FormFieldsPage extends NewAngularPage { public static FormField prefixSuffixFormFieldPassword; public static FormField modifiedLayoutFormFieldColor; public static FormField formFieldDisabled; - @UI("//*[@id='mat-mdc-checkbox-1']") + @UI("#mat-mdc-checkbox-1") public static Checkbox hideRequiredMarker; @UI("mat-radio-button[value='always']") public static RadioButton alwaysFloatLabel; 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 da493bc938..3b44bdb7f8 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 @@ -81,8 +81,9 @@ public void formFieldWithLabelTest() { @Test public void formFieldAppearanceVariantsTest() { formFieldAppearanceInputLegacy.show(); - formFieldAppearanceInputLegacy.set("Input 1 value"); + formFieldAppearanceInputLegacy.doubleClick(); formFieldAppearanceInputLegacy.focusOut(); + formFieldAppearanceInputLegacy.set("Input 1 value"); formFieldAppearanceInputLegacy.has().value( "Input 1 value"); formFieldAppearanceInputLegacy.has().fieldIcon("sentiment_very_satisfied"); formFieldAppearanceInputLegacy.is().filled(); 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 d772af01ac..77214670ac 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 @@ -57,18 +57,16 @@ public void focusOut() { private String getType() { String type = ""; try { - WebElement el = core().find(By.cssSelector("input")).get(); + core().find(By.cssSelector("input")).get(); type = "input"; - logger.debug("Type is input " + el); } catch (Exception e1) { try { core().find(By.cssSelector("mat-select")).get(); type = "mat-select"; } catch (Exception e2) { try { - WebElement el = core().find(By.cssSelector("textarea")).get(); + core().find(By.cssSelector("textarea")).get(); type = "textarea"; - logger.debug("Type is textarea " + el); } catch (Exception e3) { logger.error(e3.toString()); } From ffe5785f68bd7e30d75dbb054126a3eb62c9af85 Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Sun, 18 Feb 2024 13:23:17 +0100 Subject: [PATCH 10/14] 4908 fixes --- .../tests/elements/complex/FormFieldTests.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 3b44bdb7f8..52d7aa2ba3 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 @@ -82,7 +82,6 @@ public void formFieldWithLabelTest() { public void formFieldAppearanceVariantsTest() { formFieldAppearanceInputLegacy.show(); formFieldAppearanceInputLegacy.doubleClick(); - formFieldAppearanceInputLegacy.focusOut(); formFieldAppearanceInputLegacy.set("Input 1 value"); formFieldAppearanceInputLegacy.has().value( "Input 1 value"); formFieldAppearanceInputLegacy.has().fieldIcon("sentiment_very_satisfied"); @@ -133,13 +132,14 @@ public void formFieldsThemesTest() { modifiedLayoutFormFieldColor.has().color("rgba(0, 0, 0, 0.87)"); } -// @Test -// public void formFieldsRequiredTest() { -// formFieldWithLabelSelect.show(); -// formFieldWithLabelSelect.is().required(); -// hideRequiredMarker.check(); -// formFieldWithLabelSelect.is().notRequired(); -// } + @Test + public void formFieldsRequiredTest() { + formFieldWithLabelSelect.show(); + hideRequiredMarker.show(); + formFieldWithLabelSelect.is().required(); + hideRequiredMarker.click(); + formFieldWithLabelSelect.is().notRequired(); + } @Test public void formFieldsFloatLabelTest() { From c92a02a18adbe75c4fe6682637c16b7fccfbceda Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Mon, 19 Feb 2024 18:46:11 +0100 Subject: [PATCH 11/14] 4908 fixes --- .../src/main/java/io/github/com/pages/FormFieldsPage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 865159517b..b6662490d5 100644 --- 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 @@ -23,7 +23,7 @@ public class FormFieldsPage extends NewAngularPage { public static FormField prefixSuffixFormFieldPassword; public static FormField modifiedLayoutFormFieldColor; public static FormField formFieldDisabled; - @UI("#mat-mdc-checkbox-1") + @UI("mat-checkbox[id*='mat-mdc-checkbox']") public static Checkbox hideRequiredMarker; @UI("mat-radio-button[value='always']") public static RadioButton alwaysFloatLabel; From 10fd2d1c4b42774f77f14187652c7d8448763504 Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Mon, 26 Feb 2024 13:28:19 +0100 Subject: [PATCH 12/14] 4908 added interface --- .../elements/interfaces/IFormField.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/interfaces/IFormField.java 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..8e174510c5 --- /dev/null +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/interfaces/IFormField.java @@ -0,0 +1,77 @@ +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("Click icon in '{name}'") + default void clickIcon() { + WebElement element = core().find(By.xpath("//mat-icon/ancestor::button")); + UIElement actualElement = new UIElement(element); + actualElement.click(); + } + + @JDIAction("Get mat-icon text in '{name}'") + default String icon() { + WebElement element = core().find(By.cssSelector("mat-icon")); + UIElement actualElement = new UIElement(element); + return actualElement.getText(); + } + + @JDIAction("Get appearance attribute in '{name}'") + default String appearance() { + return core().attr("appearance"); + } + + @JDIAction("Check if '{name}' is required") + default boolean isRequired() { + return core().find(By.cssSelector("span")).attr("class").contains("mat-mdc-form-field-required-marker"); + } + + @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 disabled") + default boolean isDisabled() { + return core().attr("class").contains("mat-form-field-disabled"); + } + + @JDIAction("Check if select field '{name}' has dynamic subscriptSizing") + default boolean isDynamicSubscriptSizing() { + return !core().finds("//div[contains(@class,'mat-mdc-form-field-subscript-dynamic-size')]").getWebElements().isEmpty(); + } +} From 64851fbaaa97a4df6a2ddbf56e0704cff733829b Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Wed, 17 Apr 2024 16:52:26 +0200 Subject: [PATCH 13/14] 4908 fix comments --- .../elements/complex/FormFieldTests.java | 6 ----- .../elements/interfaces/IFormField.java | 27 +++++-------------- 2 files changed, 7 insertions(+), 26 deletions(-) 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 52d7aa2ba3..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 @@ -39,8 +39,6 @@ public void before() { @Test public void simpleFormFieldTest() { simpleFormFieldInput.show(); - simpleFormFieldTextarea.show(); - simpleFormFieldSelect.show(); simpleFormFieldInput.has().label("Input"); simpleFormFieldTextarea.has().label("Textarea"); simpleFormFieldSelect.has().label("Select"); @@ -64,8 +62,6 @@ public void simpleFormFieldTest() { @Test public void formFieldWithLabelTest() { formFieldWithLabelInputSimplePlaceholder.show(); - formFieldWithLabelInputSimplePlaceholderAndLabel.show(); - formFieldWithLabelSelect.show(); formFieldWithLabelInputSimplePlaceholder.has().placeholder("Simple placeholder"); formFieldWithLabelInputSimplePlaceholderAndLabel.has().placeholder("Simple placeholder"); formFieldWithLabelInputSimplePlaceholderAndLabel.has().label("Both a label and a placeholder"); @@ -135,7 +131,6 @@ public void formFieldsThemesTest() { @Test public void formFieldsRequiredTest() { formFieldWithLabelSelect.show(); - hideRequiredMarker.show(); formFieldWithLabelSelect.is().required(); hideRequiredMarker.click(); formFieldWithLabelSelect.is().notRequired(); @@ -144,7 +139,6 @@ public void formFieldsRequiredTest() { @Test public void formFieldsFloatLabelTest() { formFieldWithLabelSelect.show(); - alwaysFloatLabel.show(); alwaysFloatLabel.click(); formFieldWithLabelSelect.has().alwaysFloatLabel(); } 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 index 8e174510c5..980f5abcc5 100644 --- 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 @@ -35,28 +35,15 @@ default String error() { return core().find(By.cssSelector("mat-error")).getText(); } - @JDIAction("Click icon in '{name}'") - default void clickIcon() { + @JDIAction("Get icon with '{name}'") + default UIElement icon() { WebElement element = core().find(By.xpath("//mat-icon/ancestor::button")); - UIElement actualElement = new UIElement(element); - actualElement.click(); - } - - @JDIAction("Get mat-icon text in '{name}'") - default String icon() { - WebElement element = core().find(By.cssSelector("mat-icon")); - UIElement actualElement = new UIElement(element); - return actualElement.getText(); - } - - @JDIAction("Get appearance attribute in '{name}'") - default String appearance() { - return core().attr("appearance"); + return new UIElement(element); } @JDIAction("Check if '{name}' is required") default boolean isRequired() { - return core().find(By.cssSelector("span")).attr("class").contains("mat-mdc-form-field-required-marker"); + return core().find(By.cssSelector("span.mat-mdc-form-field-required-marker")).isExist(); } @JDIAction("Check if '{name}' has always float label") @@ -65,13 +52,13 @@ default boolean hasAlwaysFloatLabel() { } @Override - @JDIAction("Check if '{name}' is disabled") - default boolean isDisabled() { + @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().finds("//div[contains(@class,'mat-mdc-form-field-subscript-dynamic-size')]").getWebElements().isEmpty(); + return core().find("//div[contains(@class,'mat-mdc-form-field-subscript-dynamic-size')]").isExist(); } } From 693e54e0517fcab96d60e8ba22569aa66c020c62 Mon Sep 17 00:00:00 2001 From: Kira Vlasova Date: Wed, 17 Apr 2024 18:12:50 +0200 Subject: [PATCH 14/14] 4908 fix comments --- .../epam/jdi/light/angular/asserts/FormFieldsAssert.java | 4 ++-- .../epam/jdi/light/angular/elements/complex/FormField.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) 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 2e8105b107..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 @@ -99,13 +99,13 @@ public FormFieldsAssert alwaysFloatLabel() { @JDIAction(value = "Assert that {name} is required", isAssert = true) public FormFieldsAssert disabled() { - jdiAssert(element().isDisabled(), Matchers.is(true), "Field is not disabled"); + jdiAssert(element().isDisabled(), Matchers.is(false), "Field is not disabled"); return this; } @JDIAction(value = "Assert that {name} is not required", isAssert = true) public FormFieldsAssert notDisabled() { - jdiAssert(element().isDisabled(), Matchers.is(false), "Field is disabled"); + jdiAssert(element().isEnabled(), Matchers.is(true), "Field is disabled"); 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 77214670ac..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 @@ -165,9 +165,9 @@ public boolean hasAlwaysFloatLabel() { } @Override - @JDIAction("Check if '{name}' is disabled") - public boolean isDisabled() { - return core().attr("class").contains("mat-form-field-disabled"); + @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")