Skip to content

Commit

Permalink
Merge pull request #5462 from jdi-testing/5320
Browse files Browse the repository at this point in the history
#5320 Fix TextField
  • Loading branch information
pnatashap authored Apr 13, 2024
2 parents 3c3bdb1 + c48e7f2 commit dc65a3a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ public void before() {
public void counterTextFieldTest() {
String defText = "Preliminary report";
TextField regularCounterField = counterTextField.get(1);
regularCounterField.has().labelText("Regular");
regularCounterField.has().label("Regular");
regularCounterField.setText(defText);
regularCounterField.has().counter(18, 25);
regularCounterField.has().counter("18 / 25");
regularCounterField.click();
regularCounterField.has().messageText("This field uses counter prop");
TextField customCountPropField = counterTextField.get(3);
customCountPropField.has().labelText("Custom counter from prop");
customCountPropField.has().label("Custom counter from prop");
customCountPropField.has().text(defText);
customCountPropField.has().counter(2, 5);
customCountPropField.has().counter("2 / 5");
customCountPropField.click();
customCountPropField.messages().get(1).has().text("This field counts words instead of characters");
TextField customCountSlotField = counterTextField.get(4);
customCountSlotField.label().is().text("Custom counter from slot");
customCountSlotField.has().text(defText);
customCountSlotField.has().counter(2, 5);
customCountSlotField.has().counter("2 / 5");
customCountSlotField.click();
customCountSlotField.has().messageText("This field counts words instead of characters");

TextField limitExcField = counterTextField.get(2);
limitExcField.is().labelText("Limit exceeded");
limitExcField.has().counter(50, 25);
limitExcField.is().label("Limit exceeded");
limitExcField.has().counter("50 / 25");
limitExcField.click();
limitExcField.has().messageText("This field uses maxlength attribute");
customCountSlotField.click();
Expand All @@ -88,8 +88,8 @@ public void counterTextFieldTest() {
regularCounterField.has().text("");
customCountPropField.has().text("");
customCountSlotField.has().text("");
regularCounterField.has().counter(0, 25);
customCountSlotField.has().counter(1, 5);
regularCounterField.has().counter("0 / 25");
customCountSlotField.has().counter("1 / 5");

}

Expand Down Expand Up @@ -259,12 +259,13 @@ public void hintTextFieldTest() {
@Test (description = "Test checks validation fields : rules (func), validate-on-blur (y/n)")
public void validationTextFieldTest() {
String maxLengthString = "abcdeabcdeabcdeabcde";
String format = String.format("%d / 20", maxLengthString.length());
validationTextField.get(1).setText(maxLengthString);
validationTextField.get(1).is().text(maxLengthString);
validationTextField.get(1).is().counter(maxLengthString.length(), 20);
validationTextField.get(1).is().counter(format);
validationTextField.get(1).setText(maxLengthString + "abcd");
validationTextField.get(1).is().text(maxLengthString);
validationTextField.get(1).is().counter(maxLengthString.length(), 20);
validationTextField.get(1).is().counter(format);

validationTextField.get(2).setText("email");
validationTextField.get(2).has().errorMessage("Invalid e-mail.");
Expand Down Expand Up @@ -313,7 +314,7 @@ public void iconSlotsTextFieldTest() {

// @todo #5048 Fix the test to not use the locator and check the content of an element
@Test (description = "Test checks text field label and it's text")
public void labelTextFieldTest() {
public void labelFieldTest() {
labelTextField.has().label();
labelTextField.label().has().text("What about icon here?");
labelTextField.label().find("./i").isDisplayed();
Expand Down Expand Up @@ -368,7 +369,7 @@ public void loadingTextField() {
TextField loadedTextField = darkTextField.get(1);
loadingTextField1.show();
loadingTextField1.is().loading();
loadingTextField1.has().loaderHeightPx(2);
loadingTextField1.loader().has().height(2);
loadedTextField.show();
loadedTextField.is().loaded();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public TextFieldAssert notFocused() {

@JDIAction(value = "Assert that '{name}' text type is '{0}'", isAssert = true)
public TextFieldAssert textType(String textType) {
String actualTextType = element().getTextType();
jdiAssert(element().getTextType(), Matchers.equalTo(textType));
return this;
}
Expand All @@ -92,19 +91,14 @@ public TextFieldAssert placeholder(String placeholder) {
return this;
}

// @todo #5048 Change the implementation to check real counter content without any manipulation
@JDIAction(value = "Assert that '{name}' current counter is '{0}' and max counter is '{1}'", isAssert = true)
public TextFieldAssert counter(int currentCounter, int maxCounter) {
String[] counter = element().counter().text().replaceAll("\\s", "").split("/");
jdiAssert(Integer.parseInt(counter[0]), Matchers.equalTo(currentCounter), String.format("Actual current counter " +
"'%s' is not equal to expected '%s'", counter[0], currentCounter));
jdiAssert(Integer.parseInt(counter[1]), Matchers.equalTo(maxCounter), String.format("Actual max counter '%s' is " +
"not equal to expected '%s'", counter[1], maxCounter));
public TextFieldAssert counter(String counter) {
jdiAssert(element().counter().text(), Matchers.equalTo(counter));
return this;
}

@JDIAction(value = "Assert that '{name}' has label {0}", isAssert = true)
public TextFieldAssert labelText(String label) {
public TextFieldAssert label(String label) {
jdiAssert(element().labelText(), Matchers.is(label));
return this;
}
Expand Down Expand Up @@ -154,10 +148,4 @@ public TextFieldAssert notAutofocus() {
jdiAssert(element().isAutofocus(), Matchers.is(false), "TextField is autofocus");
return this;
}

@JDIAction(value = "Assert that '{name}' has loader height {0}", isAssert = true)
public TextFieldAssert loaderHeightPx(int height) {
jdiAssert(element().getLoaderHeight(), Matchers.equalTo(height));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public List<UIElement> messages() {
return details().finds(messageLocator);
}

// @todo #5320 Check this method, not clear why should we have external locator
@Override
@JDIAction("Get '{name}' messages text by locator '{0}'")
public List<String> messagesText(String locator) {
Expand Down Expand Up @@ -312,11 +313,6 @@ public ProgressLinear loader() {
return new ProgressLinear().setCore(ProgressLinear.class, core().find(loaderLocator));
}

@JDIAction("Get '{name}' loader height")
public int getLoaderHeight() {
return Integer.parseInt(core().find(loaderLocator).css("height").replace("px", ""));
}

@Override
public TextFieldAssert is() {
return new TextFieldAssert().set(this);
Expand Down

0 comments on commit dc65a3a

Please sign in to comment.