From 4e60ac8bcb783366028201f7eb32ed040df7028d Mon Sep 17 00:00:00 2001 From: Ekaterina_Semenova1 Date: Thu, 20 Jul 2023 14:13:24 +0400 Subject: [PATCH] 4903: tests refactoring BADGE --- .../main/java/io/github/com/StaticSite.java | 5 +- .../java/io/github/com/pages/AngularPage.java | 1 - .../java/io/github/com/pages/BadgePage.java | 17 ++++ .../com/pages/sections/BadgeSection.java | 10 --- .../tests/elements/common/BadgeTests.java | 82 +++++++++++++++--- .../angular/tests/unit/BadgeUnitTests.java | 13 ++- .../light/angular/asserts/BadgeAssert.java | 59 ++++++++++++- .../light/angular/elements/common/Badge.java | 86 ++++++++++++++++++- 8 files changed, 240 insertions(+), 33 deletions(-) create mode 100644 jdi-light-angular-tests/src/main/java/io/github/com/pages/BadgePage.java delete mode 100644 jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/BadgeSection.java diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java b/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java index 110cf6e6ee0..6408b32f893 100644 --- a/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java +++ b/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java @@ -1,8 +1,9 @@ package io.github.com; import com.epam.jdi.light.elements.pageobjects.annotations.JSite; -import com.epam.jdi.light.elements.pageobjects.annotations.Url;; +import com.epam.jdi.light.elements.pageobjects.annotations.Url; import io.github.com.pages.AngularPage; +import io.github.com.pages.BadgePage; import io.github.com.pages.ProgressBarPage; import io.github.com.pages.ProgressSpinnerPage; @@ -17,4 +18,6 @@ public class StaticSite { @Url("progress_spinner") public static ProgressSpinnerPage progressSpinnerPage; + @Url("badges") + public static BadgePage badgePage; } diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/AngularPage.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/AngularPage.java index d38d6c5bd65..81667b2c6d6 100644 --- a/jdi-light-angular-tests/src/main/java/io/github/com/pages/AngularPage.java +++ b/jdi-light-angular-tests/src/main/java/io/github/com/pages/AngularPage.java @@ -26,7 +26,6 @@ public class AngularPage extends WebPage { public static SelectSection selectSection; public static ListSection listSection; public static GridListSection gridListSection; - public static BadgeSection badgeSection; public static BasicButtonsSection basicButtonsSection; public static AutocompleteSection autocompleteSection; public static SnackbarSection snackbarSection; diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/BadgePage.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/BadgePage.java new file mode 100644 index 00000000000..067b937742a --- /dev/null +++ b/jdi-light-angular-tests/src/main/java/io/github/com/pages/BadgePage.java @@ -0,0 +1,17 @@ +package io.github.com.pages; + +import com.epam.jdi.light.angular.elements.common.Badge; + +public class BadgePage extends NewAngularPage { + + public static Badge textWithBadge; + public static Badge buttonWithBadge; + public static Badge iconWithBadge; + public static Badge largeBadge; + public static Badge smallBadge; + public static Badge customSizeBadge; + public static Badge bellowPositionBadge; + public static Badge toggleVisibilityBadge; + public static Badge toggleDisabledBadge; + +} diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/BadgeSection.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/BadgeSection.java deleted file mode 100644 index f2e19109ce2..00000000000 --- a/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/BadgeSection.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.github.com.pages.sections; - -import com.epam.jdi.light.angular.elements.common.Badge; -import com.epam.jdi.light.elements.composite.Section; - -public class BadgeSection extends Section { - public static Badge textWithBadge; - public static Badge buttonWithBadge; - public static Badge iconWithBadge; -} diff --git a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/common/BadgeTests.java b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/common/BadgeTests.java index 0c7a71a604d..522f1cb9748 100644 --- a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/common/BadgeTests.java +++ b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/common/BadgeTests.java @@ -2,23 +2,27 @@ import io.github.epam.TestsInit; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Ignore; import org.testng.annotations.Test; -import static io.github.com.StaticSite.angularPage; -import static io.github.com.pages.sections.BadgeSection.buttonWithBadge; -import static io.github.com.pages.sections.BadgeSection.iconWithBadge; -import static io.github.com.pages.sections.BadgeSection.textWithBadge; -import static io.github.epam.site.steps.States.shouldBeLoggedIn; +import static com.jdiai.tools.Timer.waitCondition; +import static io.github.com.StaticSite.badgePage; +import static io.github.com.pages.BadgePage.bellowPositionBadge; +import static io.github.com.pages.BadgePage.buttonWithBadge; +import static io.github.com.pages.BadgePage.customSizeBadge; +import static io.github.com.pages.BadgePage.iconWithBadge; +import static io.github.com.pages.BadgePage.largeBadge; +import static io.github.com.pages.BadgePage.smallBadge; +import static io.github.com.pages.BadgePage.textWithBadge; +import static io.github.com.pages.BadgePage.toggleDisabledBadge; +import static io.github.com.pages.BadgePage.toggleVisibilityBadge; -// TODO Move to the new page -@Ignore public class BadgeTests extends TestsInit { - @BeforeMethod(alwaysRun = true) + @BeforeMethod public void before() { - shouldBeLoggedIn(); - angularPage.shouldBeOpened(); + badgePage.open(); + waitCondition(() -> badgePage.isOpened()); + badgePage.checkOpened(); } @Test @@ -44,4 +48,60 @@ public void iconBadgeTest() { iconWithBadge.badge().has().text("15"); iconWithBadge.has().color("Red"); } + + @Test + public void badgeWithTextTest() { + customSizeBadge.badge().is().displayed(); + customSizeBadge.badge().has().text("Best"); + customSizeBadge.has().color("Violet"); + + } + + @Test + public void disabledBadgeTest() { + toggleDisabledBadge.is().disabled(); + toggleVisibilityBadge.click(); + toggleVisibilityBadge.is().enabled(); + toggleVisibilityBadge.click(); + toggleDisabledBadge.is().disabled(); + } + + @Test + public void hiddenBadgeTest() { + toggleVisibilityBadge.is().displayed(); + toggleVisibilityBadge.click(); + toggleVisibilityBadge.is().hidden(); + toggleVisibilityBadge.click(); + toggleVisibilityBadge.is().displayed(); + } + + @Test + public void overlapBadgeTest() { + textWithBadge.is().overlap(false); + buttonWithBadge.is().overlap(true); + } + + @Test + public void positionOfTheBadgeTest() { + buttonWithBadge.has().positionVertical("above"); + buttonWithBadge.has().positionHorizontal("before"); + + textWithBadge.has().positionVertical("above"); + textWithBadge.has().positionHorizontal("after"); + + bellowPositionBadge.has().positionVertical("below"); + bellowPositionBadge.has().positionHorizontal("after"); + } + + @Test + public void sizeOfTheBadgeTest() { + largeBadge.badge().is().displayed(); + largeBadge.has().size("large"); + + smallBadge.badge().is().displayed(); + smallBadge.has().size("small"); + + textWithBadge.badge().is().displayed(); + textWithBadge.has().size("medium"); + } } diff --git a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/unit/BadgeUnitTests.java b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/unit/BadgeUnitTests.java index 5f5d2b57958..94b2e257e78 100644 --- a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/unit/BadgeUnitTests.java +++ b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/unit/BadgeUnitTests.java @@ -5,19 +5,18 @@ import org.testng.annotations.Ignore; import org.testng.annotations.Test; -import static io.github.com.StaticSite.angularPage; -import static io.github.com.pages.sections.BadgeSection.textWithBadge; -import static io.github.epam.site.steps.States.shouldBeLoggedIn; +import static com.jdiai.tools.Timer.waitCondition; +import static io.github.com.StaticSite.badgePage; +import static io.github.com.pages.BadgePage.textWithBadge; import static org.testng.Assert.assertTrue; -// TODO Move to the new page -@Ignore public class BadgeUnitTests extends TestsInit { @BeforeMethod(alwaysRun = true) public void before() { - shouldBeLoggedIn(); - angularPage.shouldBeOpened(); + badgePage.open(); + waitCondition(() -> badgePage.isOpened()); + badgePage.checkOpened(); } @Test diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/BadgeAssert.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/BadgeAssert.java index 2a9bb2b2266..11640b705a9 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/BadgeAssert.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/BadgeAssert.java @@ -7,11 +7,66 @@ import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert; -public class BadgeAssert extends UIAssert { +public class BadgeAssert extends UIAssert { - @JDIAction("'{name}' has '{0}' color") + @JDIAction("Assert that '{name}' has '{0}' color") public BadgeAssert color(String value) { jdiAssert(element().color(value), Matchers.is(true)); return this; } + + @JDIAction("Assert that '{name}' has '{0}' size") + public BadgeAssert size(String value) { + jdiAssert(element().size(value), Matchers.is(true)); + return this; + + } + + @JDIAction("Assert that '{name}' has '{0}' position (vertical)") + public BadgeAssert positionVertical(String value) { + jdiAssert(element().positionVertical(value), Matchers.is(true)); + return this; + + } + + @JDIAction("Assert that '{name}' has '{0}' position (horizontal)") + public BadgeAssert positionHorizontal(String value) { + jdiAssert(element().positionHorizontal(value), Matchers.is(true)); + return this; + + } + + @JDIAction("Assert that '{name}' is overlap: {0}") + public BadgeAssert overlap(boolean value) { + jdiAssert(element().overlap(), Matchers.is(value)); + return this; + } + + @Override + @JDIAction("Assert that '{name}' is displayed") + public BadgeAssert displayed() { + jdiAssert(element().hidden(), Matchers.is(false)); + return super.displayed(); + } + + @Override + @JDIAction("Assert that '{name}' is hidden") + public BadgeAssert hidden() { + jdiAssert(element().hidden(), Matchers.is(true)); + return this; + } + + @Override + @JDIAction("Assert that '{name}' is enabled") + public BadgeAssert enabled() { + jdiAssert(element().disabled(), Matchers.is(false)); + return super.enabled(); + } + + @Override + @JDIAction("Assert that '{name}' is disabled") + public BadgeAssert disabled() { + jdiAssert(element().disabled(), Matchers.is(true)); + return this; + } } diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/Badge.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/Badge.java index 8328cef034a..791b1987314 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/Badge.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/Badge.java @@ -4,12 +4,13 @@ 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.interfaces.base.HasClick; /** * To see an example of Badge web element please visit https://material.angular.io/components/badge/overview. */ -public class Badge extends UIBaseElement { +public class Badge extends UIBaseElement implements HasClick { @JDIAction("Get '{name}' badge") public UIElement badge() { @@ -26,6 +27,7 @@ public BadgeAssert is() { return new BadgeAssert().set(this); } + @JDIAction("Get '{name}' color") private String getColor() { return getColor(badge().css("background-color")); } @@ -42,4 +44,86 @@ private String getColor(String bgValue) { return "unknown color"; } } + + public boolean size(String value) { + return getBadgeSize().equalsIgnoreCase(value); + } + + private String getAttrClass() { + return attr("class"); + } + + private String getBadgeSize() { + return getBadgeSize(getAttrClass()); + } + + private String getBadgeSize(String aClass) { + String medium = "mat-badge-medium"; + String large = "mat-badge-large"; + String small = "mat-badge-small"; + if (aClass.contains(medium)) { + return "medium"; + } + if (aClass.contains(large)) { + return "large"; + } + if (aClass.contains(small)) { + return "small"; + } + return "unknown size"; + } + + public boolean positionVertical(String position) { + return getPositionVertical().equalsIgnoreCase(position); + } + + private String getPositionVertical() { + return getPositionVertical(getAttrClass()); + + } + + private String getPositionVertical(String aClass) { + String above = "mat-badge-above"; + String below = "mat-badge-below"; + if (aClass.contains(above)) { + return "above"; + } + if (aClass.contains(below)) { + return "below"; + } + return "unknown vertical position"; + } + + public boolean positionHorizontal(String position) { + return getPositionHorizontal().equalsIgnoreCase(position); + } + + private String getPositionHorizontal() { + return getPositionHorizontal(getAttrClass()); + } + + private String getPositionHorizontal(String aClass) { + String before = "mat-badge-before"; + String after = "mat-badge-after"; + if (aClass.contains(before)) { + return "before"; + } + if (aClass.contains(after)) { + return "after"; + } + return "unknown horizontal position"; + } + + public boolean overlap() { + return getAttrClass().contains("mat-badge-overlap"); + } + + public boolean hidden() { + return getAttrClass().contains("mat-badge-hidden"); + } + + public boolean disabled() { + return getAttrClass().contains("mat-badge-disabled"); + } + }