Skip to content

Commit

Permalink
4903: tests refactoring BADGE
Browse files Browse the repository at this point in the history
  • Loading branch information
Kate-Semenova committed Jul 24, 2023
1 parent 3c8babe commit 4e60ac8
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -17,4 +18,6 @@ public class StaticSite {

@Url("progress_spinner")
public static ProgressSpinnerPage progressSpinnerPage;
@Url("badges")
public static BadgePage badgePage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,66 @@

import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert;

public class BadgeAssert extends UIAssert<BadgeAssert, Badge> {
public class BadgeAssert extends UIAssert<BadgeAssert, Badge> {

@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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BadgeAssert> {
public class Badge extends UIBaseElement<BadgeAssert> implements HasClick {

@JDIAction("Get '{name}' badge")
public UIElement badge() {
Expand All @@ -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"));
}
Expand All @@ -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");
}

}

0 comments on commit 4e60ac8

Please sign in to comment.