Skip to content

Commit 2b4178e

Browse files
author
Konstantin Bulavin
committed
Amended in accordance with the comments
1 parent a74c6e4 commit 2b4178e

File tree

10 files changed

+63
-135
lines changed

10 files changed

+63
-135
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.github.com.custom.elements;
2+
3+
import com.epam.jdi.light.angular.elements.complex.AutoComplete;
4+
import com.epam.jdi.light.angular.elements.complex.ChipGroup;
5+
import com.epam.jdi.light.common.JDIAction;
6+
7+
public class ChipGroupWithAutocomlete extends ChipGroup {
8+
9+
@JDIAction("Get '{name}' input field")
10+
public AutoComplete inputField() {
11+
return new AutoComplete().setCore(AutoComplete.class, find("input"));
12+
}
13+
}

jdi-light-angular-tests/src/main/java/io/github/com/pages/ChipsPage.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.epam.jdi.light.angular.elements.complex.ChipGroup;
44
import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI;
55
import com.epam.jdi.light.ui.html.elements.common.Text;
6+
import io.github.com.custom.elements.ChipGroupWithAutocomlete;
67

78
public class ChipsPage extends NewAngularPage {
89

@@ -13,10 +14,10 @@ public class ChipsPage extends NewAngularPage {
1314
public static ChipGroup stackedChips;
1415

1516
@UI("#chips-autocomplete-field")
16-
public static ChipGroup autocompleteChips;
17+
public static ChipGroupWithAutocomlete autocompleteChips;
1718

1819
@UI("#chips-with-input-field")
19-
public static ChipGroup inputChips;
20+
public static ChipGroupWithAutocomlete inputChips;
2021

2122
@UI("#chips-with-form-control")
2223
public static ChipGroup formControlChips;
@@ -43,7 +44,7 @@ public class ChipsPage extends NewAngularPage {
4344
public static ChipGroup multipleChips;
4445

4546
@UI("#chips-with-error-state")
46-
public static ChipGroup errorChips;
47+
public static ChipGroupWithAutocomlete errorChips;
4748

4849
@UI("#basic-chips-label")
4950
public static Text basicSelectedValue;

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

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,16 @@
2424

2525
public class ChipsTests extends TestsInit {
2626

27-
private static final String ONEFISH = "One fish";
2827
private static final String TWOFISH = "Two fish";
29-
private static final String PRIMARYFISH = "Primary fish";
3028
private static final String WARNFISH = "Warn fish";
3129

32-
private static final String NONE = "none";
33-
private static final String PRIMARY = "Primary";
34-
private static final String ACCENT = "Accent";
35-
private static final String WARN = "Warn";
36-
37-
private static final String PLACEHOLDER = "New fruit...";
3830
private static final String APPLE = "Apple";
3931
private static final String LEMON = "Lemon";
4032
private static final String LIME = "Lime";
33+
private static final String KIWI = "Kiwi";
34+
private static final String ROCKMELON = "Rockmelon";
35+
private static final String MELON = "Melon";
36+
4137

4238
@BeforeClass
4339
public void before() {
@@ -78,10 +74,8 @@ public void chipsColorTest() {
7874
.and().highlighted();
7975
highlightedChips.getElement("Highlighted color Accent").is().color(AngularColors.ACCENT)
8076
.and().highlighted();
81-
;
8277
highlightedChips.getElement("Highlighted color Warn").is().color(AngularColors.WARN)
8378
.and().highlighted();
84-
;
8579
}
8680

8781
@Test(description = "Test verifies that chips isn't highlighted")
@@ -95,41 +89,39 @@ public void chipsNotHighlightedTest() {
9589
@Test(description = "Test checks the operation of the autocomplete in chips group")
9690
public void chipsAutocompleteTest() {
9791
String[] expectedValuesArray = {
98-
"Apple", "Lemon", "Lime", "Orange", "Strawberry"};
92+
APPLE, LEMON, LIME, "Orange", "Strawberry"};
9993
List<String> expectedValues = Arrays.asList(expectedValuesArray);
10094

10195
autocompleteChips.show();
10296
autocompleteChips.is().displayed();
103-
autocompleteChips.has().placeholder("New Fruit...");
104-
autocompleteChips.has().options(expectedValues);
97+
autocompleteChips.inputField().has().placeholder("New Fruit...");
98+
autocompleteChips.inputField().has().options(expectedValues);
10599

106-
autocompleteChips.select(LEMON);
107-
autocompleteChips.collapseField();
100+
autocompleteChips.inputField().select(LEMON);
108101
autocompleteChips.is().hasElement(LEMON);
109-
autocompleteChips.select(APPLE);
110-
autocompleteChips.collapseField();
102+
autocompleteChips.inputField().select(APPLE);
111103
autocompleteChips.is().hasElement(APPLE);
112104
}
113105

114106
@Test(description = "Test checks the input field in chips group")
115107
public void chipsWithInputTest() {
116108
inputChips.show();
117109
inputChips.is().displayed();
118-
inputChips.has().placeholder(PLACEHOLDER);
119-
inputChips.input("Kiwi" + "\n");
120-
inputChips.input("Melon");
121-
inputChips.clearInputField();
122-
inputChips.input("Rockmelon" + "\n");
123-
inputChips.is().hasElement("Kiwi");
124-
inputChips.is().hasElement("Rockmelon");
110+
inputChips.inputField().has().placeholder("New fruit...");
111+
inputChips.inputField().input(KIWI + "\n");
112+
inputChips.inputField().input(MELON);
113+
inputChips.inputField().clear();
114+
inputChips.inputField().input(ROCKMELON + "\n");
115+
inputChips.is().hasElement(KIWI);
116+
inputChips.is().hasElement(ROCKMELON);
125117
}
126118

127119
@Test(description = "Test checks that chips can be removed")
128120
public void chipsRemovableTest() {
129121
inputChips.show();
130122
inputChips.is().displayed();
131-
inputChips.getElement("Lemon").is().removable();
132-
inputChips.getElement("Lemon").close();
123+
inputChips.getElement(LEMON).is().removable();
124+
inputChips.getElement(LEMON).close();
133125
}
134126

135127
@Test(description = "Test checks that chips can't be removed")
@@ -143,18 +135,17 @@ public void chipsNotRemovableTest() {
143135
public void chipFocusedTest() {
144136
inputChips.show();
145137
inputChips.is().displayed();
146-
inputChips.getElement("Apple").click();
147-
inputChips.getElement("Apple").is().focused();
148-
inputChips.getElement("Lime").click();
149-
inputChips.getElement("Lime").is().focused();
150-
inputChips.getElement("Apple").is().notFocused();
138+
inputChips.getElement(APPLE).click();
139+
inputChips.getElement(APPLE).is().focused();
140+
inputChips.getElement(LIME).click();
141+
inputChips.getElement(LIME).is().focused();
142+
inputChips.getElement(APPLE).is().notFocused();
151143
}
152144

153145
@Test(description = "Test checks that chips has avatar image")
154146
public void chipAvatarTest() {
155-
String expectedSrc = "https://material.angular.io/assets/img/examples/shiba1.jpg";
156147
avatarChips.show();
157-
avatarChips.getElement("Dog one").leadingIcon().is().src(expectedSrc);
148+
avatarChips.getElement("Dog one").has().image();
158149
}
159150

160151
@Test(description = "Test checks that chips can be disabled")
@@ -190,7 +181,7 @@ public void chipsNotMultipleSelectionTest() {
190181
public void chipsErrorState() {
191182
errorChips.show();
192183
errorChips.is().displayed();
193-
errorChips.input("Kiwi" + "\n");
184+
errorChips.inputField().input(KIWI + "\n");
194185
errorChips.has().errorState();
195186
}
196187
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,10 @@ public ChipAssert notFocused() {
6262
jdiAssert(element().focused(), Matchers.is(false));
6363
return this;
6464
}
65+
66+
@JDIAction("Assert that '{name}' has avatar image")
67+
public ChipAssert image() {
68+
jdiAssert(element().hasImage(), Matchers.is(true));
69+
return this;
70+
}
6571
}

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import com.epam.jdi.light.common.JDIAction;
66
import org.hamcrest.Matchers;
77

8-
import java.util.List;
9-
108
import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert;
119

1210
public class ChipGroupAssert extends UIAssert<ChipGroupAssert, ChipGroup> {
@@ -37,18 +35,6 @@ public ChipGroupAssert notVertical() {
3735
return this;
3836
}
3937

40-
@JDIAction("Assert that '{name}' has placeholder '{0}'")
41-
public ChipGroupAssert placeholder(String expected) {
42-
jdiAssert(element().getPlaceholderForChips(), Matchers.is(expected));
43-
return this;
44-
}
45-
46-
@JDIAction("Assert that '{name}' has options")
47-
public ChipGroupAssert options(List<String> options) {
48-
jdiAssert(element().options(), Matchers.is(options));
49-
return this;
50-
}
51-
5238
@JDIAction("Assert that '{name}' has multiple select options")
5339
public ChipGroupAssert multiselectable() {
5440
jdiAssert(element().multiselectable(), Matchers.is("true"));

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
import com.epam.jdi.light.angular.elements.interfaces.HasImage;
77
import com.epam.jdi.light.common.JDIAction;
88
import com.epam.jdi.light.elements.base.UIBaseElement;
9+
import com.epam.jdi.light.elements.common.Label;
910
import com.epam.jdi.light.elements.interfaces.base.HasClick;
10-
import com.epam.jdi.light.ui.html.elements.common.Image;
11+
import com.epam.jdi.light.elements.interfaces.base.HasLabel;
1112

12-
public class Chip extends UIBaseElement<ChipAssert> implements HasClick, HasColor, HasIcon, HasImage {
13+
public class Chip extends UIBaseElement<ChipAssert> implements HasClick, HasColor, HasIcon, HasImage, HasLabel {
1314

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

@@ -43,14 +44,15 @@ public boolean highlighted() {
4344
return hasClass("mat-mdc-chip-highlighted");
4445
}
4546

46-
@JDIAction("Get '{name}' label text")
47-
public String getText() {
48-
return find(".mdc-evolution-chip__text-label").getText();
47+
@Override
48+
public Label label() {
49+
return new Label().setCore(Label.class, find(".mdc-evolution-chip__text-label"));
4950
}
5051

51-
@JDIAction("Get '{name}' avatar image")
52-
public Image leadingIcon() {
53-
return new Image().setCore(Image.class, find("[matchipavatar]"));
52+
@Override
53+
@JDIAction("Get '{name}' label text")
54+
public String labelText() {
55+
return label().getText();
5456
}
5557

5658
@Override

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public void clear() {
5959
@JDIAction("Select value {0} for '{name}'")
6060
public void select(String value) {
6161
if (value == null) return;
62+
core().click();
6263
WebList options = getOptions(optionsCss);
6364
options.get(value).click();
6465
}

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

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,14 @@
66
import com.epam.jdi.light.angular.elements.interfaces.IsGroupElement;
77
import com.epam.jdi.light.common.JDIAction;
88
import com.epam.jdi.light.elements.base.UIBaseElement;
9-
import com.epam.jdi.light.elements.common.UIElement;
10-
import com.epam.jdi.light.elements.complex.WebList;
119
import com.epam.jdi.light.elements.interfaces.base.ICoreElement;
12-
import org.openqa.selenium.By;
13-
import org.openqa.selenium.Keys;
14-
import org.openqa.selenium.Point;
1510

16-
import java.util.ArrayList;
1711
import java.util.List;
1812
import java.util.stream.Collectors;
1913

2014
public class ChipGroup extends UIBaseElement<ChipGroupAssert> implements IsGroupElement<Chip>, HasOrientation {
2115

2216
public static final String CHIP_LOCATOR = ".mat-mdc-chip";
23-
private final String matOptions = "mat-option";
2417

2518
@Override
2619
@JDIAction("Get list of '{name}' items")
@@ -35,15 +28,15 @@ public List<Chip> groupElements() {
3528
@JDIAction("Get {0} element from '{name}'")
3629
public Chip getElement(String value) {
3730
return groupElements().stream()
38-
.filter(element -> element.getText().equals(value))
31+
.filter(element -> element.labelText().equals(value))
3932
.findFirst()
4033
.get();
4134
}
4235

4336
@JDIAction("Get if {0} element exist in '{name}'")
4437
public boolean hasElement(String value) {
4538
return groupElements().stream()
46-
.anyMatch(chip -> chip.getText().equals(value));
39+
.anyMatch(chip -> chip.labelText().equals(value));
4740
}
4841

4942
@Override
@@ -76,47 +69,6 @@ public void deselectByText(String text) {
7669
}
7770
}
7871

79-
@JDIAction("Get '{name}' input field")
80-
public UIElement inputField() {
81-
return find("input");
82-
}
83-
84-
@JDIAction("'{name}' input field input '{0}' value")
85-
public void input(String value) {
86-
inputField().input(value);
87-
}
88-
89-
@JDIAction("Clear value from '{name}' input field")
90-
public void clearInputField() {
91-
inputField().sendKeys(Keys.CONTROL + "a");
92-
inputField().sendKeys(Keys.DELETE);
93-
}
94-
95-
@JDIAction("Select value '{0}' for '{name}' autocomplete")
96-
public void select(String value) {
97-
if (value == null) return;
98-
inputField().click();
99-
WebList options = getOptions(this.matOptions);
100-
options.get(value).click();
101-
}
102-
103-
@JDIAction("Get placeholder for '{name}' input field")
104-
public String getPlaceholderForChips() {
105-
String placeholder = "placeholder";
106-
return inputField().hasAttribute(placeholder) ? inputField().getAttribute(placeholder) : "";
107-
}
108-
109-
@JDIAction("Collapse '{name}' chips autocomplete field")
110-
public void collapseField() {
111-
core().click(getPointOutsideField().getX(), getPointOutsideField().getY());
112-
}
113-
114-
@JDIAction("Get options for '{name}' autocomplete field")
115-
public List<String> options() {
116-
getItems();
117-
return getValues();
118-
}
119-
12072
@Override
12173
@JDIAction("Get if '{name}' is vertical")
12274
public boolean isVertical() {
@@ -137,27 +89,4 @@ public boolean errorState() {
13789
public ChipGroupAssert is() {
13890
return new ChipGroupAssert().set(this);
13991
}
140-
141-
protected Point getPointOutsideField() {
142-
return new Point(core().getRect().
143-
getWidth() + 3, core().getRect().getHeight() + 3);
144-
}
145-
146-
private WebList getOptions(String css) {
147-
return new WebList(By.cssSelector(css));
148-
}
149-
150-
private WebList getItems() {
151-
inputField().click();
152-
WebList options = getOptions(matOptions);
153-
inputField().click();
154-
return options;
155-
}
156-
157-
private List<String> getValues() {
158-
List<String> values = new ArrayList<>();
159-
WebList options = getOptions(this.matOptions);
160-
options.forEach(option -> values.add(option.getValue()));
161-
return values;
162-
}
16392
}

jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/interfaces/HasIcon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ default Icon icon() {
2828
*/
2929
@JDIAction("Get if '{name}' has icon")
3030
default boolean hasIcon() {
31-
return core().finds(ICON_LOCATOR).isNotEmpty();
31+
return icon().isExist() & icon().isVisible();
3232
}
3333
}

jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/interfaces/HasImage.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ default Image image() {
2626
*/
2727
@JDIAction("Check that '{name}' image is displayed")
2828
default boolean hasImage() {
29-
return core().find("img").isDisplayed()
30-
|| core().find("//*[contains(@style, 'background-image')]").isDisplayed();
29+
return image().isExist() & image().isVisible();
3130
}
3231
}

0 commit comments

Comments
 (0)