-
-
Notifications
You must be signed in to change notification settings - Fork 767
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 2 commits
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,53 @@ | ||
| 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.Arrays; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.function.Function; | ||
|
|
||
|
|
||
| public class ByAll extends org.openqa.selenium.support.pagefactory.ByAll { | ||
|
|
||
| private List<By> bys; | ||
|
|
||
| private Function<SearchContext, Optional<WebElement>> getSearchingFunction(By by) { | ||
| return input -> { | ||
|
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); | ||
|
||
| } catch (NoSuchElementException e) { | ||
| return Optional.empty(); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * @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); | ||
|
|
||
| this.bys = Arrays.asList(bys); | ||
| if (this.bys.isEmpty()) { | ||
|
||
| throw new IllegalArgumentException("By array should not be empty"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public WebElement findElement(SearchContext context) { | ||
| for (By by : bys) { | ||
|
||
| Optional<WebElement> element = getSearchingFunction(by).apply(context); | ||
| if (element.isPresent()) { | ||
| return element.get(); | ||
| } | ||
| } | ||
| throw new NoSuchElementException("Cannot locate an element using " + toString()); | ||
| } | ||
| } | ||
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.
can be final