diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/entities/InputsForm.java b/jdi-light-angular-tests/src/main/java/io/github/com/entities/InputsForm.java index 2139020b19d..7e04ec796d0 100644 --- a/jdi-light-angular-tests/src/main/java/io/github/com/entities/InputsForm.java +++ b/jdi-light-angular-tests/src/main/java/io/github/com/entities/InputsForm.java @@ -1,6 +1,7 @@ package io.github.com.entities; import com.epam.jdi.light.angular.elements.common.Input; +import com.epam.jdi.light.angular.elements.common.TextArea; import com.epam.jdi.light.elements.composite.Form; import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI; @@ -13,10 +14,10 @@ public class InputsForm extends Form { public Input lastName; @UI("#inputs_form_address") - public Input address; + public TextArea address; @UI("#inputs_form_address2") - public Input address2; + public TextArea address2; @UI("#inputs_form_city") public Input city; diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/InputPage.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/InputPage.java index e60fa6cedcf..cee8f886fb3 100644 --- a/jdi-light-angular-tests/src/main/java/io/github/com/pages/InputPage.java +++ b/jdi-light-angular-tests/src/main/java/io/github/com/pages/InputPage.java @@ -1,6 +1,7 @@ package io.github.com.pages; import com.epam.jdi.light.angular.elements.common.Input; +import com.epam.jdi.light.angular.elements.common.TextArea; import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI; import com.epam.jdi.light.ui.html.elements.common.Button; import com.epam.jdi.light.ui.html.elements.common.Icon; @@ -13,7 +14,7 @@ public class InputPage extends NewAngularPage { public static Input inputBasicFood; @UI("#inputs_basic_comment") - public static Input inputBasicLeaveAComment; + public static TextArea textAreaBasicLeaveAComment; @UI("#inputs_errorStateMatcher_email") public static Input inputEmailErrorStateMatcher; @@ -22,7 +23,7 @@ public class InputPage extends NewAngularPage { public static Text messageErrorStateMatcher; @UI("#inputs_autosize_textarea") - public static Input inputAutoSize; + public static TextArea textAreaAutoSize; @UI("#inputs_clearable_textbox") public static Input inputWithClearButton; @@ -46,7 +47,7 @@ public class InputPage extends NewAngularPage { public static Text messageHint; @UI("#inputs_hints_counter") - public static Text massageHintCounter; + public static Text messageHintCounter; @UI("#inputs_prefixes") public static Text prefixForInput; @@ -57,9 +58,6 @@ public class InputPage extends NewAngularPage { @UI("#inputs_prefixes_suffixes_phone") public static Input inputTelephone; - @UI("#mat-input-16") - public static Input inputWithAriaLabel; - @UI("#input-readonly-option") public static Input inputWithReadonly; } diff --git a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/common/InputTests.java b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/common/InputTests.java index 83f73cd82c3..378f23b827c 100644 --- a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/common/InputTests.java +++ b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/common/InputTests.java @@ -9,10 +9,9 @@ import static com.jdiai.tools.Timer.waitCondition; import static io.github.com.StaticSite.inputPage; import static io.github.com.entities.Users.DEFAULT_USER; -import static io.github.com.pages.InputPage.inputWithAriaLabel; -import static io.github.com.pages.InputPage.inputAutoSize; +import static io.github.com.pages.InputPage.textAreaAutoSize; import static io.github.com.pages.InputPage.buttonClear; -import static io.github.com.pages.InputPage.massageHintCounter; +import static io.github.com.pages.InputPage.messageHintCounter; import static io.github.com.pages.InputPage.inputEmailErrorStateMatcher; import static io.github.com.pages.InputPage.messageError; import static io.github.com.pages.InputPage.messageErrorStateMatcher; @@ -23,7 +22,7 @@ import static io.github.com.pages.InputPage.suffixForInput; import static io.github.com.pages.InputPage.inputWithClearButton; import static io.github.com.pages.InputPage.inputsForm; -import static io.github.com.pages.InputPage.inputBasicLeaveAComment; +import static io.github.com.pages.InputPage.textAreaBasicLeaveAComment; import static io.github.com.pages.InputPage.inputWithMessageHint; import static io.github.com.pages.InputPage.inputWithReadonly; import static io.github.com.pages.InputPage.inputTelephone; @@ -44,14 +43,14 @@ public void inputBasicTest() { inputBasicFood.isVisible(); inputBasicFood.has().placeholder("Ex. Pizza") .and().value("Sushi"); - inputBasicFood.input("Lasagna"); - inputBasicFood.has().value("Lasagna"); + inputBasicFood.focus(); + inputBasicFood.has().hasFocus(); inputBasicFood.input("Ice Cream"); inputBasicFood.has().value("Ice"); - inputBasicLeaveAComment.has().placeholder("Ex. It makes me feel..."); - inputBasicLeaveAComment.input("Delicious"); - inputBasicLeaveAComment.has().value("Delicious"); + textAreaBasicLeaveAComment.has().placeholder("Ex. It makes me feel..."); + textAreaBasicLeaveAComment.input("Delicious"); + textAreaBasicLeaveAComment.has().value("Delicious"); } @Test(description = "Test checks input with a clear button attributes") @@ -77,15 +76,6 @@ public void inputReadonlyTest() { .and().readonly(); } - @Test(description = "Test checks input with aria-label attributes") - public void inputWithAriaLabelTest() { - inputWithAriaLabel.isDisplayed(); - inputWithAriaLabel.show(); - inputWithAriaLabel.isVisible(); - inputWithAriaLabel.has().inputType(TEXT); - inputWithAriaLabel.has().label("Clear"); - } - @Test(description = "Test checks inputs with a custom ErrorStateMatcher attributes") public void inputWithCustomErrorStateMatcherTest() { inputEmailErrorStateMatcher.isDisplayed(); @@ -122,8 +112,8 @@ public void inputWithHintsTest() { messageHint.isDisplayed(); messageHint.is().text("Don't disclose personal info"); - massageHintCounter.isDisplayed(); - massageHintCounter.is().text("4 / 256"); + messageHintCounter.isDisplayed(); + messageHintCounter.is().text("4 / 256"); } @Test(description = "Test checks inputs with prefixes and suffixes attributes") @@ -142,16 +132,16 @@ public void inputWithPrefixesAndSuffixesTest() { @Test(description = "Test checks input with auto-resizing textarea attributes") public void inputWithTextAutoResizingTest() { - inputAutoSize.isDisplayed(); - inputAutoSize.show(); - inputAutoSize.isVisible(); - inputAutoSize.has().autoSize(); - inputAutoSize.input("line1"); - inputAutoSize.pressButton(Keys.ENTER) - .sendKeys("line2"); - inputAutoSize.is().value("line1\nline2"); - inputAutoSize.clear(); - inputAutoSize.is().value(""); + textAreaAutoSize.isDisplayed(); + textAreaAutoSize.show(); + textAreaAutoSize.isVisible(); + textAreaAutoSize.has().autoSize(); + textAreaAutoSize.input("line1"); + textAreaAutoSize.pressButton(Keys.ENTER) + .sendKeys("line2"); + textAreaAutoSize.is().value("line1\nline2"); + textAreaAutoSize.clear(); + textAreaAutoSize.is().value(""); } @Test(description = "Test checks inputs in a form attributes") diff --git a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/unit/InputsUnitTests.java b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/unit/InputsUnitTests.java deleted file mode 100644 index a70e7d1f2c3..00000000000 --- a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/unit/InputsUnitTests.java +++ /dev/null @@ -1,112 +0,0 @@ -package io.github.epam.angular.tests.unit; - -import static com.jdiai.tools.Timer.waitCondition; -import static io.github.com.StaticSite.inputPage; -import static io.github.com.entities.Users.DEFAULT_USER; -import static io.github.com.pages.InputPage.inputAutoSize; -import static io.github.com.pages.InputPage.inputBasicFood; -import static io.github.com.pages.InputPage.inputBasicLeaveAComment; -import static io.github.com.pages.InputPage.inputEmailErrorStateMatcher; -import static io.github.com.pages.InputPage.inputErrorMail; -import static io.github.com.pages.InputPage.inputTelephone; -import static io.github.com.pages.InputPage.inputWithAriaLabel; -import static io.github.com.pages.InputPage.inputWithClearButton; -import static io.github.com.pages.InputPage.inputWithMessageHint; -import static io.github.com.pages.InputPage.inputWithReadonly; -import static io.github.com.pages.InputPage.inputsForm; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import io.github.epam.TestsInit; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -public class InputsUnitTests extends TestsInit { - - @BeforeMethod - public void before() { - inputPage.open(); - waitCondition(() -> inputPage.isOpened()); - inputPage.checkOpened(); - } - - @Test - public void isDisplayed() { - assertTrue(inputBasicFood.isDisplayed()); - assertTrue(inputBasicLeaveAComment.isDisplayed()); - assertTrue(inputEmailErrorStateMatcher.isDisplayed()); - assertTrue(inputAutoSize.isDisplayed()); - assertTrue(inputWithClearButton.isDisplayed()); - assertTrue(inputErrorMail.isDisplayed()); - assertTrue(inputsForm.isDisplayed()); - assertTrue(inputWithMessageHint.isDisplayed()); - assertTrue(inputTelephone.isDisplayed()); - assertTrue(inputWithAriaLabel.isDisplayed()); - assertTrue(inputWithReadonly.isDisplayed()); - } - - @Test - public void isVisible() { - inputBasicFood.show(); - assertTrue(inputBasicFood.isVisible()); - assertTrue(inputBasicLeaveAComment.isVisible()); - - inputEmailErrorStateMatcher.show(); - assertTrue(inputEmailErrorStateMatcher.isVisible()); - - inputAutoSize.show(); - assertTrue(inputAutoSize.isVisible()); - - inputWithClearButton.show(); - assertTrue(inputWithClearButton.isVisible()); - - inputErrorMail.show(); - assertTrue(inputErrorMail.isVisible()); - - inputsForm.show(); - assertTrue(inputsForm.isVisible()); - - inputWithMessageHint.show(); - assertTrue(inputWithMessageHint.isVisible()); - - inputTelephone.show(); - assertTrue(inputTelephone.isVisible()); - - inputWithAriaLabel.show(); - assertTrue(inputWithAriaLabel.isVisible()); - - inputWithReadonly.show(); - assertTrue(inputWithReadonly.isVisible()); - } - - @Test - public void hasTypedText() { - inputBasicFood.input("test"); - assertEquals(inputBasicFood.getValue(), "test"); - inputBasicLeaveAComment.input("test"); - assertEquals(inputBasicLeaveAComment.getValue(), "test"); - inputEmailErrorStateMatcher.input("test"); - assertEquals(inputEmailErrorStateMatcher.getValue(), "test"); - inputAutoSize.input("test"); - assertEquals(inputAutoSize.getValue(), "test"); - inputWithClearButton.input("test"); - assertEquals(inputWithClearButton.getValue(), "test"); - inputErrorMail.input("test"); - assertEquals(inputErrorMail.getValue(), "test"); - inputWithMessageHint.input("test"); - assertEquals(inputWithMessageHint.getValue(), "test"); - inputTelephone.input("test"); - assertEquals(inputTelephone.getValue(), "test"); - inputWithAriaLabel.input("test"); - assertEquals(inputWithAriaLabel.getValue(), "test"); - - inputsForm.fill(DEFAULT_USER); - assertEquals(inputsForm.firstName.getValue(), DEFAULT_USER.firstName); - assertEquals(inputsForm.lastName.getValue(), DEFAULT_USER.lastName); - assertEquals(inputsForm.address.getValue(), DEFAULT_USER.address); - assertEquals(inputsForm.address2.getValue(), DEFAULT_USER.address2); - assertEquals(inputsForm.city.getValue(), DEFAULT_USER.city); - assertEquals(inputsForm.state.getValue(), DEFAULT_USER.state); - assertEquals(inputsForm.postalCode.getValue(), DEFAULT_USER.postalCode); - } -} diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/InputAssert.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/InputAssert.java index a7a58c92a1f..c887969760e 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/InputAssert.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/InputAssert.java @@ -34,15 +34,9 @@ public InputAssert placeholder(String placeholder) { return this; } - @JDIAction("Assert that '{name}' has aria-label '{0}'") - public InputAssert label(String labelText) { - jdiAssert(element().labelText(), Matchers.containsString(labelText)); - return this; - } - - @JDIAction("Assert that '{name}' has attribute auto-size") - public InputAssert autoSize() { - jdiAssert(element().hasAutoSize(), Matchers.is(true)); + @JDIAction + public InputAssert hasFocus() { + jdiAssert(element().hasFocus(), Matchers.is(true)); return this; } } diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/TextAreaAssert.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/TextAreaAssert.java new file mode 100644 index 00000000000..0e898b28f82 --- /dev/null +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/TextAreaAssert.java @@ -0,0 +1,35 @@ +package com.epam.jdi.light.angular.asserts; + +import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert; + +import com.epam.jdi.light.angular.elements.common.TextArea; +import com.epam.jdi.light.asserts.generic.UIAssert; +import com.epam.jdi.light.common.JDIAction; +import org.hamcrest.Matchers; + +public class TextAreaAssert extends UIAssert { + + @JDIAction("Assert that '{name}' has attribute auto-size") + public TextAreaAssert autoSize() { + jdiAssert(element().autoSize(), Matchers.is(true)); + return this; + } + + @JDIAction("Assert that '{name}' has typed text '{0}' in input field") + public TextAreaAssert value(String text) { + jdiAssert(element().getValue(), Matchers.containsString(text)); + return this; + } + + @JDIAction("Assert that '{name}' has placeholder '{0}'") + public TextAreaAssert placeholder(String placeholder) { + jdiAssert(element().placeholder(), Matchers.containsString(placeholder)); + return this; + } + + @JDIAction + public TextAreaAssert changeableHeight() { + jdiAssert(element().changeableHeight(), Matchers.is(true)); + return this; + } +} diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/Input.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/Input.java index cddeb5921bb..6c38365ddfc 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/Input.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/Input.java @@ -1,16 +1,26 @@ package com.epam.jdi.light.angular.elements.common; import com.epam.jdi.light.angular.asserts.InputAssert; +import com.epam.jdi.light.angular.elements.complex.FormField; import com.epam.jdi.light.angular.elements.enums.InputsTypes; 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.epam.jdi.light.elements.interfaces.base.HasLabel; import com.epam.jdi.light.elements.interfaces.base.SetValue; import com.epam.jdi.light.elements.interfaces.common.IsInput; +import com.jdiai.tools.map.MapArray; +import java.util.List; +import java.util.Map; +import org.openqa.selenium.By; import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; public class Input extends UIBaseElement implements IsInput, SetValue, HasLabel { + private String focusClass = "mdc-line-ripple--active"; + @JDIAction("Press button '{0}' in '{name}'") public Input pressButton(Keys key) { core().sendKeys(key); @@ -27,11 +37,6 @@ public InputsTypes inputType() { return InputsTypes.fromType(core().getAttribute("type")); } - @JDIAction(value = "Get if '{name}' has auto-size attribute") - public boolean hasAutoSize() { - return attrs().has("cdktextareaautosize"); - } - @JDIAction("Set text '{name}' as ‘{0}’") public void setValue(String value) { input(value); @@ -42,9 +47,14 @@ public String getValue() { return core().getAttribute("value"); } - @Override - public String labelText() { - return core().getAttribute("aria-label"); + @JDIAction() + public void focus() { + core().click(); + } + + @JDIAction() + public boolean hasFocus() { + return true; } @Override diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/TextArea.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/TextArea.java new file mode 100644 index 00000000000..0a46be043ef --- /dev/null +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/TextArea.java @@ -0,0 +1,63 @@ +package com.epam.jdi.light.angular.elements.common; + +import static com.epam.jdi.light.ui.html.HtmlUtils.getInt; + +import com.epam.jdi.light.angular.asserts.TextAreaAssert; +import com.epam.jdi.light.common.JDIAction; +import com.epam.jdi.light.elements.base.UIBaseElement; +import com.epam.jdi.light.elements.interfaces.base.SetValue; +import com.epam.jdi.light.elements.interfaces.common.IsInput; +import org.openqa.selenium.Keys; + +public class TextArea extends UIBaseElement implements SetValue, IsInput { + + @JDIAction() + public int rows() { + return getInt(core().attr("rows")); + } + + @JDIAction() + public int minRows() { + return getInt(core().attr("cdkautosizeminrows")); + } + + @JDIAction() + public int maxRows() { + return getInt(core().attr("cdkautosizemaxrows")); + } + + @JDIAction(value = "Get if '{name}' has auto-size attribute") + public boolean autoSize() { + return attrs().has("cdktextareaautosize"); + } + + @JDIAction("Press button '{0}' in '{name}'") + public TextArea pressButton(Keys key) { + core().sendKeys(key); + return this; + } + + @Override + public String getValue() { + return core().getAttribute("value"); + } + + @Override + public void setValue(String value) { + input(value); + } + + public boolean changeableHeight() { + return hasAttribute("style"); + } + + @JDIAction() + public void changeHeight(int px) { + setAttribute("style", "height: " + px +"px"); + } + + @Override + public TextAreaAssert is() { + return new TextAreaAssert().set(this); + } +} diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/enums/InputsTypes.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/enums/InputsTypes.java index 10982e64c53..5327f9909b9 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/enums/InputsTypes.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/enums/InputsTypes.java @@ -15,24 +15,26 @@ public enum InputsTypes { TEXT("text"), TIME("time"), URL("url"), - WEEK("week"), - UNDEFINED("undefined");; + WEEK("week"); private final String type; InputsTypes(String label) { this.type = label; } + public String getType() { return type; } + public static int size() { return values().length; } + public static InputsTypes fromType(String type) { return Arrays.stream(values()) - .filter(t -> t.type.equalsIgnoreCase(type)) - .findFirst() - .orElse(UNDEFINED); + .filter(t -> t.type.equalsIgnoreCase(type)) + .findFirst() + .orElse(TEXT); } }