Skip to content

Commit 5358d58

Browse files
authored
feat(java): ✨ added element list and dom property support (#940)
1 parent b5f15b0 commit 5358d58

File tree

11 files changed

+498
-442
lines changed

11 files changed

+498
-442
lines changed

core-java/src/main/java/io/github/boykaframework/actions/elements/ElementActions.java

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@
2121
import static io.github.boykaframework.actions.CommonActions.pause;
2222
import static io.github.boykaframework.actions.CommonActions.performElementAction;
2323
import static io.github.boykaframework.actions.drivers.DriverActions.withDriver;
24+
import static io.github.boykaframework.actions.elements.ElementFinder.finds;
2425
import static io.github.boykaframework.enums.ListenerType.ELEMENT_ACTION;
26+
import static io.github.boykaframework.enums.WaitStrategy.VISIBLE;
2527
import static io.github.boykaframework.manager.ParallelSession.getSession;
2628
import static java.util.Optional.ofNullable;
2729
import static org.apache.commons.lang3.StringUtils.EMPTY;
2830
import static org.apache.logging.log4j.LogManager.getLogger;
2931

32+
import java.util.List;
33+
3034
import com.google.common.truth.BooleanSubject;
35+
import com.google.common.truth.IterableSubject;
3136
import com.google.common.truth.StringSubject;
37+
import com.google.common.truth.Truth;
3238
import io.github.boykaframework.actions.interfaces.elements.IElementActions;
3339
import io.github.boykaframework.actions.interfaces.listeners.elements.IElementActionsListener;
3440
import io.github.boykaframework.builders.Locator;
@@ -92,6 +98,14 @@ public String getAttribute (final String attribute) {
9298
return LOGGER.traceExit (getAttributeValue (attribute));
9399
}
94100

101+
@Override
102+
public String getProperty (final String property) {
103+
LOGGER.traceEntry ();
104+
LOGGER.info ("Getting Property: {} of element located by: {}", property, this.locator.getName ());
105+
ofNullable (this.listener).ifPresent (l -> l.onGetProperty (property));
106+
return LOGGER.traceExit (getPropertyValue (property));
107+
}
108+
95109
@Override
96110
public String getStyle (final String styleName) {
97111
LOGGER.traceEntry ();
@@ -133,6 +147,13 @@ public boolean isSelected () {
133147
return LOGGER.traceExit (getElementAttribute (WebElement::isSelected, this.locator, false));
134148
}
135149

150+
@Override
151+
public List<String> itemList () {
152+
LOGGER.info ("Getting the list of elements: {}", this.locator.getName ());
153+
ofNullable (this.listener).ifPresent (IElementActionsListener::onItemList);
154+
return getElementList ();
155+
}
156+
136157
@Override
137158
public void scrollIntoView () {
138159
LOGGER.info ("Scrolling element located by [{}] into view", this.locator.getName ());
@@ -181,6 +202,23 @@ public BooleanSubject verifyIsSelected () {
181202
return assertWithMessage ("Selected").that (isSelected ());
182203
}
183204

205+
@Override
206+
public IterableSubject verifyItems () {
207+
LOGGER.info ("Verifying the list of elements: {}", this.locator.getName ());
208+
ofNullable (this.listener).ifPresent (IElementActionsListener::onVerifyItems);
209+
return Truth.assertWithMessage (this.locator.getName ())
210+
.that (getElementList ());
211+
}
212+
213+
@Override
214+
public StringSubject verifyProperty (final String property) {
215+
LOGGER.traceEntry ();
216+
LOGGER.info ("Verifying property of {}", this.locator.getName ());
217+
ofNullable (this.listener).ifPresent (l -> l.onVerifyProperty (property));
218+
LOGGER.traceExit ();
219+
return assertWithMessage (property).that (getProperty (property));
220+
}
221+
184222
@Override
185223
public StringSubject verifyStyle (final String styleName) {
186224
LOGGER.traceEntry ();
@@ -207,10 +245,23 @@ public StringSubject verifyText () {
207245
* @return Attribute value
208246
*/
209247
protected String getAttributeValue (final String attribute) {
210-
return getElementAttribute (e -> e.getAttribute (attribute), this.locator, EMPTY);
248+
return getElementAttribute (e -> e.getDomAttribute (attribute), this.locator, EMPTY);
211249
}
212250

213251
private boolean displayed () {
214252
return getElementAttribute (WebElement::isDisplayed, this.locator, false);
215253
}
254+
255+
private List<String> getElementList () {
256+
return getElementAttribute (element -> {
257+
final var items = finds (this.locator, VISIBLE);
258+
return items.stream ()
259+
.map (WebElement::getText)
260+
.toList ();
261+
}, this.locator, List.of ());
262+
}
263+
264+
private String getPropertyValue (final String property) {
265+
return getElementAttribute (e -> e.getDomProperty (property), this.locator, EMPTY);
266+
}
216267
}

core-java/src/main/java/io/github/boykaframework/actions/elements/TextBoxActions.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static io.github.boykaframework.manager.ParallelSession.getSession;
2626
import static java.util.Optional.ofNullable;
2727
import static org.apache.commons.lang3.StringUtils.EMPTY;
28+
import static org.apache.commons.lang3.StringUtils.isEmpty;
2829
import static org.apache.logging.log4j.LogManager.getLogger;
2930

3031
import com.google.common.truth.StringSubject;
@@ -108,12 +109,14 @@ private String getInputAttribute () {
108109

109110
private void sendKeys (final String text) {
110111
performElementAction (e -> {
111-
e.sendKeys (text);
112-
if (getSession ().getPlatformType () == IOS && getSession ().getMobileSetting ()
113-
.getDevice ()
114-
.getApplication ()
115-
.getType () != ApplicationType.WEB) {
116-
e.sendKeys ("\n");
112+
if (!isEmpty (text)) {
113+
e.sendKeys (text);
114+
if (getSession ().getPlatformType () == IOS && getSession ().getMobileSetting ()
115+
.getDevice ()
116+
.getApplication ()
117+
.getType () != ApplicationType.WEB) {
118+
e.sendKeys ("\n");
119+
}
117120
}
118121
}, this.locator);
119122
}

core-java/src/main/java/io/github/boykaframework/actions/interfaces/elements/IElementActions.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
package io.github.boykaframework.actions.interfaces.elements;
1818

19+
import java.util.List;
20+
1921
import com.google.common.truth.BooleanSubject;
22+
import com.google.common.truth.IterableSubject;
2023
import com.google.common.truth.StringSubject;
2124

2225
/**
@@ -40,6 +43,15 @@ public interface IElementActions {
4043
*/
4144
String getAttribute (final String attribute);
4245

46+
/**
47+
* Get Dom property value.
48+
*
49+
* @param property DOM property
50+
*
51+
* @return Property value
52+
*/
53+
String getProperty (String property);
54+
4355
/**
4456
* Gets the styling attribute of the element.
4557
*
@@ -77,6 +89,13 @@ public interface IElementActions {
7789
*/
7890
boolean isSelected ();
7991

92+
/**
93+
* Gets all the list of items identified by the provided locator.
94+
*
95+
* @return List of elements text
96+
*/
97+
List<String> itemList ();
98+
8099
/**
81100
* Scroll the element into view.
82101
*/
@@ -112,6 +131,22 @@ public interface IElementActions {
112131
*/
113132
BooleanSubject verifyIsSelected ();
114133

134+
/**
135+
* Verify the list of elements text.
136+
*
137+
* @return Iterable subject to verify the list of elements.
138+
*/
139+
IterableSubject verifyItems ();
140+
141+
/**
142+
* Verify DOM property.
143+
*
144+
* @param property DOM property.
145+
*
146+
* @return StringSubject to verify the value.
147+
*/
148+
StringSubject verifyProperty (final String property);
149+
115150
/**
116151
* Verify style of element.
117152
*

core-java/src/main/java/io/github/boykaframework/actions/interfaces/listeners/elements/IElementActionsListener.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ default void onGetAttribute (final Locator locator, final String attribute) {
4545
// not implemented.
4646
}
4747

48+
/**
49+
* Handles getProperty method.
50+
*
51+
* @param property property name
52+
*/
53+
default void onGetProperty (final String property) {
54+
// not implemented.
55+
}
56+
4857
/**
4958
* Handle get style method.
5059
*
@@ -91,6 +100,13 @@ default void onIsSelected (final Locator locator) {
91100
// not implemented.
92101
}
93102

103+
/**
104+
* Handles itemList method.
105+
*/
106+
default void onItemList () {
107+
// not implemented.
108+
}
109+
94110
/**
95111
* Handle scroll into view method.
96112
*
@@ -137,6 +153,22 @@ default void onVerifyIsSelected (final Locator locator) {
137153
// not implemented.
138154
}
139155

156+
/**
157+
* Handles verifyItems method.
158+
*/
159+
default void onVerifyItems () {
160+
// not implemented.
161+
}
162+
163+
/**
164+
* Handles verifyProperty value.
165+
*
166+
* @param property Property name
167+
*/
168+
default void onVerifyProperty (final String property) {
169+
// not implemented.
170+
}
171+
140172
/**
141173
* Handle verify style method.
142174
*

core-java/src/test/java/io/github/boykaframework/testng/ui/theinternet/DropDownTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
package io.github.boykaframework.testng.ui.theinternet;
1818

1919
import static io.github.boykaframework.actions.drivers.NavigateActions.navigate;
20+
import static io.github.boykaframework.actions.elements.ClickableActions.withMouse;
2021
import static io.github.boykaframework.actions.elements.DropDownActions.onDropDown;
22+
import static io.github.boykaframework.actions.elements.ElementActions.onElement;
2123
import static io.github.boykaframework.manager.ParallelSession.clearSession;
2224
import static io.github.boykaframework.manager.ParallelSession.createSession;
2325
import static io.github.boykaframework.testng.ui.theinternet.pages.DropDownPage.dropDownPage;
2426
import static org.apache.commons.lang3.StringUtils.EMPTY;
2527

28+
import java.util.List;
29+
2630
import io.github.boykaframework.enums.PlatformType;
2731
import org.testng.annotations.AfterClass;
2832
import org.testng.annotations.BeforeClass;
@@ -112,6 +116,18 @@ public void testDeselectByValue () {
112116
.isEqualTo (EMPTY);
113117
}
114118

119+
@Test (description = "Verify the list of fruits")
120+
public void testFruitList () {
121+
withMouse (dropDownPage ().getFruits ()).click ();
122+
final var expected = onElement (dropDownPage ().getFruitList ()).itemList ();
123+
onElement (dropDownPage ().getFruitList ()).verifyItems ()
124+
.isNotEmpty ();
125+
onElement (dropDownPage ().getFruitList ()).verifyItems ()
126+
.containsExactlyElementsIn (expected);
127+
onElement (dropDownPage ().getFruitList ()).verifyItems ()
128+
.containsAtLeastElementsIn (List.of ("Apple", "Mango", "Banana"));
129+
}
130+
115131
/**
116132
* Test multiple select.
117133
*/

core-java/src/test/java/io/github/boykaframework/testng/ui/theinternet/pages/DropDownPage.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.github.boykaframework.testng.ui.theinternet.pages;
1818

1919
import static org.openqa.selenium.By.id;
20+
import static org.openqa.selenium.By.tagName;
2021

2122
import io.github.boykaframework.builders.Locator;
2223
import lombok.Getter;
@@ -44,6 +45,11 @@ public static DropDownPage dropDownPage () {
4445
.web (id ("fruits"))
4546
.name ("Fruits")
4647
.build ();
48+
private final Locator fruitList = Locator.buildLocator ()
49+
.name ("Fruit List")
50+
.web (tagName ("option"))
51+
.parent (this.fruits)
52+
.build ();
4753
private final Locator superHeroes = Locator.buildLocator ()
4854
.web (id ("superheros"))
4955
.name ("Super Heroes")

core-java/test-suites/testng-web-grid.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
<class name="io.github.boykaframework.testng.ui.theinternet.ContextMenuTest"/>
3131
<class name="io.github.boykaframework.testng.ui.theinternet.DoubleClickTest"/>
3232
<class name="io.github.boykaframework.testng.ui.theinternet.DragDropTest"/>
33-
<class name="io.github.boykaframework.testng.ui.theinternet.DropDownTest"/>
3433
<class name="io.github.boykaframework.testng.ui.theinternet.FileUploadTest"/>
3534
<class name="io.github.boykaframework.testng.ui.theinternet.FramesTest"/>
3635
<class name="io.github.boykaframework.testng.ui.theinternet.HoverTest"/>

core-java/test-suites/testng-web-local.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<parameter name="platformType" value="WEB"/>
2525
<parameter name="driverKey" value="test_local_chrome"/>
2626
<packages>
27+
<package name="io.github.boykaframework.testng.ui.theinternet"/>
2728
<package name="io.github.boykaframework.testng.ui.ecomm"/>
2829
<package name="io.github.boykaframework.testng.ui.jiomeet"/>
2930
</packages>

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
"@eslint/compat": "^1.2.4",
3636
"@lerna/child-process": "^7.4.2",
3737
"@release-it-plugins/lerna-changelog": "^7.0.0",
38-
"@stylistic/eslint-plugin-js": "^2.11.0",
39-
"@stylistic/eslint-plugin-ts": "^2.11.0",
40-
"@types/node": "^22.10.1",
41-
"@typescript-eslint/eslint-plugin": "^8.17.0",
42-
"@typescript-eslint/parser": "^8.17.0",
38+
"@stylistic/eslint-plugin-js": "^2.12.1",
39+
"@stylistic/eslint-plugin-ts": "^2.12.1",
40+
"@types/node": "^22.10.2",
41+
"@typescript-eslint/eslint-plugin": "^8.18.0",
42+
"@typescript-eslint/parser": "^8.18.0",
4343
"commitlint": "^19.6.0",
4444
"eslint": "^9.16.0",
4545
"eslint-config-google": "^0.14.0",
@@ -54,16 +54,16 @@
5454
"lerna": "8.1.9",
5555
"lerna-changelog": "^2.2.0",
5656
"lerna-version": "^6.6.2",
57-
"lint-staged": "^15.2.10",
57+
"lint-staged": "^15.2.11",
5858
"lodash": "^4.17.21",
59-
"nx": "^20.2.1",
59+
"nx": "^20.2.2",
6060
"prettier": "^3.4.2",
6161
"react": "^19.0.0",
6262
"react-dom": "^19.0.0",
6363
"release-it": "^17.10.0",
6464
"ts-node": "^10.9.2",
6565
"typescript": "^5.7.2",
66-
"typescript-eslint": "^8.17.0"
66+
"typescript-eslint": "^8.18.0"
6767
},
6868
"scripts": {
6969
"preinstall": "npx only-allow pnpm",
@@ -99,5 +99,5 @@
9999
"pnpm format"
100100
]
101101
},
102-
"packageManager": "pnpm@9.11.0"
102+
"packageManager": "pnpm@9.15.0"
103103
}

0 commit comments

Comments
 (0)