Skip to content

Commit

Permalink
Merge pull request #3 from donatas-b/manager-feature
Browse files Browse the repository at this point in the history
Manager feature implementation
  • Loading branch information
donatas-b authored Feb 28, 2024
2 parents cf32951 + ecef76f commit e37bd80
Show file tree
Hide file tree
Showing 16 changed files with 428 additions and 49 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ replay_pid*

.idea
target
allure-results
allure-results
build
27 changes: 27 additions & 0 deletions src/main/java/xyz/selenide/model/Currency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package xyz.selenide.model;

import lombok.Getter;

public enum Currency {
DOLLAR("Dollar"),
PUND("Pound"),
RUPEE("Rupee");

@Getter
private final String currency;

Currency(String currency) {
this.currency = currency;
}

public static Currency byValue(String currencyValue) {
for (Currency currency : Currency.values()) {
if (currency.currency.equals(currencyValue)) {
return currency;
}
}
throw new IllegalArgumentException(
String.format("Currency enum does not contains value '%s'", currencyValue));
}

}
10 changes: 5 additions & 5 deletions src/main/java/xyz/selenide/model/CustomerInformation.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public class CustomerInformation {
private List<String> accountNumbers;

public CustomerInformation(String tableRow) {
List<String> cells = Arrays.asList(tableRow.split("\n"));
this.firstName = cells.get(1).trim();
this.lastName = cells.get(2).trim();
this.postCode = cells.get(3).trim();
String accounts = cells.get(4).trim();
List<String> cells = Arrays.asList(tableRow.split("\t"));
this.firstName = cells.get(0).trim();
this.lastName = cells.get(1).trim();
this.postCode = cells.get(2).trim();
String accounts = cells.get(3).trim();
if (isEmpty(accounts)) {
this.accountNumbers = null;
} else {
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/xyz/selenide/model/CustomerSortColumn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package xyz.selenide.model;

public enum CustomerSortColumn {
FIRST_NAME("First Name"),
LAST_NAME("Last Name"),
POST_CODE("Post Code");

private final String column;

CustomerSortColumn(String columnName) {
this.column = columnName;
}

public static CustomerSortColumn byValue(String columnName) {
for (CustomerSortColumn column : CustomerSortColumn.values()) {
if (column.column.equals(columnName)) {
return column;
}
}
throw new IllegalArgumentException(
String.format("CustomerSortColumn enum does not contains value '%s'", columnName));
}

}
32 changes: 32 additions & 0 deletions src/main/java/xyz/selenide/model/Customers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package xyz.selenide.model;

import com.codeborne.selenide.ElementsCollection;

import java.util.ArrayList;
import java.util.Comparator;

public class Customers extends ArrayList<CustomerInformation> {

public Customers(ElementsCollection rows) {
rows.texts().subList(1, rows.size()).forEach(row -> this.add(new CustomerInformation(row)));
}

public void sort(CustomerSortColumn column, SortOrder sortOrder) {
switch (sortOrder) {
case ASC -> {
switch (column) {
case FIRST_NAME -> this.sort(Comparator.comparing(CustomerInformation::getFirstName));
case LAST_NAME -> this.sort(Comparator.comparing(CustomerInformation::getLastName));
case POST_CODE -> this.sort(Comparator.comparing(CustomerInformation::getPostCode));
}
}
case DESC -> {
switch (column) {
case FIRST_NAME -> this.sort(Comparator.comparing(CustomerInformation::getFirstName).reversed());
case LAST_NAME -> this.sort(Comparator.comparing(CustomerInformation::getLastName).reversed());
case POST_CODE -> this.sort(Comparator.comparing(CustomerInformation::getPostCode).reversed());
}
}
}
}
}
23 changes: 23 additions & 0 deletions src/main/java/xyz/selenide/model/SortOrder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package xyz.selenide.model;

public enum SortOrder {
ASC("Ascending"),
DESC("Descending");

private final String order;

SortOrder(String order) {
this.order = order;
}

public static SortOrder byValue(String orderValue) {
for (SortOrder order : SortOrder.values()) {
if (order.order.equals(orderValue)) {
return order;
}
}
throw new IllegalArgumentException(
String.format("SortOrder enum does not contains value '%s'", orderValue));
}

}
2 changes: 1 addition & 1 deletion src/main/java/xyz/selenide/tasks/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class Login {

public static void asManager(){
public static void asManager() {
LoginPage loginPage = new LoginPage();
loginPage.getBtnBankManagerLogin().click();
}
Expand Down
106 changes: 105 additions & 1 deletion src/main/java/xyz/selenide/tasks/Manager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package xyz.selenide.tasks;

import xyz.selenide.model.CustomerInformation;
import com.codeborne.selenide.Condition;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.SelenideElement;
import org.openqa.selenium.Alert;
import xyz.selenide.model.*;
import xyz.selenide.userInterface.AddCustomerPage;
import xyz.selenide.userInterface.CustomersPage;
import xyz.selenide.userInterface.OpenAccountPage;

import static com.codeborne.selenide.Selenide.switchTo;
import static org.apache.commons.lang3.StringUtils.isEmpty;

public class Manager {

Expand All @@ -12,4 +21,99 @@ public static void enterCustomerInformation(CustomerInformation customer) {
addCustomerPage.getInputPostCode().setValue(customer.getPostCode());
}

public static void addCustomer() {
AddCustomerPage addCustomerPage = new AddCustomerPage();
addCustomerPage.getButtonAddCustomer().click();

Alert info = switchTo().alert();
info.accept();
}

public static boolean areCustomerFieldsCleared() {
AddCustomerPage addCustomerPage = new AddCustomerPage();
String firstName = addCustomerPage.getInputFirstName().getText();
String lastName = addCustomerPage.getInputLastName().getText();
String postCode = addCustomerPage.getInputPostCode().getText();

return isEmpty(firstName) && isEmpty(lastName) && isEmpty(postCode);
}

public static boolean isCustomerInTheList(CustomerInformation customerInformation) {
CustomersPage customersPage = new CustomersPage();
ElementsCollection rows = customersPage.getTableCustomersRows();
String customerRowText = rows.findBy(Condition.partialText(customerInformation.getFirstName())).getText();
boolean isFirstNameVisible = customerRowText.contains(customerInformation.getFirstName());
boolean isLastNameVisible = customerRowText.contains(customerInformation.getLastName());
boolean isPostCodeVisible = customerRowText.contains(customerInformation.getPostCode());
return isFirstNameVisible && isLastNameVisible && isPostCodeVisible;
}

public static boolean isCustomerNotInTheList(CustomerInformation customerInformation) {
CustomersPage customersPage = new CustomersPage();
return customersPage.isCustomerNotInTheList(customerInformation);
}

public static String openCustomerAccount(CustomerInformation customerInformation, Currency currency) {
OpenAccountPage openAccountPage = new OpenAccountPage();
openAccountPage.getDrpCustomer().selectOption(customerInformation.toStringShort());
openAccountPage.getDrpCurrency().selectOption(currency.getCurrency());
openAccountPage.getButtonProcess().click();

Alert info = switchTo().alert();
return info.getText();
}

public static boolean isCustomerWithAccountInTheList(CustomerInformation customerInformation, String accountNumber) {
boolean isCustomerInTheList = isCustomerInTheList(customerInformation);
CustomersPage customersPage = new CustomersPage();
ElementsCollection rows = customersPage.getTableCustomersRows();
String customerRowText = rows.findBy(Condition.partialText(customerInformation.getFirstName())).getText();
boolean isAccountVisible = customerRowText.contains(accountNumber);

return isCustomerInTheList && isAccountVisible;
}

public static void searchCustomers(CustomerInformation customerInformation) {
CustomersPage customersPage = new CustomersPage();
//needed to trick the test into waiting for input to be ready
customersPage.getInputSearchCustomers().shouldBe(Condition.attribute("ng-model", "searchCustomer"));
customersPage.getInputSearchCustomers().setValue(customerInformation.getFirstName());
}

public static int customerCount() {
CustomersPage customersPage = new CustomersPage();
return customersPage.getTableCustomersRows().size() - 1;
}

public static void sortCustomers(CustomerSortColumn sortColumn, SortOrder sortOrder) {
CustomersPage customersPage = new CustomersPage();
SelenideElement columnTarget = customersPage.getLinkFirstName();
switch (sortColumn) {
case LAST_NAME -> columnTarget = customersPage.getLinkLastName();
case POST_CODE -> columnTarget = customersPage.getLinkPostCode();
}
switch (sortOrder) {
case DESC -> columnTarget.click();
case ASC -> {
columnTarget.click();
columnTarget.click();
}
}
}

public static Customers getCustomerList() {
CustomersPage customersPage = new CustomersPage();
return new Customers(customersPage.getTableCustomersRows());
}

public static void deleteCustomer(CustomerInformation customerInformation) {
searchCustomers(customerInformation);
CustomersPage customersPage = new CustomersPage();
customersPage.getButtonDelete().click();
}

public static void clearCustomerSearch() {
CustomersPage customersPage = new CustomersPage();
customersPage.getInputSearchCustomers().clear();
}
}
20 changes: 10 additions & 10 deletions src/main/java/xyz/selenide/tasks/Navigate.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public static void toAddCustomer() {
ManagerHomePage managerHomePage = new ManagerHomePage();
managerHomePage.getBtnAddCustomer().click();
}
//
// public static void toOpenAccount(Page page) {
// ManagerHomePage managerHomePage = new ManagerHomePage(page);
// managerHomePage.getBtnOpenAccount().click();
// }
//
// public static void toCustomers(Page page) {
// ManagerHomePage managerHomePage = new ManagerHomePage(page);
// managerHomePage.getBtnCustomers().click();
// }

public static void toOpenAccount() {
ManagerHomePage managerHomePage = new ManagerHomePage();
managerHomePage.getBtnOpenAccount().click();
}

public static void toCustomers() {
ManagerHomePage managerHomePage = new ManagerHomePage();
managerHomePage.getBtnCustomers().click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.codeborne.selenide.SelenideElement;
import lombok.Getter;

import static com.codeborne.selenide.Selectors.*;
import static com.codeborne.selenide.Selectors.by;
import static com.codeborne.selenide.Selectors.byXpath;
import static com.codeborne.selenide.Selenide.$;

@Getter
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/xyz/selenide/userInterface/CustomersPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package xyz.selenide.userInterface;

import com.codeborne.selenide.Condition;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.SelenideElement;
import lombok.Getter;
import xyz.selenide.model.CustomerInformation;

import static com.codeborne.selenide.Selectors.byTagName;
import static com.codeborne.selenide.Selectors.byText;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;

@Getter
public class CustomersPage {
private final SelenideElement inputSearchCustomers;
private final SelenideElement tableCustomers;
private final ElementsCollection tableCustomersRows;
private final SelenideElement buttonDelete;
private final SelenideElement linkFirstName;
private final SelenideElement linkLastName;
private final SelenideElement linkPostCode;

public CustomersPage() {
this.inputSearchCustomers = $(byTagName("input"));
this.tableCustomers = $(byTagName("table"));
this.tableCustomersRows = $$(byTagName("tr"));
this.buttonDelete = $(byText("Delete"));
this.linkFirstName = $(byText("First Name"));
this.linkLastName = $(byText("Last Name"));
this.linkPostCode = $(byText("Post Code"));
}

public boolean isCustomerNotInTheList(CustomerInformation customerInformation) {
SelenideElement notIn = $(byText(customerInformation.getFirstName())).shouldNot(Condition.exist);
return notIn.exists();
}
}
22 changes: 22 additions & 0 deletions src/main/java/xyz/selenide/userInterface/OpenAccountPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package xyz.selenide.userInterface;

import com.codeborne.selenide.SelenideElement;
import lombok.Getter;

import static com.codeborne.selenide.Selectors.byText;
import static com.codeborne.selenide.Selectors.byXpath;
import static com.codeborne.selenide.Selenide.$;

@Getter
public class OpenAccountPage {
private final SelenideElement drpCustomer;
private final SelenideElement drpCurrency;
private final SelenideElement buttonProcess;

public OpenAccountPage() {
this.drpCustomer = $(byXpath("//select[@id='userSelect']"));
this.drpCurrency = $(byXpath("//select[@id='currency']"));
this.buttonProcess = $(byText("Process"));
}

}
13 changes: 13 additions & 0 deletions src/test/java/xyz/selenide/stepDefinitions/Hooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package xyz.selenide.stepDefinitions;

import com.codeborne.selenide.WebDriverRunner;
import io.cucumber.java.After;

public class Hooks {

@After
public void After() {
WebDriverRunner.closeWebDriver();
}

}
Loading

0 comments on commit e37bd80

Please sign in to comment.