Skip to content

Commit

Permalink
feat(java): ✨ added element list and dom property support (#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
WasiqB authored Dec 12, 2024
1 parent b5f15b0 commit 5358d58
Show file tree
Hide file tree
Showing 11 changed files with 498 additions and 442 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@
import static io.github.boykaframework.actions.CommonActions.pause;
import static io.github.boykaframework.actions.CommonActions.performElementAction;
import static io.github.boykaframework.actions.drivers.DriverActions.withDriver;
import static io.github.boykaframework.actions.elements.ElementFinder.finds;
import static io.github.boykaframework.enums.ListenerType.ELEMENT_ACTION;
import static io.github.boykaframework.enums.WaitStrategy.VISIBLE;
import static io.github.boykaframework.manager.ParallelSession.getSession;
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.apache.logging.log4j.LogManager.getLogger;

import java.util.List;

import com.google.common.truth.BooleanSubject;
import com.google.common.truth.IterableSubject;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Truth;
import io.github.boykaframework.actions.interfaces.elements.IElementActions;
import io.github.boykaframework.actions.interfaces.listeners.elements.IElementActionsListener;
import io.github.boykaframework.builders.Locator;
Expand Down Expand Up @@ -92,6 +98,14 @@ public String getAttribute (final String attribute) {
return LOGGER.traceExit (getAttributeValue (attribute));
}

@Override
public String getProperty (final String property) {
LOGGER.traceEntry ();
LOGGER.info ("Getting Property: {} of element located by: {}", property, this.locator.getName ());
ofNullable (this.listener).ifPresent (l -> l.onGetProperty (property));
return LOGGER.traceExit (getPropertyValue (property));
}

@Override
public String getStyle (final String styleName) {
LOGGER.traceEntry ();
Expand Down Expand Up @@ -133,6 +147,13 @@ public boolean isSelected () {
return LOGGER.traceExit (getElementAttribute (WebElement::isSelected, this.locator, false));
}

@Override
public List<String> itemList () {
LOGGER.info ("Getting the list of elements: {}", this.locator.getName ());
ofNullable (this.listener).ifPresent (IElementActionsListener::onItemList);
return getElementList ();
}

@Override
public void scrollIntoView () {
LOGGER.info ("Scrolling element located by [{}] into view", this.locator.getName ());
Expand Down Expand Up @@ -181,6 +202,23 @@ public BooleanSubject verifyIsSelected () {
return assertWithMessage ("Selected").that (isSelected ());
}

@Override
public IterableSubject verifyItems () {
LOGGER.info ("Verifying the list of elements: {}", this.locator.getName ());
ofNullable (this.listener).ifPresent (IElementActionsListener::onVerifyItems);
return Truth.assertWithMessage (this.locator.getName ())
.that (getElementList ());
}

@Override
public StringSubject verifyProperty (final String property) {
LOGGER.traceEntry ();
LOGGER.info ("Verifying property of {}", this.locator.getName ());
ofNullable (this.listener).ifPresent (l -> l.onVerifyProperty (property));
LOGGER.traceExit ();
return assertWithMessage (property).that (getProperty (property));
}

@Override
public StringSubject verifyStyle (final String styleName) {
LOGGER.traceEntry ();
Expand All @@ -207,10 +245,23 @@ public StringSubject verifyText () {
* @return Attribute value
*/
protected String getAttributeValue (final String attribute) {
return getElementAttribute (e -> e.getAttribute (attribute), this.locator, EMPTY);
return getElementAttribute (e -> e.getDomAttribute (attribute), this.locator, EMPTY);
}

private boolean displayed () {
return getElementAttribute (WebElement::isDisplayed, this.locator, false);
}

private List<String> getElementList () {
return getElementAttribute (element -> {
final var items = finds (this.locator, VISIBLE);
return items.stream ()
.map (WebElement::getText)
.toList ();
}, this.locator, List.of ());
}

private String getPropertyValue (final String property) {
return getElementAttribute (e -> e.getDomProperty (property), this.locator, EMPTY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static io.github.boykaframework.manager.ParallelSession.getSession;
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.apache.logging.log4j.LogManager.getLogger;

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

private void sendKeys (final String text) {
performElementAction (e -> {
e.sendKeys (text);
if (getSession ().getPlatformType () == IOS && getSession ().getMobileSetting ()
.getDevice ()
.getApplication ()
.getType () != ApplicationType.WEB) {
e.sendKeys ("\n");
if (!isEmpty (text)) {
e.sendKeys (text);
if (getSession ().getPlatformType () == IOS && getSession ().getMobileSetting ()
.getDevice ()
.getApplication ()
.getType () != ApplicationType.WEB) {
e.sendKeys ("\n");
}
}
}, this.locator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

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

import java.util.List;

import com.google.common.truth.BooleanSubject;
import com.google.common.truth.IterableSubject;
import com.google.common.truth.StringSubject;

/**
Expand All @@ -40,6 +43,15 @@ public interface IElementActions {
*/
String getAttribute (final String attribute);

/**
* Get Dom property value.
*
* @param property DOM property
*
* @return Property value
*/
String getProperty (String property);

/**
* Gets the styling attribute of the element.
*
Expand Down Expand Up @@ -77,6 +89,13 @@ public interface IElementActions {
*/
boolean isSelected ();

/**
* Gets all the list of items identified by the provided locator.
*
* @return List of elements text
*/
List<String> itemList ();

/**
* Scroll the element into view.
*/
Expand Down Expand Up @@ -112,6 +131,22 @@ public interface IElementActions {
*/
BooleanSubject verifyIsSelected ();

/**
* Verify the list of elements text.
*
* @return Iterable subject to verify the list of elements.
*/
IterableSubject verifyItems ();

/**
* Verify DOM property.
*
* @param property DOM property.
*
* @return StringSubject to verify the value.
*/
StringSubject verifyProperty (final String property);

/**
* Verify style of element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ default void onGetAttribute (final Locator locator, final String attribute) {
// not implemented.
}

/**
* Handles getProperty method.
*
* @param property property name
*/
default void onGetProperty (final String property) {
// not implemented.
}

/**
* Handle get style method.
*
Expand Down Expand Up @@ -91,6 +100,13 @@ default void onIsSelected (final Locator locator) {
// not implemented.
}

/**
* Handles itemList method.
*/
default void onItemList () {
// not implemented.
}

/**
* Handle scroll into view method.
*
Expand Down Expand Up @@ -137,6 +153,22 @@ default void onVerifyIsSelected (final Locator locator) {
// not implemented.
}

/**
* Handles verifyItems method.
*/
default void onVerifyItems () {
// not implemented.
}

/**
* Handles verifyProperty value.
*
* @param property Property name
*/
default void onVerifyProperty (final String property) {
// not implemented.
}

/**
* Handle verify style method.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
package io.github.boykaframework.testng.ui.theinternet;

import static io.github.boykaframework.actions.drivers.NavigateActions.navigate;
import static io.github.boykaframework.actions.elements.ClickableActions.withMouse;
import static io.github.boykaframework.actions.elements.DropDownActions.onDropDown;
import static io.github.boykaframework.actions.elements.ElementActions.onElement;
import static io.github.boykaframework.manager.ParallelSession.clearSession;
import static io.github.boykaframework.manager.ParallelSession.createSession;
import static io.github.boykaframework.testng.ui.theinternet.pages.DropDownPage.dropDownPage;
import static org.apache.commons.lang3.StringUtils.EMPTY;

import java.util.List;

import io.github.boykaframework.enums.PlatformType;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
Expand Down Expand Up @@ -112,6 +116,18 @@ public void testDeselectByValue () {
.isEqualTo (EMPTY);
}

@Test (description = "Verify the list of fruits")
public void testFruitList () {
withMouse (dropDownPage ().getFruits ()).click ();
final var expected = onElement (dropDownPage ().getFruitList ()).itemList ();
onElement (dropDownPage ().getFruitList ()).verifyItems ()
.isNotEmpty ();
onElement (dropDownPage ().getFruitList ()).verifyItems ()
.containsExactlyElementsIn (expected);
onElement (dropDownPage ().getFruitList ()).verifyItems ()
.containsAtLeastElementsIn (List.of ("Apple", "Mango", "Banana"));
}

/**
* Test multiple select.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.github.boykaframework.testng.ui.theinternet.pages;

import static org.openqa.selenium.By.id;
import static org.openqa.selenium.By.tagName;

import io.github.boykaframework.builders.Locator;
import lombok.Getter;
Expand Down Expand Up @@ -44,6 +45,11 @@ public static DropDownPage dropDownPage () {
.web (id ("fruits"))
.name ("Fruits")
.build ();
private final Locator fruitList = Locator.buildLocator ()
.name ("Fruit List")
.web (tagName ("option"))
.parent (this.fruits)
.build ();
private final Locator superHeroes = Locator.buildLocator ()
.web (id ("superheros"))
.name ("Super Heroes")
Expand Down
1 change: 0 additions & 1 deletion core-java/test-suites/testng-web-grid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<class name="io.github.boykaframework.testng.ui.theinternet.ContextMenuTest"/>
<class name="io.github.boykaframework.testng.ui.theinternet.DoubleClickTest"/>
<class name="io.github.boykaframework.testng.ui.theinternet.DragDropTest"/>
<class name="io.github.boykaframework.testng.ui.theinternet.DropDownTest"/>
<class name="io.github.boykaframework.testng.ui.theinternet.FileUploadTest"/>
<class name="io.github.boykaframework.testng.ui.theinternet.FramesTest"/>
<class name="io.github.boykaframework.testng.ui.theinternet.HoverTest"/>
Expand Down
1 change: 1 addition & 0 deletions core-java/test-suites/testng-web-local.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<parameter name="platformType" value="WEB"/>
<parameter name="driverKey" value="test_local_chrome"/>
<packages>
<package name="io.github.boykaframework.testng.ui.theinternet"/>
<package name="io.github.boykaframework.testng.ui.ecomm"/>
<package name="io.github.boykaframework.testng.ui.jiomeet"/>
</packages>
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"@eslint/compat": "^1.2.4",
"@lerna/child-process": "^7.4.2",
"@release-it-plugins/lerna-changelog": "^7.0.0",
"@stylistic/eslint-plugin-js": "^2.11.0",
"@stylistic/eslint-plugin-ts": "^2.11.0",
"@types/node": "^22.10.1",
"@typescript-eslint/eslint-plugin": "^8.17.0",
"@typescript-eslint/parser": "^8.17.0",
"@stylistic/eslint-plugin-js": "^2.12.1",
"@stylistic/eslint-plugin-ts": "^2.12.1",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"commitlint": "^19.6.0",
"eslint": "^9.16.0",
"eslint-config-google": "^0.14.0",
Expand All @@ -54,16 +54,16 @@
"lerna": "8.1.9",
"lerna-changelog": "^2.2.0",
"lerna-version": "^6.6.2",
"lint-staged": "^15.2.10",
"lint-staged": "^15.2.11",
"lodash": "^4.17.21",
"nx": "^20.2.1",
"nx": "^20.2.2",
"prettier": "^3.4.2",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"release-it": "^17.10.0",
"ts-node": "^10.9.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.17.0"
"typescript-eslint": "^8.18.0"
},
"scripts": {
"preinstall": "npx only-allow pnpm",
Expand Down Expand Up @@ -99,5 +99,5 @@
"pnpm format"
]
},
"packageManager": "pnpm@9.11.0"
"packageManager": "pnpm@9.15.0"
}
Loading

0 comments on commit 5358d58

Please sign in to comment.