From e3e77f3964681ef83a53c95319976f739bb79009 Mon Sep 17 00:00:00 2001 From: evgen460 Date: Fri, 26 Jan 2024 11:37:00 +0300 Subject: [PATCH] 4935_Test-refactoring-element-Sidenav3 --- .../java/io/github/com/pages/SideNavPage.java | 13 ++++++----- .../tests/elements/complex/SideNavTests.java | 20 +++++++---------- .../light/angular/asserts/SideNaveAssert.java | 21 ++++++++++++++++++ .../angular/elements/complex/SideNav.java | 22 +++++++++++++++++-- 4 files changed, 56 insertions(+), 20 deletions(-) create mode 100644 jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/SideNaveAssert.java diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/SideNavPage.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/SideNavPage.java index 6db100a956c..d16348eab60 100644 --- a/jdi-light-angular-tests/src/main/java/io/github/com/pages/SideNavPage.java +++ b/jdi-light-angular-tests/src/main/java/io/github/com/pages/SideNavPage.java @@ -1,11 +1,12 @@ package io.github.com.pages; +import com.epam.jdi.light.angular.elements.common.Button; import com.epam.jdi.light.angular.elements.common.Checkbox; import com.epam.jdi.light.angular.elements.complex.SideNav; import com.epam.jdi.light.angular.elements.complex.radiobuttons.RadioGroup; -import com.epam.jdi.light.elements.common.UIElement; +import com.epam.jdi.light.angular.elements.composite.MaterialSelectorContainer; import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI; -import com.epam.jdi.light.ui.html.elements.common.Button; +import com.epam.jdi.light.ui.html.elements.common.TextField; import io.github.com.pages.sections.SideNavSection; public class SideNavPage extends NewAngularPage { @@ -33,10 +34,10 @@ public class SideNavPage extends NewAngularPage { @UI("#configurable-mode .mat-sidenav .mat-mdc-radio-group") public static RadioGroup sideNavRadioGroup; @UI("#mat-select-position") - public static UIElement sideNavPosition; + public static MaterialSelectorContainer sideNavPosition; @UI("#mat-select-focus-on-the-first-item") - public static UIElement sideNavFocusSelection; + public static MaterialSelectorContainer sideNavFocusSelection; @UI("#configurable-mode .mat-sidenav-content .mat-mdc-radio-group") public static RadioGroup contentRadioGroup; @@ -66,10 +67,10 @@ public class SideNavPage extends NewAngularPage { public static Button toggleFixedSideNav; @UI("#fixed-position .mat-sidenav-content mat-form-field input[formcontrolname='top']") - public static UIElement topGap; + public static TextField topGap; @UI("#fixed-position .mat-sidenav-content mat-form-field input[formcontrolname='bottom']") - public static UIElement bottomGap; + public static TextField bottomGap; public static SideNavSection sidenavBackdropDrawer; diff --git a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/SideNavTests.java b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/SideNavTests.java index 8b7eac2f0a1..bea7971ac71 100644 --- a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/SideNavTests.java +++ b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/SideNavTests.java @@ -1,9 +1,8 @@ package io.github.epam.angular.tests.elements.complex; -import com.epam.jdi.light.angular.elements.composite.MaterialSelectorContainer; import com.epam.jdi.light.elements.common.UIElement; import io.github.epam.TestsInit; -import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import static com.epam.jdi.light.elements.composite.WebPage.refresh; @@ -19,7 +18,6 @@ import static io.github.com.pages.SideNavPage.contentRadioGroup; import static io.github.com.pages.SideNavPage.contentToggle; import static io.github.com.pages.SideNavPage.customEscapeBackdrop; -import static io.github.com.pages.SideNavPage.firstElement; import static io.github.com.pages.SideNavPage.firstElementFocused; import static io.github.com.pages.SideNavPage.fixSideNav; import static io.github.com.pages.SideNavPage.fixedPosition; @@ -55,7 +53,7 @@ public class SideNavTests extends TestsInit { public static final String MODE = "mode"; public static final String SIDE = "side"; - @BeforeMethod(alwaysRun = true) + @BeforeClass(alwaysRun = true) public void before() { sideNavPage.open(); waitCondition(() -> sideNavPage.isOpened()); @@ -87,11 +85,11 @@ public void verifyPositionSelectionDrawerWithExplicitBackdropSettingSideNavTest( sidenavBackdropContainer.is().enabled(); sideNavPosition.click(); - (new MaterialSelectorContainer()).select("End"); + sideNavPosition.select("End"); backDropToggle.click(); sidenavBackdropDrawer.is().displayed(); - sidenavBackdropDrawer.has().cssClass("mat-drawer-end"); + sidenavBackdropContainer.has().sideNavSectionOnTheRight(sidenavBackdropDrawer.getLocation()); } @Test(description = "Test verifies first menu item focus when 'true' is selected") @@ -101,13 +99,13 @@ public void verifyFocusSelectionDrawerWithExplicitBackdropSettingSideNavTest() { sidenavBackdropContainer.is().enabled(); sideNavFocusSelection.click(); - (new MaterialSelectorContainer()).select("True"); + sideNavFocusSelection.select("True"); backDropToggle.click(); firstElementFocused.base().timer().wait(() -> firstElementFocused.has().cssClass("cdk-program-focused")); - firstElementFocused.has().cssClass("cdk-focused"); firstElementFocused.is().displayed(); + firstElementFocused.is().focused(); } @Test(description = "Verify main content is properly displayed alongside two side navigation panels") @@ -213,12 +211,10 @@ public void verifyAutoSizeSideNav() { public void fixedSideNavTest() { String testValue = "100"; fixedPosition.show(); - topGap.click(); topGap.clear(); - topGap.sendKeys(testValue); - bottomGap.click(); + topGap.setValue(testValue); bottomGap.clear(); - bottomGap.sendKeys(testValue); + bottomGap.setValue(testValue); fixSideNav.click(); fixedPosition.getSideNav().has().attr(STYLE, "transform: none; visibility: visible; top: 100px; bottom: " + "100px;"); diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/SideNaveAssert.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/SideNaveAssert.java new file mode 100644 index 00000000000..8a4a16a48f4 --- /dev/null +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/SideNaveAssert.java @@ -0,0 +1,21 @@ +package com.epam.jdi.light.angular.asserts; + +import com.epam.jdi.light.angular.elements.complex.SideNav; +import com.epam.jdi.light.asserts.generic.UIAssert; +import com.epam.jdi.light.common.JDIAction; +import org.hamcrest.Matchers; +import org.openqa.selenium.Point; + +import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert; + +public class SideNaveAssert extends UIAssert { + + private static final String LOCATION_ERROR_MESSAGE = "SideNavSection with location %s isn't on the right side"; + + @JDIAction(value = "Assert that '{name}' has section with location '{0}' on the right side", isAssert = true) + public SideNaveAssert sideNavSectionOnTheRight(Point locationOfSection) { + jdiAssert(element().isSectionInRightPart(locationOfSection), Matchers.is(true), + String.format(LOCATION_ERROR_MESSAGE, locationOfSection)); + return this; + } +} diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/SideNav.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/SideNav.java index 65664fe3eed..a131ffc69bf 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/SideNav.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/SideNav.java @@ -1,16 +1,28 @@ package com.epam.jdi.light.angular.elements.complex; -import com.epam.jdi.light.asserts.generic.UIAssert; +import com.epam.jdi.light.angular.asserts.SideNaveAssert; 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.complex.WebList; +import com.epam.jdi.light.elements.interfaces.base.HasLabel; +import org.openqa.selenium.Point; /** * To see an example of Checkbox web element please visit https://material.angular.io/components/sidenav/overview. */ -public class SideNav extends UIBaseElement> { +public class SideNav extends UIBaseElement implements HasLabel { + + @Override + public SideNaveAssert is() { + return new SideNaveAssert().set(this); + } + + @Override + public SideNaveAssert has() { + return is(); + } @JDIAction("Get '{name}' side nav") public UIElement getSideNav() { @@ -64,4 +76,10 @@ public UIElement getMatDrawer() { public UIElement getMatDrawerContent() { return this.find(".mat-drawer-content"); } + + @JDIAction("Is '{name}' side nav has section with location '{0}' on right side") + public boolean isSectionInRightPart(Point locationOfSection) { + int containerCenterX = this.getLocation().getX() + this.getSize().getWidth() / 2; + return locationOfSection.getX() >= containerCenterX; + } }