Skip to content

Commit

Permalink
add unit tests and refactor page object + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
b14ckster committed Aug 31, 2023
1 parent 259fcb3 commit 23ca9a5
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.epam.jdi.light.angular.elements.common.Input;
import com.epam.jdi.light.elements.composite.Form;
import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI;
import com.epam.jdi.light.ui.html.elements.common.TextField;
import io.github.com.entities.User;

public class InputsForm extends Form<User> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,61 @@
import com.epam.jdi.light.ui.html.elements.common.Button;
import com.epam.jdi.light.ui.html.elements.common.Icon;
import com.epam.jdi.light.ui.html.elements.common.Text;
import com.epam.jdi.light.ui.html.elements.common.TextArea;
import io.github.com.entities.InputsForm;

public class InputPage extends NewAngularPage {

@UI("#inputs_basic_food")
public static Input foodBasicInput;
public static Input inputBasicFood;

@UI("#inputs_basic_comment")
public static Input leaveACommentBasicInput;
public static Input inputBasicLeaveAComment;

@UI("#inputs_errorStateMatcher_email")
public static Input emailErrorStateMatcherInput;
public static Input inputEmailErrorStateMatcher;

@UI("#inputs_errorStateMatcher_message")
public static Text errorStateMatcherMessage;
public static Text messageErrorStateMatcher;

@UI("#inputs_autosize_textarea")
public static Input autoSizeTextArea;
public static Input inputAutoSize;

@UI("#inputs_clearable_textbox")
public static Input inputWithClearButton;

@UI("#inputs_clearable_button")
public static Button clearButton;
public static Button buttonClear;

@UI("#inputs_error_email")
public static Input inputErrorMail;

@UI("#inputs_error_message")
public static Text errorMessage;
public static Text messageError;

@UI("input-form-example form")
public static InputsForm inputsForm;

@UI("#inputs_hints_message")
public static Input messageHintInput;
public static Input inputWithMessageHint;

@UI("#inputs_hints_text")
public static Text hintMassage;
public static Text messageHint;

@UI("#inputs_hints_counter")
public static Text counterHintMassage;
public static Text massageHintCounter;

@UI("#inputs_prefixes")
public static Text inputPrefix;
public static Text prefixForInput;

@UI("#inputs_suffixes")
public static Icon inputSuffix;
public static Icon suffixForInput;

@UI("#inputs_prefixes_suffixes_phone")
public static Input telephoneInput;
public static Input inputTelephone;

@UI("#mat-input-16")
public static Input ariaLabelInput;
public static Input inputWithAriaLabel;

@UI("#input-readonly-option")
public static Input readonlyInput;
public static Input inputWithReadonly;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,24 @@
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.*;
import static io.github.com.pages.InputPage.inputWithAriaLabel;
import static io.github.com.pages.InputPage.inputAutoSize;
import static io.github.com.pages.InputPage.buttonClear;
import static io.github.com.pages.InputPage.massageHintCounter;
import static io.github.com.pages.InputPage.inputEmailErrorStateMatcher;
import static io.github.com.pages.InputPage.messageError;
import static io.github.com.pages.InputPage.messageErrorStateMatcher;
import static io.github.com.pages.InputPage.inputBasicFood;
import static io.github.com.pages.InputPage.messageHint;
import static io.github.com.pages.InputPage.inputErrorMail;
import static io.github.com.pages.InputPage.prefixForInput;
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.inputWithMessageHint;
import static io.github.com.pages.InputPage.inputWithReadonly;
import static io.github.com.pages.InputPage.inputTelephone;

public class InputTests extends TestsInit {

Expand All @@ -20,126 +37,141 @@ public void before() {
inputPage.checkOpened();
}

@Test(description = "")
public void basicInputTest() {
foodBasicInput.isDisplayed();
foodBasicInput.show();
foodBasicInput.isVisible();
foodBasicInput.has().placeholder("Ex. Pizza")
@Test(description = "Test checks basic inputs attributes")
public void inputBasicTest() {
inputBasicFood.isDisplayed();
inputBasicFood.show();
inputBasicFood.isVisible();
inputBasicFood.has().placeholder("Ex. Pizza")
.and().value("Sushi");
foodBasicInput.clearAndSetText("Lasagna")
.has().typedText("Lasagna");
foodBasicInput.clearAndSetText("Ice Cream")
.has().typedText("Ice");

leaveACommentBasicInput.isDisplayed();
leaveACommentBasicInput.show();
leaveACommentBasicInput.isVisible();
leaveACommentBasicInput.has().placeholder("Ex. It makes me feel...");
leaveACommentBasicInput.clearAndSetText("Delicious")
.has().typedText("Delicious");
}
inputBasicFood.input("Lasagna");
inputBasicFood.has().value("Lasagna");
inputBasicFood.input("Ice Cream");
inputBasicFood.has().value("Ice");

@Test(description = "")
public void inputWithACustomErrorStateMatcherTest() {
emailErrorStateMatcherInput.isDisplayed();
emailErrorStateMatcherInput.show();
emailErrorStateMatcherInput.isVisible();
emailErrorStateMatcherInput.has().placeholder("Ex. pat@example.com");
emailErrorStateMatcherInput.clearAndSetText("test");
errorStateMatcherMessage.is().text("Please enter a valid email address");
inputBasicLeaveAComment.has().placeholder("Ex. It makes me feel...");
inputBasicLeaveAComment.input("Delicious");
inputBasicLeaveAComment.has().value("Delicious");
}

@Test(description = "")
public void clearableInputTest() {
@Test(description = "Test checks input with a clear button attributes")
public void inputCleanableTest() {
inputWithClearButton.isDisabled();
inputWithClearButton.show();
inputWithClearButton.isVisible();
inputWithClearButton.has().inputType(TEXT);
inputWithClearButton.clearAndSetText("test");
inputWithClearButton.has().typedText("test");
clearButton.isDisplayed();
clearButton.click();
inputWithClearButton.is().typedText("");
inputWithClearButton.input("test");
inputWithClearButton.has().value("test");

buttonClear.isDisplayed();
buttonClear.click();
inputWithClearButton.is().value("");
}

@Test(description = "Test checks input with readonly attributes")
public void inputReadonlyTest() {
inputWithReadonly.isDisplayed();
inputWithReadonly.show();
inputWithReadonly.isVisible();
inputWithReadonly.has().inputType(TEXT)
.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();
inputEmailErrorStateMatcher.show();
inputEmailErrorStateMatcher.isVisible();
inputEmailErrorStateMatcher.has().placeholder("Ex. pat@example.com");
inputEmailErrorStateMatcher.input("test");

messageErrorStateMatcher.isDisplayed();
messageErrorStateMatcher.is().text("Please enter a valid email address");
}

@Test(description = "")
@Test(description = "Test checks input with error messages attributes")
public void inputWithErrorMessagesTest() {
inputErrorMail.isDisplayed();
inputErrorMail.show();
inputErrorMail.isVisible();
inputErrorMail.has().placeholder("Ex. pat@example.com");
inputErrorMail.clearAndSetText("test");
inputErrorMail.input("test");
inputErrorMail.pressButton(Keys.ENTER);
errorMessage.isDisplayed();
errorMessage.is().text("Please enter a valid email address");
}

@Test
public void inputWithTextAutoResizingTest() {
autoSizeTextArea.isDisplayed();
autoSizeTextArea.show();
autoSizeTextArea.isVisible();
autoSizeTextArea.has().autoSize();
autoSizeTextArea.clearAndSetText("line1")
.pressButton(Keys.ENTER)
.sendKeys("line2");
autoSizeTextArea.is().typedText("line1\nline2");
autoSizeTextArea.clear();
autoSizeTextArea.is().typedText("");
}

@Test
public void inputsInAFormTest() {
inputsForm.fill(DEFAULT_USER);
inputsForm.firstName.is().typedText(DEFAULT_USER.firstName);
inputsForm.lastName.is().typedText(DEFAULT_USER.lastName);
inputsForm.address.is().typedText(DEFAULT_USER.address);
inputsForm.address2.is().typedText(DEFAULT_USER.address2);
inputsForm.city.is().typedText(DEFAULT_USER.city);
inputsForm.state.is().typedText(DEFAULT_USER.state);
inputsForm.postalCode.is().typedText(DEFAULT_USER.postalCode);
messageError.isDisplayed();
messageError.is().text("Please enter a valid email address");
}

@Test(description = "")
@Test(description = "Test checks inputs with hints attributes")
public void inputWithHintsTest() {
messageHintInput.isDisplayed();
messageHintInput.show();
messageHintInput.isVisible();
messageHintInput.has().placeholder("Ex. I need help with...");
messageHintInput.clearAndSetText("test");
hintMassage.isDisplayed();
hintMassage.is().text("Don't disclose personal info");
counterHintMassage.isDisplayed();
counterHintMassage.is().text("4 / 256");
inputWithMessageHint.isDisplayed();
inputWithMessageHint.show();
inputWithMessageHint.isVisible();
inputWithMessageHint.has().placeholder("Ex. I need help with...");
inputWithMessageHint.input("test");

messageHint.isDisplayed();
messageHint.is().text("Don't disclose personal info");

massageHintCounter.isDisplayed();
massageHintCounter.is().text("4 / 256");
}

@Test(description = "")
@Test(description = "Test checks inputs with prefixes and suffixes attributes")
public void inputWithPrefixesAndSuffixesTest() {
inputPrefix.isDisplayed();
inputSuffix.isDisplayed();
telephoneInput.isDisplayed();
telephoneInput.has().placeholder("555-555-1234");
telephoneInput.clearAndSetText("0123456789");
telephoneInput.clear();
telephoneInput.is().typedText("");
prefixForInput.isDisplayed();
prefixForInput.has().text("+1 ");
suffixForInput.isDisplayed();

inputTelephone.isDisplayed();
inputTelephone.has().placeholder("555-555-1234");
inputTelephone.input("0123456789");
inputTelephone.is().value("0123456789");
inputTelephone.clear();
inputTelephone.is().value("");
}

@Test(description = "")
public void inputWithAriaLabelTest() {
ariaLabelInput.isDisplayed();
ariaLabelInput.show();
ariaLabelInput.isVisible();
ariaLabelInput.has().inputType(TEXT);
ariaLabelInput.has().label("Clear");
@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("");
}

@Test(description = "")
public void readonlyInputTest() {
readonlyInput.isDisplayed();
readonlyInput.show();
readonlyInput.isVisible();
readonlyInput.has().inputType(TEXT)
.and().readonly();
@Test(description = "Test checks inputs in a form attributes")
public void inputsInAFormTest() {
inputsForm.isDisplayed();
inputsForm.show();
inputsForm.isVisible();
inputsForm.postalCode.is().value("94043");

inputsForm.fill(DEFAULT_USER);
inputsForm.firstName.is().value(DEFAULT_USER.firstName);
inputsForm.lastName.is().value(DEFAULT_USER.lastName);
inputsForm.address.is().value(DEFAULT_USER.address)
.and().placeholder("Ex. 100 Main St");
inputsForm.address2.is().value(DEFAULT_USER.address2);
inputsForm.city.is().value(DEFAULT_USER.city)
.and().placeholder("Ex. San Francisco");
inputsForm.state.is().value(DEFAULT_USER.state)
.and().placeholder("Ex. California");
inputsForm.postalCode.is().value(DEFAULT_USER.postalCode)
.and().placeholder("Ex. 94105");
}
}
Loading

0 comments on commit 23ca9a5

Please sign in to comment.