Skip to content

Commit

Permalink
4903: tests refactoring BADGE. fix 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Kate-Semenova committed Aug 24, 2023
1 parent 01e3ac0 commit 7ca902f
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,7 @@
import com.epam.jdi.light.elements.composite.WebPage;
import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI;
import com.epam.jdi.light.ui.html.elements.common.Icon;
import io.github.com.pages.sections.AutocompleteSection;
import io.github.com.pages.sections.ButtonToggleSection;
import io.github.com.pages.sections.CardSection;
import io.github.com.pages.sections.CheckboxSection;
import io.github.com.pages.sections.ChipsSection;
import io.github.com.pages.sections.DatepickerSection;
import io.github.com.pages.sections.DividerSection;
import io.github.com.pages.sections.ExpansionPanelSection;
import io.github.com.pages.sections.FormFieldsSection;
import io.github.com.pages.sections.GridListSection;
import io.github.com.pages.sections.InputSection;
import io.github.com.pages.sections.ListSection;
import io.github.com.pages.sections.MenuSection;
import io.github.com.pages.sections.PaginatorSection;
import io.github.com.pages.sections.RadioButtonSection;
import io.github.com.pages.sections.SelectSection;
import io.github.com.pages.sections.SideNavSection;
import io.github.com.pages.sections.SlideToggleSection;
import io.github.com.pages.sections.SliderSection;
import io.github.com.pages.sections.SnackbarSection;
import io.github.com.pages.sections.SortingOverviewSection;
import io.github.com.pages.sections.TabGroupSection;
import io.github.com.pages.sections.TableSection;
import io.github.com.pages.sections.ToolbarSection;
import io.github.com.pages.sections.TooltipSection;
import io.github.com.pages.sections.*;

