Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
b14ckster committed Sep 26, 2023
1 parent cd53b9f commit 0e32445
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 172 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,10 +14,10 @@ public class InputsForm extends Form<User> {
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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")
Expand All @@ -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();
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<TextAreaAssert, TextArea> {

@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;
}
}
Original file line number Diff line number Diff line change
@@ -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<InputAssert> 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);
Expand All @@ -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);
Expand All @@ -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
Expand Down
Loading

0 comments on commit 0e32445

Please sign in to comment.