Skip to content

Commit

Permalink
Merge pull request #5407 from jdi-testing/4838
Browse files Browse the repository at this point in the history
rework Angular element: Button
  • Loading branch information
spbqaru authored Mar 27, 2024
2 parents b35b3cb + 95a3a78 commit 2c0d24e
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.epam.angular.tests.elements.common;

import java.util.Random;

import com.epam.jdi.light.angular.elements.common.Button;
import com.epam.jdi.light.angular.elements.enums.AngularColors;
import io.github.epam.TestsInit;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.Random;

import static com.epam.jdi.light.angular.elements.enums.ButtonsTypes.BASIC;
import static com.epam.jdi.light.angular.elements.enums.ButtonsTypes.EXTENDED_FAB;
import static com.epam.jdi.light.angular.elements.enums.ButtonsTypes.FAB;
Expand All @@ -18,21 +18,18 @@
import static com.epam.jdi.light.angular.elements.enums.ButtonsTypes.STROKED;
import static com.jdiai.tools.Timer.waitCondition;
import static io.github.com.StaticSite.buttonsPage;

import static org.hamcrest.Matchers.containsString;
import static io.github.com.pages.ButtonsPage.accentColorButtons;
import static io.github.com.pages.ButtonsPage.basicButtons;
import static io.github.com.pages.ButtonsPage.basicbuttonLabel;
import static io.github.com.pages.ButtonsPage.defaultColorButton;
import static io.github.com.pages.ButtonsPage.extendedFabButtons;
import static io.github.com.pages.ButtonsPage.primaryColorButtons;
import static io.github.com.pages.ButtonsPage.accentColorButtons;
import static io.github.com.pages.ButtonsPage.warnColorButtons;
import static io.github.com.pages.ButtonsPage.fabButtons;
import static io.github.com.pages.ButtonsPage.flatButtons;
import static io.github.com.pages.ButtonsPage.iconButtons;
import static io.github.com.pages.ButtonsPage.miniFabButtons;
import static io.github.com.pages.ButtonsPage.primaryColorButtons;
import static io.github.com.pages.ButtonsPage.raisedButtons;
import static io.github.com.pages.ButtonsPage.strokedButtons;
import static io.github.com.pages.ButtonsPage.warnColorButtons;