public class AngularPage extends WebPage {

Expand All @@ -50,7 +26,6 @@ public class AngularPage extends WebPage {
public static SelectSection selectSection;
public static ListSection listSection;
public static GridListSection gridListSection;
public static BasicButtonsSection basicButtonsSection;
public static AutocompleteSection autocompleteSection;
public static SnackbarSection snackbarSection;
public static ButtonToggleSection buttonToggleSection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import static com.epam.jdi.light.angular.elements.enums.BadgePosition.ABOVE;
import static com.epam.jdi.light.angular.elements.enums.BadgePosition.AFTER;
import static com.epam.jdi.light.angular.elements.enums.BadgePosition.BEFORE;
import static com.epam.jdi.light.angular.elements.enums.BadgePosition.BELOW;
import static com.epam.jdi.light.angular.elements.enums.BadgeSize.LARGE;
import static com.epam.jdi.light.angular.elements.enums.BadgeSize.MEDIUM;
import static com.epam.jdi.light.angular.elements.enums.BadgeSize.SMALL;
import static com.jdiai.tools.Timer.waitCondition;
import static io.github.com.StaticSite.badgePage;
import static io.github.com.enums.Colors.AMBER_ACCENT_2;
import static io.github.com.enums.Colors.DEEP_PURPLE;
import static io.github.com.enums.Colors.RED;
import static io.github.com.pages.BadgePage.bellowPositionBadge;
import static io.github.com.pages.BadgePage.buttonWithBadge;
import static io.github.com.pages.BadgePage.customSizeBadge;
Expand All @@ -23,50 +33,34 @@ public void before() {
badgePage.open();
waitCondition(() -> badgePage.isOpened());
badgePage.checkOpened();
}

@Test
public void basicBadgeTest() {
textWithBadge.show();
textWithBadge.badge().is().displayed();
textWithBadge.badge().has().text("4");
textWithBadge.has().color("Violet");
}

@Test
public void buttonBadgeTest() {
buttonWithBadge.show();
buttonWithBadge.badge().is().displayed();
buttonWithBadge.badge().has().text("8");
buttonWithBadge.has().color("Yellow");
}

@Test
public void iconBadgeTest() {
iconWithBadge.show();
iconWithBadge.badge().is().displayed();
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(description = "The test checks color of the badge and content (string/number)")
public void colorAndContentBadgeTest() {
iconWithBadge.is().displayed()
.has().text("15")
.and().has().color(RED.value());
buttonWithBadge.is().displayed()
.has().text("8")
.and().has().color(AMBER_ACCENT_2.value());
customSizeBadge.is().displayed()
.has().text("Best")
.and().has().color(DEEP_PURPLE.value());
}

@Test
@Test(description = "Test checks if the badge is disabled/enabled")
public void disabledBadgeTest() {
toggleDisabledBadge.is().disabled();
toggleVisibilityBadge.click();
toggleVisibilityBadge.is().enabled();
toggleVisibilityBadge.click();

toggleDisabledBadge.click();
toggleDisabledBadge.is().enabled();

toggleDisabledBadge.click();
toggleDisabledBadge.is().disabled();
}

@Test
@Test(description = "Test checks the visibility of the badge")
public void hiddenBadgeTest() {
toggleVisibilityBadge.is().displayed();
toggleVisibilityBadge.click();
Expand All @@ -75,33 +69,34 @@ public void hiddenBadgeTest() {
toggleVisibilityBadge.is().displayed();
}

@Test
@Test(description = "Test checks if badge overlaps")
public void overlapBadgeTest() {
textWithBadge.is().overlap(false);

buttonWithBadge.is().overlap(true);
}

@Test
@Test(description = "Test check position of the badge")
public void positionOfTheBadgeTest() {
buttonWithBadge.has().positionVertical("above");
buttonWithBadge.has().positionHorizontal("before");
buttonWithBadge.has().positionVertical(ABOVE)
.and().has().positionHorizontal(BEFORE);

textWithBadge.has().positionVertical("above");
textWithBadge.has().positionHorizontal("after");
textWithBadge.has().positionVertical(ABOVE)
.and().has().positionHorizontal(AFTER);

bellowPositionBadge.has().positionVertical("below");
bellowPositionBadge.has().positionHorizontal("after");
bellowPositionBadge.has().positionVertical(BELOW)
.and().has().positionHorizontal(AFTER);
}

@Test
@Test(description = "Test checks size of the badge")
public void sizeOfTheBadgeTest() {
largeBadge.badge().is().displayed();
largeBadge.has().size("large");
largeBadge.is().displayed()
.and().has().size(LARGE);

smallBadge.badge().is().displayed();
smallBadge.has().size("small");
smallBadge.is().displayed()
.and().has().size(SMALL);

textWithBadge.badge().is().displayed();
textWithBadge.has().size("medium");
textWithBadge.is().displayed()
.and().has().size(MEDIUM);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,18 @@
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

import static com.jdiai.tools.Timer.waitCondition;
import static io.github.com.StaticSite.badgePage;
import static io.github.com.pages.BadgePage.textWithBadge;
import static io.github.com.StaticSite.angularPage;
import static io.github.epam.site.steps.States.shouldBeLoggedIn;
import static org.testng.Assert.assertTrue;

// TODO Move to the new page
@Ignore
public class BadgeUnitTests extends TestsInit {

@BeforeMethod(alwaysRun = true)
public void before() {
badgePage.open();
waitCondition(() -> badgePage.isOpened());
badgePage.checkOpened();
shouldBeLoggedIn();
angularPage.shouldBeOpened();
}

@Test
public void badgeTest() {
assertTrue(textWithBadge.badge().isDisplayed());
}

@Test
public void colorTest() {
assertTrue(textWithBadge.color("Violet"));
}
}
Original file line number Diff line number Diff line change
@@ -1,72 +1,79 @@
package com.epam.jdi.light.angular.asserts;

import com.epam.jdi.light.angular.elements.common.Badge;
import com.epam.jdi.light.angular.elements.enums.BadgePosition;
import com.epam.jdi.light.angular.elements.enums.BadgeSize;
import com.epam.jdi.light.asserts.generic.UIAssert;
import com.epam.jdi.light.common.JDIAction;
import org.hamcrest.Matchers;

import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert;
import static java.lang.String.format;

public class BadgeAssert extends UIAssert<BadgeAssert, Badge> {

@JDIAction("Assert that '{name}' has '{0}' color")
public BadgeAssert color(String value) {
jdiAssert(element().color(value), Matchers.is(true));
String actualColor = element().color();
jdiAssert(actualColor, Matchers.equalTo(value), format("%s is not equal to %s", actualColor, value));
return this;
}

@JDIAction("Assert that '{name}' has '{0}' size")
public BadgeAssert size(String value) {
jdiAssert(element().size(value), Matchers.is(true));
public BadgeAssert size(BadgeSize size) {
final BadgeSize actualBadgeSize = element().size();
jdiAssert(actualBadgeSize, Matchers.is(size), format("%s is not equal to %s", actualBadgeSize, size));
return this;

}

@JDIAction("Assert that '{name}' has '{0}' position (vertical)")
public BadgeAssert positionVertical(String value) {
jdiAssert(element().positionVertical(value), Matchers.is(true));
public BadgeAssert positionVertical(BadgePosition value) {
final BadgePosition actualPosition = element().positionVertical();
jdiAssert(actualPosition, Matchers.is(value), format("%s is not equal to %s", actualPosition, value));
return this;

}

@JDIAction("Assert that '{name}' has '{0}' position (horizontal)")
public BadgeAssert positionHorizontal(String value) {
jdiAssert(element().positionHorizontal(value), Matchers.is(true));
public BadgeAssert positionHorizontal(BadgePosition value) {
final BadgePosition actualPosition = element().positionHorizontal();
jdiAssert(actualPosition, Matchers.is(value), format("%s is not equal to %s", actualPosition, value));
return this;

}

@JDIAction("Assert that '{name}' is overlap: {0}")
public BadgeAssert overlap(boolean value) {
jdiAssert(element().overlap(), Matchers.is(value));
jdiAssert(element().isOverlap(), Matchers.is(value), value ? "should be overlap" : "should NOT be overlap");
return this;
}

@Override
@JDIAction("Assert that '{name}' is displayed")
public BadgeAssert displayed() {
jdiAssert(element().hidden(), Matchers.is(false));
jdiAssert(element().isDisplayed(), Matchers.is(true), "should be displayed");
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));
jdiAssert(element().isEnabled(), Matchers.is(true), "should be enabled");
return super.enabled();
}

@Override
@JDIAction("Assert that '{name}' is disabled")
public BadgeAssert disabled() {
jdiAssert(element().disabled(), Matchers.is(true));
jdiAssert(element().isDisabled(), Matchers.is(true), "should be disabled");
return this;
}

@JDIAction("Assert that '{name}' has text {0}")
public BadgeAssert text(String value) {
final String actualText = element().getText();
jdiAssert(actualText, Matchers.is(value), format("%s is not equal to %s", actualText, value));
return this;
}
}
Loading

0 comments on commit 7ca902f

Please sign in to comment.