Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static io.github.boykaframework.manager.ParallelSession.getSession;
import static io.github.boykaframework.utils.ErrorHandler.handleAndThrow;
import static io.github.boykaframework.utils.ErrorHandler.throwError;
import static java.text.MessageFormat.format;
import static java.util.Objects.isNull;
import static java.util.Objects.requireNonNull;
import static org.apache.logging.log4j.LogManager.getLogger;
Expand All @@ -31,7 +30,6 @@

import io.github.boykaframework.builders.Locator;
import io.github.boykaframework.enums.WaitStrategy;
import io.github.boykaframework.exception.FrameworkError;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
Expand Down Expand Up @@ -60,14 +58,17 @@ public static WebElement find (final Locator locator, final WaitStrategy waitStr
if (elements.isEmpty ()) {
throwError (ELEMENT_NOT_FOUND, locator.getName (), getSession ().getPlatformType ());
}
final var index = getPlatformIndex (locator);
if (!isNull (locator.getFilter ())) {
return elements.stream ()
final var filteredElements = elements.stream ()
.filter (locator.getFilter ())
.findFirst ()
.orElseThrow (() -> new FrameworkError (format (ELEMENT_NOT_FOUND.getMessageText (), locator.getName (),
getSession ().getPlatformType ())));
.toList ();
if (filteredElements.isEmpty ()) {
throwError (ELEMENT_NOT_FOUND, locator.getName (), getSession ().getPlatformType ());
}
return filteredElements.get (index);
}
return elements.get (locator.getIndex ());
return elements.get (index);
}

/**
Expand Down Expand Up @@ -115,6 +116,16 @@ private static <D extends WebDriver> List<WebElement> finds (final D driver, fin
return LOGGER.traceExit (finds (driver, null, null, locator));
}

private static int getPlatformIndex (final Locator locator) {
final var index = switch (getSession ().getPlatformType ()) {
case ANDROID -> locator.getAndroidIndex ();
case IOS -> locator.getIosIndex ();
case MAC -> locator.getMacIndex ();
default -> locator.getWebIndex ();
};
return index > -1 ? index : locator.getIndex ();
}

private static void waitForElement (final Locator locator, final WaitStrategy waitStrategy) {
try {
final var wait = getSession ().getWait ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,25 @@
@Builder (toBuilder = true, builderMethodName = "buildLocator")
public class Locator {
private By android;
@Builder.Default
private int androidIndex = -1;
private Predicate<WebElement> filter;
private int index;
@Builder.Default
private int index = 0;
private By ios;
@Builder.Default
private int iosIndex = -1;
private By mac;
@Builder.Default
private int macIndex = -1;
@NotNull
private String name;
private Locator parent;
@Builder.Default
private boolean shadowRoot = false;
private boolean shadowRoot = false;
private By web;
@Builder.Default
private int webIndex = -1;

/**
* Gets the platform specific locator
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@release-it-plugins/lerna-changelog": "^8.0.1",
"@stylistic/eslint-plugin-js": "^4.4.1",
"@stylistic/eslint-plugin-ts": "^4.4.1",
"@types/node": "^24.6.2",
"@types/node": "^24.7.0",
"@typescript-eslint/eslint-plugin": "^8.45.0",
"@typescript-eslint/parser": "^8.45.0",
"commitlint": "^20.1.0",
Expand All @@ -61,7 +61,7 @@
"prettier": "^3.6.2",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"release-it": "^19.0.4",
"release-it": "^19.0.5",
"ts-node": "^10.9.2",
"typescript": "^5.9.3",
"typescript-eslint": "^8.45.0"
Expand Down Expand Up @@ -100,5 +100,5 @@
"pnpm format"
]
},
"packageManager": "pnpm@10.15.0"
"packageManager": "pnpm@10.18.0"
}
Loading
Loading