|
20 | 20 | import static io.github.boykaframework.manager.ParallelSession.getSession; |
21 | 21 | import static io.github.boykaframework.utils.ErrorHandler.handleAndThrow; |
22 | 22 | import static io.github.boykaframework.utils.ErrorHandler.throwError; |
23 | | -import static java.text.MessageFormat.format; |
24 | 23 | import static java.util.Objects.isNull; |
25 | 24 | import static java.util.Objects.requireNonNull; |
26 | 25 | import static org.apache.logging.log4j.LogManager.getLogger; |
|
31 | 30 |
|
32 | 31 | import io.github.boykaframework.builders.Locator; |
33 | 32 | import io.github.boykaframework.enums.WaitStrategy; |
34 | | -import io.github.boykaframework.exception.FrameworkError; |
35 | 33 | import org.apache.logging.log4j.Logger; |
36 | 34 | import org.openqa.selenium.TimeoutException; |
37 | 35 | import org.openqa.selenium.WebDriver; |
@@ -60,14 +58,17 @@ public static WebElement find (final Locator locator, final WaitStrategy waitStr |
60 | 58 | if (elements.isEmpty ()) { |
61 | 59 | throwError (ELEMENT_NOT_FOUND, locator.getName (), getSession ().getPlatformType ()); |
62 | 60 | } |
| 61 | + final var index = getPlatformIndex (locator); |
63 | 62 | if (!isNull (locator.getFilter ())) { |
64 | | - return elements.stream () |
| 63 | + final var filteredElements = elements.stream () |
65 | 64 | .filter (locator.getFilter ()) |
66 | | - .findFirst () |
67 | | - .orElseThrow (() -> new FrameworkError (format (ELEMENT_NOT_FOUND.getMessageText (), locator.getName (), |
68 | | - getSession ().getPlatformType ()))); |
| 65 | + .toList (); |
| 66 | + if (filteredElements.isEmpty ()) { |
| 67 | + throwError (ELEMENT_NOT_FOUND, locator.getName (), getSession ().getPlatformType ()); |
| 68 | + } |
| 69 | + return filteredElements.get (index); |
69 | 70 | } |
70 | | - return elements.get (locator.getIndex ()); |
| 71 | + return elements.get (index); |
71 | 72 | } |
72 | 73 |
|
73 | 74 | /** |
@@ -115,6 +116,16 @@ private static <D extends WebDriver> List<WebElement> finds (final D driver, fin |
115 | 116 | return LOGGER.traceExit (finds (driver, null, null, locator)); |
116 | 117 | } |
117 | 118 |
|
| 119 | + private static int getPlatformIndex (final Locator locator) { |
| 120 | + final var index = switch (getSession ().getPlatformType ()) { |
| 121 | + case ANDROID -> locator.getAndroidIndex (); |
| 122 | + case IOS -> locator.getIosIndex (); |
| 123 | + case MAC -> locator.getMacIndex (); |
| 124 | + default -> locator.getWebIndex (); |
| 125 | + }; |
| 126 | + return index > -1 ? index : locator.getIndex (); |
| 127 | + } |
| 128 | + |
118 | 129 | private static void waitForElement (final Locator locator, final WaitStrategy waitStrategy) { |
119 | 130 | try { |
120 | 131 | final var wait = getSession ().getWait (); |
|
0 commit comments