-
- Notifications
You must be signed in to change notification settings - Fork 768
#732 FIX #733
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
#732 FIX #733
Changes from 2 commits
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 |
---|---|---|
| @@ -18,6 +18,7 @@ | |
| ||
import static io.appium.java_client.MobileCommand.GET_SESSION; | ||
import static java.util.Optional.ofNullable; | ||
import static java.util.stream.Collectors.toMap; | ||
import static org.apache.commons.lang3.StringUtils.isBlank; | ||
| ||
import com.google.common.collect.ImmutableMap; | ||
| @@ -34,26 +35,46 @@ public interface HasSessionDetails extends ExecutesMethod { | |
@SuppressWarnings("unchecked") | ||
default Map<String, Object> getSessionDetails() { | ||
Response response = execute(GET_SESSION); | ||
Map<String, Object> resultMap = Map.class.cast(response.getValue()); | ||
| ||
return ImmutableMap.<String, Object>builder() | ||
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 might be helpful to have a comment here about why additional filtering is necessary | ||
.putAll(Map.class.cast(response.getValue())).build(); | ||
.putAll(resultMap.entrySet() | ||
.stream().filter(entry -> { | ||
String key = entry.getKey(); | ||
Object value = entry.getValue(); | ||
return !isBlank(key) | ||
&& value != null | ||
&& !isBlank(String.valueOf(value)); | ||
}).collect(toMap(Map.Entry::getKey, Map.Entry::getValue))).build(); | ||
} | ||
| ||
default Object getSessionDetail(String detail) { | ||
return getSessionDetails().get(detail); | ||
} | ||
| ||
/** | ||
* @return name of the current mobile platform. | ||
*/ | ||
default String getPlatformName() { | ||
| ||
Object platformName = getSessionDetail("platformName"); | ||
return ofNullable(platformName != null ? String.valueOf(platformName) : null).orElse(null); | ||
Object platformName = ofNullable(getSessionDetail("platformName")) | ||
.orElseGet(() -> getSessionDetail("platform")); | ||
return ofNullable(platformName).map(Object::toString).orElse(null); | ||
} | ||
| ||
/** | ||
* @return current automation name. | ||
*/ | ||
default String getAutomationName() { | ||
Object automationName = getSessionDetail("automationName"); | ||
return ofNullable(automationName != null ? String.valueOf(automationName) : null).orElse(null); | ||
return ofNullable(getSessionDetail("automationName")) | ||
.map(Object::toString).orElse(null); | ||
} | ||
| ||
/** | ||
* @return is focus on browser or on native content. | ||
*/ | ||
boolean isBrowser(); | ||
default boolean isBrowser() { | ||
return ofNullable(getSessionDetail("browserName")) | ||
.map(browserName -> browserName.toString()) | ||
| ||
.orElse(null) != null; | ||
} | ||
} |
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.
Apache's StringUtils has StringUtils.containsIgnoreCase method