From ecb285a1407fdc3b6af7622d1efafc71b118d67f Mon Sep 17 00:00:00 2001 From: Maiia_Afanaseva Date: Fri, 28 Jul 2023 14:23:28 +0300 Subject: [PATCH] 4938-rippleTestsRefactoring --- .../main/java/io/github/com/StaticSite.java | 4 + .../java/io/github/com/pages/AngularPage.java | 1 - .../java/io/github/com/pages/RipplePage.java | 8 ++ .../tests/elements/complex/RippleTests.java | 57 +++++-------- .../angular/tests/unit/RippleUnitTests.java | 84 +++++-------------- .../angular/elements/complex/Ripple.java | 72 +++++++--------- 6 files changed, 86 insertions(+), 140 deletions(-) create mode 100644 jdi-light-angular-tests/src/main/java/io/github/com/pages/RipplePage.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..fc4d558519c 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 @@ -5,6 +5,7 @@ import io.github.com.pages.AngularPage; import io.github.com.pages.ProgressBarPage; import io.github.com.pages.ProgressSpinnerPage; +import io.github.com.pages.RipplePage; @JSite("https://jdi-testing.github.io/jdi-light/angular-page/#/") public class StaticSite { @@ -17,4 +18,7 @@ public class StaticSite { @Url("progress_spinner") public static ProgressSpinnerPage progressSpinnerPage; + + @Url("ripple") + public static RipplePage ripplePage; } 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..a2058a43be6 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 @@ -14,7 +14,6 @@ public class AngularPage extends WebPage { public static Icon basicIcon; @UI("#svg_icon") public static Icon svgIcon; - public static Ripple rippleContainer; @UI("#bottom-sheet") public static BottomSheet bottomSheet; public static Dialog dialog; diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/RipplePage.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/RipplePage.java new file mode 100644 index 00000000000..1a0697e2949 --- /dev/null +++ b/jdi-light-angular-tests/src/main/java/io/github/com/pages/RipplePage.java @@ -0,0 +1,8 @@ +package io.github.com.pages; + +import com.epam.jdi.light.angular.elements.complex.Ripple; + +public class RipplePage extends NewAngularPage { + + public static Ripple rippleContainer; +} diff --git a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/RippleTests.java b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/RippleTests.java index 2d754f0a156..e0dc5915a78 100644 --- a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/RippleTests.java +++ b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/RippleTests.java @@ -3,23 +3,20 @@ import io.github.epam.TestsInit; import org.apache.commons.lang3.RandomUtils; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Ignore; import org.testng.annotations.Test; import static com.epam.jdi.light.elements.composite.WebPage.refresh; -import static io.github.com.StaticSite.angularPage; -import static io.github.com.pages.AngularPage.rippleContainer; -import static io.github.epam.site.steps.States.shouldBeLoggedIn; +import static com.jdiai.tools.Timer.waitCondition; +import static io.github.com.StaticSite.ripplePage; +import static io.github.com.pages.RipplePage.*; import static org.hamcrest.Matchers.is; -// TODO Move to the new page -@Ignore public class RippleTests extends TestsInit { - @BeforeMethod(alwaysRun = true) + @BeforeMethod public void before() { - shouldBeLoggedIn(); - angularPage.shouldBeOpened(); - rippleContainer.show(); + ripplePage.open(); + waitCondition(() -> ripplePage.isOpened()); + ripplePage.checkOpened(); } @Test(description = "Test checks that ripple container is displayed") @@ -57,88 +54,78 @@ public void rippleActionTest() { rippleContainer.is().active(); } - @Test(description = "Test checks ripple feature: radius(number)") + @Test(description = "Test checks ripple feature: radius") public void radiusTest() { int expectedRadius = 260; rippleContainer.setRadius(expectedRadius); rippleContainer.has().radius(expectedRadius); } - @Test(description = "Test checks ripple feature: radius(number)") + @Test(description = "Test checks ripple feature: radius correct value") public void rippleRadiusTest() { int expectedRadius = 124; rippleContainer.setRadius(expectedRadius); rippleContainer.is().radius(is(124)); } - @Test + @Test(description = "Test checks ripple feature: radius attributes(correct number)") public void rippleCorrectRadiusTest() { rippleContainer.setRadius(100); rippleContainer.has().correctRadius(); } - @Test + @Test(description = "Test checks ripple feature: radius attributes(incorrect number)") public void rippleNotCorrectRadiusTest() { refresh(); rippleContainer.setRadius(-5); rippleContainer.has().incorrectRadius(); } - @Test - public void colorTest() { - String expectedColor = "BLUE"; - rippleContainer.setColor(expectedColor); - rippleContainer.is().color(expectedColor.toLowerCase()); - } - - @Test + @Test(description = "Test checks ripple feature: color attributes(correct value)") public void rippleCorrectColorTest() { - refresh(); rippleContainer.setColor("rgba(255, 0, 255, 0.7)"); rippleContainer.has().correctColor(); } - @Test + @Test(description = "Test checks ripple feature: color attributes(incorrect value)") public void rippleNotCorrectColorTest() { - refresh(); rippleContainer.setColor("custom color"); rippleContainer.has().incorrectColor(); } - @Test + @Test(description = "Test checks ripple has correct radius and value") public void rippleRadiusAndColorTest() { - refresh(); String expectedColor = "SALMON"; int expectedRadius = 219; rippleContainer.setColor(expectedColor); rippleContainer.setRadius(expectedRadius); - rippleContainer.is().radius(expectedRadius).and().color(is(expectedColor.toLowerCase())); + rippleContainer.is().radius(is(expectedRadius)).and().color(is(expectedColor.toLowerCase())); } - @Test + @Test(description = "Test checks ripple is centered has correct radius and value") public void rippleRadiusAndColorAndCenteredTest() { - refresh(); rippleContainer.center(); String expectedColor = "rgba(28, 140, 16, 0.1)"; int expectedRadius = 150; rippleContainer.setColor(expectedColor); rippleContainer.setRadius(expectedRadius); - rippleContainer.is().radius(expectedRadius).and().color(is(expectedColor.toLowerCase())).and().centered(); + rippleContainer.is().radius(is(expectedRadius)) + .and().color(is(expectedColor.toLowerCase())) + .and().centered(); } - @Test + @Test(description = "Test checks ripple center coordinates and radius value") public void mouseClickByCoordinatesAndRadiusTest() { - refresh(); int x = 0; int y = 299; int expectedRadius = 300; rippleContainer.setRadius(expectedRadius); rippleContainer.ripple(x, y); - rippleContainer.is().rippleCenter(x, y).and().radius(expectedRadius); + rippleContainer.is().rippleCenter(x, y).and().radius((is(expectedRadius))); } - @Test + @Test(description = "Test checks ripple is centered and unbounded") public void randomMouseClickCenteredAndUnboundedTest() { rippleContainer.unbound(); rippleContainer.center(); diff --git a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/unit/RippleUnitTests.java b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/unit/RippleUnitTests.java index e0a3529f640..2c5105ceea1 100644 --- a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/unit/RippleUnitTests.java +++ b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/unit/RippleUnitTests.java @@ -3,23 +3,20 @@ import io.github.epam.TestsInit; import org.apache.commons.lang3.RandomUtils; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Ignore; import org.testng.annotations.Test; import static com.epam.jdi.light.elements.composite.WebPage.refresh; -import static io.github.com.StaticSite.angularPage; -import static io.github.com.pages.AngularPage.rippleContainer; -import static io.github.epam.site.steps.States.shouldBeLoggedIn; +import static com.jdiai.tools.Timer.waitCondition; +import static io.github.com.StaticSite.ripplePage; +import static io.github.com.pages.RipplePage.*; import static org.testng.Assert.*; -// TODO Move to the new page -@Ignore public class RippleUnitTests extends TestsInit { - @BeforeMethod(alwaysRun = true) + @BeforeMethod public void before() { - shouldBeLoggedIn(); - angularPage.shouldBeOpened(); - rippleContainer.show(); + ripplePage.open(); + waitCondition(() -> ripplePage.isOpened()); + ripplePage.checkOpened(); } @Test @@ -27,88 +24,51 @@ public void displayedTest() { assertTrue(rippleContainer.isDisplayed()); } - @Test + @Test(description = "Unit test checks that ripple does not appear if 'disabled' option chosen") public void disabledTest() { rippleContainer.disable(); - assertTrue(rippleContainer.isDisabled()); + rippleContainer.ripple(); + assertTrue(rippleContainer.isNotActive()); rippleContainer.enable(); - assertTrue(rippleContainer.isEnabled()); + rippleContainer.ripple(); + assertTrue(rippleContainer.isActive()); } - @Test + @Test(description = "Unit test checks element's feature 'unbounded'") public void unboundedTest() { rippleContainer.unbound(); + rippleContainer.ripple(); assertTrue(rippleContainer.isUnbounded()); } - @Test + @Test(description = "Unit test checks element's feature 'centered'") public void centeredTest() { rippleContainer.center(); + rippleContainer.ripple(); assertTrue(rippleContainer.isCentered()); } - @Test + @Test(description = "Unit test checks that 'ripple' activates if element is clicked") public void rippleActionTest() { rippleContainer.ripple(); assertTrue(rippleContainer.isActive()); } - @Test - public void radiusTest() { - int expectedRadius = 200; - rippleContainer.setRadius(expectedRadius); - assertTrue(rippleContainer.isRadius(expectedRadius)); - } - - @Test + @Test(description = "Unit test checks that 'ripple effect' has correct value of radius") public void rippleRadiusTest() { int expectedRadius = 195; rippleContainer.setRadius(expectedRadius); assertEquals(rippleContainer.radius(), expectedRadius, "The radius has an incorrect value"); } - @Test - public void rippleCorrectRadiusTest() { - refresh(); - rippleContainer.setRadius(0); - assertTrue(rippleContainer.isCorrectRadius()); - } - - @Test - public void rippleNotCorrectRadiusTest() { - rippleContainer.setRadius(-1); - assertFalse(rippleContainer.isCorrectRadius()); - } - - @Test - public void colorTest() { - String expectedColor = "Green"; - rippleContainer.setColor(expectedColor); - assertTrue(rippleContainer.isColor(expectedColor.toLowerCase())); - } - - @Test - public void rippleCorrectColorTest() { - refresh(); - rippleContainer.setColor("rgba(0, 0, 0)"); - assertTrue(rippleContainer.isCorrectColor()); - } - - @Test - public void rippleNotCorrectColorTest() { - rippleContainer.setColor("custom color"); - assertFalse(rippleContainer.isCorrectColor()); - } - - @Test + @Test(description = "Unit test checks that 'ripple' element has correct value of color") public void rippleColorTest() { - refresh(); String expectedColor = "AqUaMaRiNe"; rippleContainer.setColor(expectedColor); assertEquals(rippleContainer.color(), expectedColor.toLowerCase(), "The color has an incorrect value"); } - @Test + @Test(description = "Unit test checks that 'ripple' element has correct value of color rgba") public void rippleRgbaColorTest() { refresh(); String expectedColor = "rgba(200, 100, 50, 0.5)"; @@ -116,7 +76,7 @@ public void rippleRgbaColorTest() { assertEquals(rippleContainer.color(), expectedColor, "The color has an incorrect value"); } - @Test + @Test(description = "Unit test checks that when 'centered' with any click in container 'ripple' is centered") public void mouseClickCenteredTest() { refresh(); rippleContainer.center(); @@ -126,7 +86,7 @@ public void mouseClickCenteredTest() { assertTrue(rippleContainer.isCentered()); } - @Test + @Test(description = "Unit test checks that when 'not-centered' - 'ripple' center is click coordinates") public void randomMouseClickTest() { refresh(); rippleContainer.show(); diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Ripple.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Ripple.java index cc11bb0b571..f2192e8d433 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Ripple.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Ripple.java @@ -5,6 +5,7 @@ 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.pageobjects.annotations.locators.UI; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.Point; @@ -23,33 +24,21 @@ public class Ripple extends UIBaseElement { public static final String LEFT_SPX_TOP_SPX = "left: %spx; top: %spx;"; public String containerLocator = "//*[@id='%s']"; public String rippleLocator = containerLocator.concat("/div"); - public String centeredCheckboxLocator = containerLocator - .concat("/preceding-sibling::mat-checkbox[@id='ripple-centered-checkbox']"); - public String disabledCheckboxLocator = containerLocator - .concat("/preceding-sibling::mat-checkbox[@id='ripple-disabled-checkbox']"); - public String unboundedCheckboxLocator = containerLocator - .concat("/preceding-sibling::mat-checkbox[@id='ripple-unbounded-checkbox']"); public String radiusLocator = containerLocator .concat("/preceding-sibling::mat-form-field[@id='ripple-radius-input']//input"); public String colorLocator = containerLocator .concat("/preceding-sibling::mat-form-field[@id='ripple-color-input']//input"); public String smartSharp = "smart: #"; public String cssSharp = "css='#"; - protected final Checkbox rippleCenteredCheckbox; - protected final Checkbox rippleDisabledCheckbox; - protected final Checkbox rippleUnboundedCheckbox; - - public Ripple() { - rippleCenteredCheckbox = new Checkbox(); - rippleDisabledCheckbox = new Checkbox(); - rippleUnboundedCheckbox = new Checkbox(); - } + @UI("#ripple-centered-checkbox-input") + public static Checkbox rippleCenteredCheckbox; + @UI("#ripple-disabled-checkbox-input") + public static Checkbox rippleDisabledCheckbox; + @UI("#ripple-unbounded-checkbox-input") + public static Checkbox rippleUnboundedCheckbox; - @Override - public boolean isDisplayed() { - return container().isDisplayed() && centeredCheckbox().isDisplayed() && disabledCheckbox().isDisplayed() - && unboundedCheckbox().isDisplayed() && getRadiusInput().isDisplayed() && getColorInput().isDisplayed(); - } + @UI("#ripple-container") + public static UIElement rippleElementContainer; @JDIAction("Ripple '{name}'") public void ripple() { @@ -116,18 +105,35 @@ public boolean isDisabled() { @JDIAction("Is '{name}' ripple unbounded") public boolean isUnbounded() { - return rippleUnboundedCheckbox.isSelected(); + return rippleElementContainer.hasClass("mat-ripple-unbounded"); } @JDIAction("Is '{name}' ripple centered") public boolean isCentered() { - return rippleCenteredCheckbox.isSelected(); + if (getRipple().isDisplayed()) { + String style = getRipple().attr(STYLE); + String left = "left: -"; + int xBeginIndex = style.lastIndexOf(left) + left.length(); + int xEndIndex = style.indexOf("px; top:"); + double actualX = Double.parseDouble(style.substring(xBeginIndex, xEndIndex)); + String top = "top: -"; + int yBeginIndex = style.lastIndexOf(top) + top.length(); + int yEndIndex = style.indexOf("px; height:"); + double actualY = Double.parseDouble(style.substring(yBeginIndex, yEndIndex)); + + return actualX - actualY == 0; + } + return false; } @JDIAction("Is '{name}' ripple active") public boolean isActive() { return getRipple().isDisplayed(); } + @JDIAction("Is '{name}' ripple not active") + public boolean isNotActive() { + return getRipple().isNotDisplayed(); + } /** * Check the center of the ripple is as indicated. @@ -202,11 +208,11 @@ public int radius() { try { result = Integer.parseInt(style.substring(beginIndex, endIndex)); } catch (NumberFormatException exception) { - return -1; + return -1;//как у нас в доме может появиться неправильный формат числа? } return result / 2; } else { - return -1; + throw new IllegalStateException("No radius value found"); } } @@ -257,24 +263,6 @@ protected UIElement getRipple() { .replace(smartSharp, "").replace(cssSharp, "").replace("'", "")))); } - protected UIElement centeredCheckbox() { - return new UIElement(By.xpath(format(centeredCheckboxLocator, - core().locator.printLocator().replace(smartSharp, "") - .replace(cssSharp, "").replace("'", "")))); - } - - protected UIElement disabledCheckbox() { - return new UIElement(By.xpath(format(disabledCheckboxLocator, - core().locator.printLocator().replace(smartSharp, "") - .replace(cssSharp, "").replace("'", "")))); - } - - protected UIElement unboundedCheckbox() { - return new UIElement(By.xpath(format(unboundedCheckboxLocator, - core().locator.printLocator().replace(smartSharp, "") - .replace(cssSharp, "").replace("'", "")))); - } - protected UIElement getRadiusInput() { return new UIElement(By.xpath(format(radiusLocator, core().locator.printLocator().replace(smartSharp, "")