Skip to content

Commit

Permalink
refactor asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
b14ckster committed Oct 13, 2023
1 parent dd6abf5 commit f2f26c5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class AngularPage extends WebPage {
public static InputSection inputSection;
public static SelectSection selectSection;
public static ListSection listSection;
public static AutocompleteSection autocompleteSection;
public static SnackbarSection snackbarSection;
public static MenuSection menuSection;
public static PaginatorSection paginatorSection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public void basicGridListTest() {
basicGridList.show();
basicGridList.shouldBe().visible();

basicGridList.has().numberOfColumnsInGridList("2")
basicGridList.has().numberOfColumns(2)
.and().rowHeight("2:1")
.and().gutterSize("10px")

.and().cellText(1, "1")
.and().cellBackgroundColor(1, LIGHT_BLUE_2.value())
.and().numberOfColumnsInCell(1, "1")
.and().numberOfRowsInCell(1, "1");
.and().numberOfColumnsInCell(1, 1)
.and().numberOfRowsInCell(1, 1);
}

@Test(description = "Test checks dynamic grid list attributes")
Expand All @@ -44,7 +44,7 @@ public void dynamicGridListTest() {
dynamicGridList.show();
dynamicGridList.shouldBe().visible();

dynamicGridList.has().numberOfColumnsInGridList("4")
dynamicGridList.has().numberOfColumns(4)
.and().rowHeight("100px")
.and().gutterSize("10px")

Expand All @@ -54,11 +54,11 @@ public void dynamicGridListTest() {
.and().cellBackgroundColor(2, LIGHT_GREEN_2.value())
.and().cellBackgroundColor(4, LIGHT_LILAC.value())

.and().numberOfColumnsInCell(1, "3")
.and().numberOfColumnsInCell(2, "1")
.and().numberOfColumnsInCell(4, "2")
.and().numberOfColumnsInCell(1, 3)
.and().numberOfColumnsInCell(2, 1)
.and().numberOfColumnsInCell(4, 2)

.and().numberOfRowsInCell(1, "1")
.and().numberOfRowsInCell(2, "2");
.and().numberOfRowsInCell(1, 1)
.and().numberOfRowsInCell(2, 2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

import com.epam.jdi.light.angular.elements.complex.GridList;
import com.epam.jdi.light.asserts.generic.UIAssert;
import com.epam.jdi.light.angular.elements.enums.AngularColors;
import com.epam.jdi.light.common.JDIAction;
import org.hamcrest.Matchers;

public class GridListAssert extends UIAssert<GridListAssert, GridList> {

@JDIAction("Assert that '{name}' has number of columns '{0}'")
public GridListAssert numberOfColumnsInGridList(String expectedNumberOfColumns) {
String actualNumberOfColumns = element().numberOfColumnsInGridList();
public GridListAssert numberOfColumns(int expectedNumberOfColumns) {
int actualNumberOfColumns = element().numberOfColumns();
jdiAssert(actualNumberOfColumns, Matchers.is(expectedNumberOfColumns),
String.format("\nActual number of columns in Grid List: '%s'\n" +
"is not equal to expected: '%s'", actualNumberOfColumns, expectedNumberOfColumns));
Expand All @@ -21,54 +22,42 @@ public GridListAssert numberOfColumnsInGridList(String expectedNumberOfColumns)
@JDIAction("Assert that '{name}' has row's height '{0}'")
public GridListAssert rowHeight(String expectedRowHeight) {
String actualRowHeight = element().rowHeight();
jdiAssert(actualRowHeight, Matchers.is(expectedRowHeight),
String.format("\nActual row height: '%s'\n" +
"is not equal to expected: '%s'", actualRowHeight, expectedRowHeight));
jdiAssert(actualRowHeight, Matchers.is(expectedRowHeight));
return this;
}

@JDIAction("Assert that '{name}' has gutter size '{0}'")
public GridListAssert gutterSize(String expectedGutterSize) {
String actualGutterSize = element().gutterSize();
jdiAssert(actualGutterSize, Matchers.is(expectedGutterSize),
String.format("\nActual gutter size: '%s'\n" +
"is not equal to expected: '%s'", actualGutterSize, expectedGutterSize));
jdiAssert(actualGutterSize, Matchers.is(expectedGutterSize));
return this;
}

@JDIAction("Assert that '{name}' cell has text '{1}'")
public GridListAssert cellText(int cellIndex, String ExpectedText) {
public GridListAssert cellText(int cellIndex, String expectedText) {
String actualText = element().cellByIndex(cellIndex).text();
jdiAssert(actualText, Matchers.is(ExpectedText),
String.format("\nActual cell's text: '%s'\n" +
"is not equal to expected: '%s'", actualText, ExpectedText));
jdiAssert(actualText, Matchers.is(expectedText));
return this;
}

@JDIAction("Assert that '{name}' cell has background color '{1}'")
public GridListAssert cellBackgroundColor(int cellIndex, String expectedColor) {
String actualColor = element().cellBackgroundColorByIndex(cellIndex);
jdiAssert(actualColor, Matchers.is(expectedColor),
String.format("\nActual cell's background color: '%s'\n" +
"is not equal to expected: '%s'", actualColor, expectedColor));
jdiAssert(actualColor, Matchers.is(expectedColor));
return this;
}

@JDIAction("Assert that '{name}' cell has number of columns '{1}'")
public GridListAssert numberOfColumnsInCell(int cellIndex, String expectedNumberOfColumns) {
String actualNumberOfColumns = element().numberOfColumnsInCellByIndex(cellIndex);
jdiAssert(actualNumberOfColumns, Matchers.is(expectedNumberOfColumns),
String.format("\nActual number of columns in cell: '%s'\n" +
"is not equal to expected: '%s'", actualNumberOfColumns, expectedNumberOfColumns));
public GridListAssert numberOfColumnsInCell(int cellIndex, int expectedNumberOfColumns) {
int actualNumberOfColumns = element().numberOfColumnsInCellByIndex(cellIndex);
jdiAssert(actualNumberOfColumns, Matchers.is(expectedNumberOfColumns));
return this;
}

@JDIAction("Assert that '{name}' cell has number of rows '{1}'")
public GridListAssert numberOfRowsInCell(int cellIndex, String expectedNumberOfRows) {
String actualNumberOfRows = element().numberOfRowsInCellByIndex(cellIndex);
jdiAssert(actualNumberOfRows, Matchers.is(expectedNumberOfRows),
String.format("\nActual number of rows in cell: '%s'\n" +
"is not equal to expected: '%s'", actualNumberOfRows, expectedNumberOfRows));
public GridListAssert numberOfRowsInCell(int cellIndex, int expectedNumberOfRows) {
int actualNumberOfRows = element().numberOfRowsInCellByIndex(cellIndex);
jdiAssert(actualNumberOfRows, Matchers.is(expectedNumberOfRows));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
public class GridList extends UIBaseElement<GridListAssert> {

@JDIAction(value = "Get '{name}' number of columns")
public String numberOfColumnsInGridList() {
return core().getAttribute("cols");
public int numberOfColumns() {
return Integer.parseInt(core().getAttribute("cols"));
}

@JDIAction(value = "Get '{name}' row's height")
Expand All @@ -32,13 +32,13 @@ public UIElement cellByIndex(int index) {
}

@JDIAction(value = "Get '{name}' cell's number of columns by index '{0}'")
public String numberOfColumnsInCellByIndex(int index) {
return cellByIndex(index).getAttribute("colspan");
public int numberOfColumnsInCellByIndex(int index) {
return Integer.parseInt(cellByIndex(index).getAttribute("colspan"));
}

@JDIAction(value = "Get '{name}' cell's number of rows by index '{0}'")
public String numberOfRowsInCellByIndex(int index) {
return cellByIndex(index).getAttribute("rowspan");
public int numberOfRowsInCellByIndex(int index) {
return Integer.parseInt(cellByIndex(index).getAttribute("rowspan"));
}

@JDIAction(value = "Get '{name}' cell's background color by index '{0}'")
Expand Down

0 comments on commit f2f26c5

Please sign in to comment.