-
-
Notifications
You must be signed in to change notification settings - Fork 762
ByAll was re-implemented. #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d1a9e51
a06a929
5b7955b
0cf1f9e
cef9efe
3917b52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package io.appium.java_client.pagefactory.bys.builder; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| import org.openqa.selenium.By; | ||
| import org.openqa.selenium.NoSuchElementException; | ||
| import org.openqa.selenium.SearchContext; | ||
| import org.openqa.selenium.WebElement; | ||
|
|
||
| import java.util.function.Function; | ||
|
|
||
|
|
||
| public class ByAll extends org.openqa.selenium.support.pagefactory.ByAll { | ||
|
|
||
| private By[] bys; | ||
|
|
||
| private Function<SearchContext, WebElement> getSearchingFunction(By by) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd mark it with Nullable annotation
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or it would be even better to return an Optional value |
||
| return input -> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return (input) -> ... is more readable |
||
| try { | ||
| return input.findElement(by); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } catch (NoSuchElementException e) { | ||
| return null; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * @param bys is a set of {@link org.openqa.selenium.By} which forms the all possible searching. | ||
| */ | ||
| public ByAll(By[] bys) { | ||
| super(bys); | ||
| checkNotNull(bys); | ||
| if (bys.length == 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better to use isEmpty() |
||
| throw new IllegalArgumentException("By array should not be empty"); | ||
| } | ||
| this.bys = bys; | ||
| } | ||
|
|
||
| @Override | ||
| public WebElement findElement(SearchContext context) { | ||
| for (By by : bys) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return bys.stream()
.map(x -> getSearchingFunction(x).apply(context))
.filter(Optional::isPresent)
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Cannot locate an element using " + toString()));
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mykola-mokhnach I don't think that we can use stream in this case, because it returns
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you know how to need to do it without double invoking searching function, show me please.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can. Updated my comment above |
||
| WebElement element = getSearchingFunction(by).apply(context); | ||
| if (element != null) { | ||
| return element; | ||
| } | ||
| } | ||
| throw new NoSuchElementException("Cannot locate an element using " + toString()); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep it as
List<By>internally