public class ButtonsTests extends TestsInit {
Random rand = new Random();
Expand Down Expand Up @@ -147,6 +144,6 @@ public void colorButtonsTest() {
accentColorButtons.get(rand.nextInt(accentColorButtons.size()) + 1)
.has().color(AngularColors.ACCENT);
warnColorButtons.get(rand.nextInt(warnColorButtons.size()) + 1)
.has().color(AngularColors.WARN.getColor());
.has().color(AngularColors.WARN);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package io.github.epam.angular.tests.elements.common;

import com.epam.jdi.light.angular.elements.enums.AngularColors;
import io.github.epam.TestsInit;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static io.github.com.enums.CheckBoxAlignPosition.AFTER;
import static io.github.com.enums.CheckBoxAlignPosition.BEFORE;
import static com.epam.jdi.light.angular.elements.enums.CustomColors.BLACK_SEMI_TRANSPARENT;
import static com.epam.jdi.light.angular.elements.enums.CustomColors.PURPLE;
import static com.epam.jdi.light.angular.elements.enums.CustomColors.RED;
import static com.epam.jdi.light.angular.elements.enums.CustomColors.YELLOW;
import static com.jdiai.tools.Timer.waitCondition;

import static io.github.com.StaticSite.checkBoxPage;
import static io.github.com.enums.CheckBoxAlignPosition.AFTER;
import static io.github.com.enums.CheckBoxAlignPosition.BEFORE;
import static io.github.com.pages.CheckBoxPage.accentColorCheckbox;
import static io.github.com.pages.CheckBoxPage.basicCheckbox;
import static io.github.com.pages.CheckBoxPage.disabledCheckbox;
Expand Down Expand Up @@ -86,16 +88,16 @@ public void isRequiredCheckboxTest() {
public void angularColorCheckBoxTest() {
//Check color for checkboxes with attribute 'color'
primaryColorCheckbox.uncheck();
primaryColorCheckbox.has().color(AngularColors.UNSELECTED);
primaryColorCheckbox.has().color(BLACK_SEMI_TRANSPARENT.getColor());
primaryColorCheckbox.check();
primaryColorCheckbox.has().color(AngularColors.PRIMARY);
primaryColorCheckbox.has().color(PURPLE.getColor());
accentColorCheckbox.check();
accentColorCheckbox.has().color(AngularColors.ACCENT);
accentColorCheckbox.has().color(YELLOW.getColor());
warnColorCheckbox.check();
warnColorCheckbox.has().color(AngularColors.WARN);
warnColorCheckbox.has().color(RED.getColor());
//Check color for checkbox without attribute 'color'
requiredCheckbox.check();
requiredCheckbox.has().color(AngularColors.ACCENT);
requiredCheckbox.has().color(YELLOW.getColor());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static com.epam.jdi.light.angular.elements.enums.AngularColors.*;
import static com.epam.jdi.light.angular.elements.enums.CustomColors.BLACK_SEMI_TRANSPARENT;
import static com.epam.jdi.light.angular.elements.enums.CustomColors.PURPLE;
import static com.epam.jdi.light.angular.elements.enums.CustomColors.RED;
import static com.epam.jdi.light.angular.elements.enums.CustomColors.YELLOW;
import static com.jdiai.tools.Timer.waitCondition;
import static io.github.com.StaticSite.radioButtonPage;
import static io.github.com.pages.RadioButtonPage.*;
import static io.github.com.pages.RadioButtonPage.accentRadioButton;
import static io.github.com.pages.RadioButtonPage.basicRadioGroup;
import static io.github.com.pages.RadioButtonPage.beforePositionRadioGroup;
import static io.github.com.pages.RadioButtonPage.colorRadioGroup;
import static io.github.com.pages.RadioButtonPage.disabledRadioGroup;
import static io.github.com.pages.RadioButtonPage.elementPositionRadioGroup;
import static io.github.com.pages.RadioButtonPage.labelPositionRadioGroup;
import static io.github.com.pages.RadioButtonPage.primaryRadioButton;
import static io.github.com.pages.RadioButtonPage.requiredRadioGroup;
import static io.github.com.pages.RadioButtonPage.warnRadioButton;

public class RadioButtonTests extends TestsInit {
@BeforeClass
Expand Down Expand Up @@ -79,13 +91,12 @@ public void colorButtonsTest() {
colorRadioGroup.show();
colorRadioGroup.is().displayed();
primaryRadioButton.click();
primaryRadioButton.has().color(PRIMARY);
accentRadioButton.has().color(UNSELECTED);
primaryRadioButton.has().color(PURPLE.getColor());
accentRadioButton.has().color(BLACK_SEMI_TRANSPARENT.getColor());
warnRadioButton.click();
warnRadioButton.has().color(WARN);
primaryRadioButton.has().color(UNSELECTED);
warnRadioButton.has().color(RED.getColor());
primaryRadioButton.has().color(BLACK_SEMI_TRANSPARENT.getColor());
accentRadioButton.click();
accentRadioButton.has().color(ACCENT);
accentRadioButton.has().color(YELLOW.getColor());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.epam.jdi.light.angular.elements.interfaces.asserts.HasBadgeAssert;
import com.epam.jdi.light.asserts.generic.UIAssert;
import com.epam.jdi.light.common.JDIAction;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;

import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert;
Expand All @@ -22,7 +23,7 @@ public ButtonAssert text(String expectedText) {
public ButtonAssert focused() {
boolean actualFocused = element().focused();
jdiAssert(actualFocused, Matchers.is(true),
"Element is not focused");
"Element is not focused");
return this;
}

Expand All @@ -34,14 +35,14 @@ public ButtonAssert color(String expectedColor) {

@JDIAction(value = "Assert that '{name}' color is '{0}'", isAssert = true)
public ButtonAssert color(AngularColors expectedColor) {
jdiAssert(element().color(), Matchers.is(expectedColor.getColor()));
jdiAssert(element().color(), Matchers.is(expectedColor.getType()));
return this;
}

@JDIAction(value = "Assert that '{name}' has default color", isAssert = true)
public ButtonAssert defaultColor() {
jdiAssert(element().defaultColor(), Matchers.is(true),
"Element doesn't have default color.");
"Element doesn't have default color.");
return this;
}

Expand All @@ -55,7 +56,19 @@ public ButtonAssert visualType(ButtonsTypes expectedType) {
@JDIAction(value = "Assert that '{name}' has icon", isAssert = true)
public ButtonAssert hasIcon() {
jdiAssert(element().hasIcon(), Matchers.is(true),
"Element doesn't have icon inside");
"Element doesn't have icon inside");
return this;
}

@JDIAction(value = "Assert that '{name}' has link", isAssert = true)
public ButtonAssert hasLink() {
jdiAssert(element().hasLink(), Matchers.is(true), "Element doesn't have link inside");
return this;
}

@JDIAction("Assert that '{name}' ref {0}")
public ButtonAssert ref(Matcher<String> condition) {
jdiAssert(element().ref(), condition);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.epam.jdi.light.angular.asserts;

import com.epam.jdi.light.angular.elements.common.Checkbox;
import com.epam.jdi.light.angular.elements.enums.AngularColors;
import com.epam.jdi.light.asserts.generic.UIAssert;
import com.epam.jdi.light.common.JDIAction;
import org.hamcrest.Matchers;
Expand Down Expand Up @@ -71,12 +70,6 @@ public CheckboxAssert notRequired() {
return this;
}

@JDIAction(value = "Assert that '{name}' angular color is '{0}'", isAssert = true)
public CheckboxAssert color(AngularColors expectedColor) {
jdiAssert(element().color(), Matchers.is(expectedColor.getColor()));
return this;
}

@JDIAction(value = "Assert that '{name}' color is '{0}'", isAssert = true)
public CheckboxAssert color(String expectedColor) {
jdiAssert(element().color(), Matchers.is(expectedColor));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.epam.jdi.light.angular.asserts.radiobuttons;

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

import com.epam.jdi.light.angular.elements.complex.radiobuttons.RadioButton;
import com.epam.jdi.light.angular.elements.enums.AngularColors;
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;

public class RadioButtonAssert extends UIAssert<RadioButtonAssert, RadioButton> {

@Override
Expand All @@ -24,12 +23,6 @@ public RadioButtonAssert enabled() {
return this;
}

@JDIAction(value = "Assert that '{name}' color is '{0}'", isAssert = true)
public RadioButtonAssert color(AngularColors expectedColor) {
jdiAssert(AngularColors.fromColor(element().color()), Matchers.is(expectedColor));
return this;
}

@JDIAction(value = "Assert that '{name}' color is '{0}'", isAssert = true)
public RadioButtonAssert color(String expectedColor) {
jdiAssert(element().color(), Matchers.is(expectedColor));
Expand All @@ -38,15 +31,13 @@ public RadioButtonAssert color(String expectedColor) {

@JDIAction(value = "'{name}' element label is in before position", isAssert = true)
public RadioButtonAssert labelBeforePosition() {
jdiAssert(element().hasLabelBeforePosition(), Matchers.is(true),
"Radio button label is not in before position");
jdiAssert(element().hasLabelBeforePosition(), Matchers.is(true), "Radio button label is not in before position");
return this;
}

@JDIAction(value = "'{name}' element label is in before position", isAssert = true)
public RadioButtonAssert labelAfterPosition() {
jdiAssert(element().hasLabelBeforePosition(), Matchers.is(false),
"Radio button label is not in after position");
jdiAssert(element().hasLabelBeforePosition(), Matchers.is(false), "Radio button label is not in after position");
return this;
}

Expand All @@ -64,7 +55,8 @@ public RadioButtonAssert notChecked() {

@JDIAction(value = "'{name}' has label with value '{0}'", isAssert = true)
public RadioButtonAssert label(String value) {
jdiAssert(element().label().getValue(), Matchers.is(value));
jdiAssert(element().label()
.getValue(), Matchers.is(value));
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.epam.jdi.light.angular.elements.common;

import com.epam.jdi.light.angular.asserts.ButtonAssert;
import com.epam.jdi.light.angular.elements.enums.AngularColors;
import com.epam.jdi.light.angular.elements.enums.ButtonsTypes;
import com.epam.jdi.light.angular.elements.interfaces.HasBadge;
import com.epam.jdi.light.common.JDIAction;
import com.epam.jdi.light.elements.base.UIBaseElement;
import com.epam.jdi.light.elements.interfaces.base.HasClick;
import com.epam.jdi.light.elements.interfaces.base.HasColor;
import com.epam.jdi.light.elements.interfaces.base.HasLink;
import com.epam.jdi.light.elements.interfaces.common.IsText;
import com.jdiai.tools.map.MapArray;

public class Button extends UIBaseElement<ButtonAssert> implements HasBadge, HasClick, IsText {
public class Button extends UIBaseElement<ButtonAssert> implements HasBadge, HasClick, IsText, HasLink, HasColor {

private static final String ICON_LOCATOR = ".//mat-icon";
private static final String LABEL_LOCATOR = ".mdc-button__label";
Expand All @@ -20,10 +21,11 @@ public boolean focused() {
return core().hasClass("cdk-focused");
}

@Override
@JDIAction("Get '{name}' color")
public String color() {
if (core().hasAttribute("color")) {
return AngularColors.fromName(core().attr("color")).getColor();
return core().attr("color");
}
return core().getCssValue("background-color");
}
Expand Down Expand Up @@ -52,7 +54,7 @@ public ButtonsTypes visualType() {

@JDIAction("Get if there is icon inside the button")
public boolean hasIcon() {
return !core().finds(ICON_LOCATOR).isEmpty();
return core().finds(ICON_LOCATOR).isExist();
}

@JDIAction("Get icon inside the button")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.epam.jdi.light.angular.elements.complex;

import com.epam.jdi.light.angular.asserts.BottomSheetAssert;
import com.epam.jdi.light.angular.elements.common.Button;
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.ui.html.elements.common.Button;
import org.openqa.selenium.By;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.epam.jdi.light.angular.elements.complex;

import com.epam.jdi.light.angular.asserts.DialogAssert;
import com.epam.jdi.light.angular.elements.common.Button;
import com.epam.jdi.light.elements.base.UIBaseElement;
import com.epam.jdi.light.elements.common.UIElement;
import com.epam.jdi.light.ui.html.elements.common.Button;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.epam.jdi.light.angular.elements.complex;

import com.epam.jdi.light.angular.asserts.NestedDropdownMenuAssert;
import com.epam.jdi.light.angular.elements.common.Button;
import com.epam.jdi.light.common.ElementArea;
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.ui.html.elements.common.Button;
import org.openqa.selenium.By;

import java.util.ArrayList;
Expand Down
Loading

0 comments on commit 2c0d24e

Please sign in to comment.