Skip to content

Commit aad3991

Browse files
author
Konstantin Bulavin
committed
Added corrections according to comments
1 parent 9a846af commit aad3991

File tree

5 files changed

+128
-48
lines changed

5 files changed

+128
-48
lines changed

jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/ChipsTests.java

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.epam.jdi.light.angular.elements.enums.AngularColors;
44
import io.github.com.pages.ChipsPage;
55
import io.github.epam.TestsInit;
6-
import org.testng.annotations.BeforeMethod;
6+
import org.testng.annotations.BeforeClass;
77
import org.testng.annotations.Test;
88

99
import java.util.Arrays;
@@ -17,10 +17,10 @@
1717
import static io.github.com.pages.ChipsPage.basicChips;
1818
import static io.github.com.pages.ChipsPage.disabledChips;
1919
import static io.github.com.pages.ChipsPage.errorChips;
20+
import static io.github.com.pages.ChipsPage.highlightedChips;
2021
import static io.github.com.pages.ChipsPage.inputChips;
2122
import static io.github.com.pages.ChipsPage.multipleChips;
2223
import static io.github.com.pages.ChipsPage.stackedChips;
23-
import static io.github.com.pages.ChipsPage.stackedSelectedValue;
2424

2525
public class ChipsTests extends TestsInit {
2626

@@ -39,7 +39,7 @@ public class ChipsTests extends TestsInit {
3939
private static final String LEMON = "Lemon";
4040
private static final String LIME = "Lime";
4141

42-
@BeforeMethod
42+
@BeforeClass
4343
public void before() {
4444
chipsPage.open();
4545
waitCondition(() -> chipsPage.isOpened());
@@ -49,34 +49,47 @@ public void before() {
4949
@Test(description = "Test verifies that chip group is selectable")
5050
public void basicChipsTest() {
5151
basicChips.show();
52-
basicChips.is().displayed();
52+
basicChips.is().displayed().and().enabled();
5353
basicChips.selectByText(TWOFISH);
54-
basicChips.selectByText(PRIMARYFISH);
54+
basicChips.getElement(TWOFISH).is().selected();
5555
basicChips.selectByText(WARNFISH);
56+
basicChips.getElement(WARNFISH).is().selected();
5657

5758
ChipsPage.basicSelectedValue.has().text(format("You clicked: %s", WARNFISH));
5859
}
5960

6061
@Test(description = "Test verifies that chip group is vertical")
6162
public void stackedChipsTest() {
6263
stackedChips.show();
63-
stackedChips.is().displayed();
64-
stackedChips.is().vertical();
65-
stackedChips.selectByText(NONE);
66-
stackedChips.selectByText(PRIMARY);
67-
stackedChips.selectByText(ACCENT);
68-
stackedChips.selectByText(WARN);
64+
stackedChips.is().displayed().and().vertical();
65+
}
6966

70-
stackedSelectedValue.has().text(format("You clicked: %s", WARN));
67+
@Test(description = "Test verifies that chip group is not vertical")
68+
public void horizontalChipsTest() {
69+
basicChips.show();
70+
basicChips.is().displayed().and().notVertical();
7171
}
7272

7373
@Test(description = "Test check chips colors")
7474
public void chipsColorTest() {
75-
stackedChips.show();
76-
stackedChips.is().displayed();
77-
stackedChips.getElement(PRIMARY).is().color(AngularColors.MAT_PRIMARY);
78-
stackedChips.getElement(ACCENT).is().color(AngularColors.MAT_ACCENT);
79-
stackedChips.getElement(WARN).is().color(AngularColors.MAT_WARN);
75+
highlightedChips.show();
76+
highlightedChips.is().displayed();
77+
highlightedChips.getElement("Highlighted color Primary").is().color(AngularColors.PRIMARY)
78+
.and().highlighted();
79+
highlightedChips.getElement("Highlighted color Accent").is().color(AngularColors.ACCENT)
80+
.and().highlighted();
81+
;
82+
highlightedChips.getElement("Highlighted color Warn").is().color(AngularColors.WARN)
83+
.and().highlighted();
84+
;
85+
}
86+
87+
@Test(description = "Test verifies that chips isn't highlighted")
88+
public void chipsNotHighlightedTest() {
89+
basicChips.show();
90+
basicChips.is().displayed().and().enabled();
91+
basicChips.getElement(TWOFISH).is().notHighlighted();
92+
basicChips.getElement(WARNFISH).is().notHighlighted();
8093
}
8194

8295
@Test(description = "Test checks the operation of the autocomplete in chips group")
@@ -119,6 +132,13 @@ public void chipsRemovableTest() {
119132
inputChips.getElement("Lemon").close();
120133
}
121134

135+
@Test(description = "Test checks that chips can't be removed")
136+
public void chipsNotRemovableTest() {
137+
basicChips.show();
138+
basicChips.is().displayed();
139+
basicChips.getElement(WARNFISH).is().notRemovable();
140+
}
141+
122142
@Test(description = "Test checks that chips can be focused")
123143
public void chipFocusedTest() {
124144
inputChips.show();
@@ -127,6 +147,7 @@ public void chipFocusedTest() {
127147
inputChips.getElement("Apple").is().focused();
128148
inputChips.getElement("Lime").click();
129149
inputChips.getElement("Lime").is().focused();
150+
inputChips.getElement("Apple").is().notFocused();
130151
}
131152

132153
@Test(description = "Test checks that chips has avatar image")
@@ -139,8 +160,7 @@ public void chipAvatarTest() {
139160
@Test(description = "Test checks that chips can be disabled")
140161
public void chipDisabledTest() {
141162
disabledChips.show();
142-
disabledChips.is().displayed();
143-
disabledChips.is().disabled();
163+
disabledChips.is().displayed().and().disabled();
144164
}
145165

146166
@Test(description = "Test checks chips multiply selection")
@@ -154,11 +174,23 @@ public void chipsMultipleSelectionTest() {
154174
multipleChips.getElement("multiple color Primary").is().selected();
155175
}
156176

177+
@Test(description = "Test checks chips isn't multiply selection")
178+
public void chipsNotMultipleSelectionTest() {
179+
basicChips.show();
180+
basicChips.is().displayed();
181+
basicChips.is().notMultiselectable();
182+
basicChips.selectByText(TWOFISH);
183+
basicChips.selectByText(WARNFISH);
184+
basicChips.getElement(TWOFISH).is().deselected();
185+
basicChips.getElement(WARNFISH).is().selected();
186+
187+
}
188+
157189
@Test(description = "Test checks that chips has error state")
158190
public void chipsErrorState() {
159191
errorChips.show();
160192
errorChips.is().displayed();
161193
errorChips.input("Kiwi" + "\n");
162194
errorChips.has().errorState();
163195
}
164-
}
196+
}

jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/ChipAssert.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,50 @@ public ChipAssert selected() {
1616
return this;
1717
}
1818

19+
@JDIAction("Assert that '{name}' is enabled")
20+
public ChipAssert deselected() {
21+
jdiAssert(element().selected(), Matchers.is(false));
22+
return this;
23+
}
24+
1925
@JDIAction("Assert that '{name}' is removable ")
2026
public ChipAssert removable() {
2127
jdiAssert(element().removable(), Matchers.is(true));
2228
return this;
2329
}
2430

31+
@JDIAction("Assert that '{name}' is removable ")
32+
public ChipAssert notRemovable() {
33+
jdiAssert(element().removable(), Matchers.is(false));
34+
return this;
35+
}
36+
2537
@JDIAction("Assert that '{name}' has '{0}' color")
2638
public ChipAssert color(AngularColors color) {
27-
return cssClass(color.getColor());
39+
return cssClass(color.getStyle());
2840
}
2941

3042
@JDIAction("Assert that '{name}' is focused ")
3143
public ChipAssert focused() {
3244
jdiAssert(element().focused(), Matchers.is(true));
3345
return this;
3446
}
47+
48+
@JDIAction("Assert that '{name}' is highlighted ")
49+
public ChipAssert highlighted() {
50+
jdiAssert(element().highlighted(), Matchers.is(true));
51+
return this;
52+
}
53+
54+
@JDIAction("Assert that '{name}' isn't highlighted ")
55+
public ChipAssert notHighlighted() {
56+
jdiAssert(element().highlighted(), Matchers.is(false));
57+
return this;
58+
}
59+
60+
@JDIAction("Assert that '{name}' isn't focused ")
61+
public ChipAssert notFocused() {
62+
jdiAssert(element().focused(), Matchers.is(false));
63+
return this;
64+
}
3565
}

jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/ChipGroupAssert.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public ChipGroupAssert vertical() {
3131
return this;
3232
}
3333

34+
@JDIAction("Assert that '{name}' aria-orientation is not vertical")
35+
public ChipGroupAssert notVertical() {
36+
jdiAssert(element().isVertical(), Matchers.is(false));
37+
return this;
38+
}
39+
3440
@JDIAction("Assert that '{name}' has placeholder '{0}'")
3541
public ChipGroupAssert placeholder(String expected) {
3642
jdiAssert(element().getPlaceholderForChips(), Matchers.is(expected));
@@ -49,6 +55,12 @@ public ChipGroupAssert multiselectable() {
4955
return this;
5056
}
5157

58+
@JDIAction("Assert that '{name}' has multiple select options")
59+
public ChipGroupAssert notMultiselectable() {
60+
jdiAssert(element().multiselectable(), Matchers.is("false"));
61+
return this;
62+
}
63+
5264
@JDIAction("Assert that '{name}' has '{0}' element")
5365
public ChipGroupAssert hasElement(String expected) {
5466
jdiAssert(element().hasElement(expected), Matchers.is(true));

jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/common/Chip.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
public class Chip extends UIBaseElement<ChipAssert> implements HasClick, HasColor, HasIcon, HasImage {
1313

14+
public static final String MAT_CHIP_REMOVE = "[matChipRemove]";
1415

1516
@JDIAction("Get if '{name} is selected'")
1617
public boolean selected() {
@@ -19,35 +20,35 @@ public boolean selected() {
1920

2021
@JDIAction("Close '{name}'")
2122
public void close() {
22-
find("[matChipRemove]").click();
23+
find(MAT_CHIP_REMOVE).click();
2324
}
2425

2526
@JDIAction("Get if '{name}' is removable")
2627
public boolean removable() {
27-
return find("[matChipRemove]").isDisplayed();
28+
return find(MAT_CHIP_REMOVE).isDisplayed();
2829
}
2930

30-
@JDIAction("Get if '{name}' background-color")
31-
public String getBackgroundColor() {
32-
return css("background-color");
33-
}
34-
35-
@JDIAction("Get if '{name} is focused'")
31+
@JDIAction("Get if '{name}' is focused")
3632
public boolean focused() {
3733
return hasClass("cdk-focused");
3834
}
3935

40-
@JDIAction("Get if '{name} checkmark is visible'")
41-
public boolean showCheckMark() {
36+
@JDIAction("Get if '{name}' checkmark is visible")
37+
public boolean hasCheckMark() {
4238
return find("mdc-evolution-chip__checkmark").isVisible();
4339
}
4440

45-
@JDIAction("Get '{name} label text")
41+
@JDIAction("Get if '{name}' is highlighted")
42+
public boolean highlighted() {
43+
return hasClass("mat-mdc-chip-highlighted");
44+
}
45+
46+
@JDIAction("Get '{name}' label text")
4647
public String getText() {
4748
return find(".mdc-evolution-chip__text-label").getText();
4849
}
4950

50-
@JDIAction("Get '{name} avatar image")
51+
@JDIAction("Get '{name}' avatar image")
5152
public Image leadingIcon() {
5253
return new Image().setCore(Image.class, find("[matchipavatar]"));
5354
}

jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/ChipGroup.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
public class ChipGroup extends UIBaseElement<ChipGroupAssert> implements IsGroupElement<Chip>, HasOrientation {
2121

22+
public static final String CHIP_LOCATOR = ".mat-mdc-chip";
2223
private final String matOptions = "mat-option";
23-
public String backdropField = "#chips-autocomplete-field";
2424

2525
@Override
2626
@JDIAction("Get list of '{name}' items")
2727
public List<Chip> groupElements() {
28-
core().timer().wait(() -> core().finds(".mat-mdc-chip").isDisplayed());
29-
return core().finds(".mat-mdc-chip").stream()
28+
core().timer().wait(() -> core().finds(CHIP_LOCATOR).isDisplayed());
29+
return core().finds(CHIP_LOCATOR).stream()
3030
.map(listItem -> new Chip().setCore(Chip.class, listItem))
3131
.collect(Collectors.toList());
3232
}
@@ -62,7 +62,18 @@ public boolean isEnabled() {
6262

6363
@JDIAction("Select chip element in '{name}' by '{0}'")
6464
public void selectByText(String text) {
65-
getElement(text).click();
65+
Chip chip = getElement(text);
66+
if (!chip.selected()){
67+
chip.click();
68+
}
69+
}
70+
71+
@JDIAction("Deselect chip element in '{name}' by '{0}'")
72+
public void deselectByText(String text) {
73+
Chip chip = getElement(text);
74+
if (chip.selected()){
75+
chip.click();
76+
}
6677
}
6778

6879
@JDIAction("Get '{name}' input field")
@@ -97,8 +108,7 @@ public String getPlaceholderForChips() {
97108

98109
@JDIAction("Collapse '{name}' chips autocomplete field")
99110
public void collapseField() {
100-
getBackdropField().core()
101-
.click(getPointOutsideField().getX(), getPointOutsideField().getY());
111+
core().click(getPointOutsideField().getX(), getPointOutsideField().getY());
102112
}
103113

104114
@JDIAction("Get options for '{name}' autocomplete field")
@@ -113,12 +123,12 @@ public boolean isVertical() {
113123
return core().attr("class").contains("mat-chip-list-stacked");
114124
}
115125

116-
@JDIAction("Get if '{namr}' has multiple selection")
126+
@JDIAction("Get if '{name}' has multiple selection")
117127
public String multiselectable() {
118128
return attr("aria-multiselectable");
119129
}
120130

121-
@JDIAction("Get if '{namr}' has error state")
131+
@JDIAction("Get if '{name}' has error state")
122132
public boolean errorState() {
123133
return core().hasClass("mat-form-field-invalid");
124134
}
@@ -128,14 +138,9 @@ public ChipGroupAssert is() {
128138
return new ChipGroupAssert().set(this);
129139
}
130140

131-
protected UIElement getBackdropField() {
132-
return new UIElement(By.cssSelector(backdropField));
133-
}
134-
135141
protected Point getPointOutsideField() {
136-
UIElement uiElement = getBackdropField();
137-
return new Point(uiElement.core().getRect().
138-
getWidth() + 3, uiElement.core().getRect().getHeight() + 3);
142+
return new Point(core().getRect().
143+
getWidth() + 3, core().getRect().getHeight() + 3);
139144
}
140145

141146
private WebList getOptions(String css) {

0 commit comments

Comments
 (0)