Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 753
#764 alternative fix#769
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
Uh oh!
There was an error while loading. Please reload this page.
#764 alternative fix #769
Changes from all commits
2ddb61c60b2aa9e75a8a5a19c0deb784e16d10f5d1File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -16,40 +16,45 @@ | ||
| package io.appium.java_client.pagefactory.bys; | ||
| import static io.appium.java_client.pagefactory.utils.WebDriverUnpackUtility.getCurrentContentType; | ||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
| import static io.appium.java_client.pagefactory.bys.ContentType.NATIVE_MOBILE_SPECIFIC; | ||
| import org.openqa.selenium.By; | ||
| import org.openqa.selenium.SearchContext; | ||
| import org.openqa.selenium.WebElement; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import javax.annotation.Nonnull; | ||
| public class ContentMappedBy extends By { | ||
| private final Map<ContentType, By> map; | ||
| private ContentType currentContent = NATIVE_MOBILE_SPECIFIC; | ||
| public ContentMappedBy(Map<ContentType, By> map) { | ||
| this.map = map; | ||
| } | ||
| /** | ||
| * This method sets required content type for the further searching. | ||
| * @param type required content type {@link ContentType} | ||
| * @return self-reference. | ||
| */ | ||
| public By useContent(@Nonnull ContentType type) { | ||
| checkNotNull(type); | ||
| currentContent = type; | ||
| return this; | ||
| } | ||
| @Override public WebElement findElement(SearchContext context) { | ||
| return context.findElement(map.get(getCurrentContentType(context))); | ||
| return context.findElement(map.get(currentContent)); | ||
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. is it ok if ContributorAuthor 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. It is not possible. It will use NATIVE_MOBILE_SPECIFIC as it is defined by default or it will use HTML_OR_DEFAULT when there is no Also there is the method /** * This method sets required content type for the further searching. * @param type required content type {@link ContentType} * @return self-reference. */publicByuseContent(@NonnullContentTypetype) {
checkNotNull(type);
currentContent = type;
returnthis;
} | ||
| } | ||
| @Override public List<WebElement> findElements(SearchContext context) { | ||
| return context.findElements(map.get(getCurrentContentType(context))); | ||
| return context.findElements(map.get(currentContent)); | ||
| } | ||
| @Override public String toString() { | ||
| By defaultBy = map.get(ContentType.HTML_OR_DEFAULT); | ||
| By nativeBy = map.get(ContentType.NATIVE_MOBILE_SPECIFIC); | ||
| if (defaultBy.equals(nativeBy)) { | ||
| return defaultBy.toString(); | ||
| } | ||
| return "Locator map: " + "\n" | ||
| + "- native content: \"" + nativeBy.toString() + "\" \n" | ||
| + "- html content: \"" + defaultBy.toString() + "\""; | ||
| return map.get(currentContent).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.
does it make any sense to use
String.valueOffor values of type String?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.
@mykola-mokhnach It may return
nullvalue