1818
1919import static io .appium .java_client .MobileCommand .GET_SESSION ;
2020import static java .util .Optional .ofNullable ;
21+ import static java .util .stream .Collectors .toMap ;
2122import static org .apache .commons .lang3 .StringUtils .isBlank ;
2223
2324import com .google .common .collect .ImmutableMap ;
2425
2526import org .openqa .selenium .remote .Response ;
2627
2728import java .util .Map ;
29+ import javax .annotation .Nullable ;
2830
2931public interface HasSessionDetails extends ExecutesMethod {
3032 /**
@@ -34,26 +36,47 @@ public interface HasSessionDetails extends ExecutesMethod {
3436 @ SuppressWarnings ("unchecked" )
3537 default Map <String , Object > getSessionDetails () {
3638 Response response = execute (GET_SESSION );
39+ Map <String , Object > resultMap = Map .class .cast (response .getValue ());
40+
41+ //this filtering was added to clear returned result.
42+ //results of further operations should be simply interpreted by users
3743 return ImmutableMap .<String , Object >builder ()
38- .putAll (Map .class .cast (response .getValue ())).build ();
44+ .putAll (resultMap .entrySet ()
45+ .stream ().filter (entry -> {
46+ String key = entry .getKey ();
47+ Object value = entry .getValue ();
48+ return !isBlank (key )
49+ && value != null
50+ && !isBlank (String .valueOf (value ));
51+ }).collect (toMap (Map .Entry ::getKey , Map .Entry ::getValue ))).build ();
3952 }
4053
41- default Object getSessionDetail (String detail ) {
54+ default @ Nullable Object getSessionDetail (String detail ) {
4255 return getSessionDetails ().get (detail );
4356 }
4457
45- default String getPlatformName () {
46- Object platformName = getSessionDetail ("platformName" );
47- return ofNullable (platformName != null ? String .valueOf (platformName ) : null ).orElse (null );
58+ /**
59+ * @return name of the current mobile platform.
60+ */
61+ default @ Nullable String getPlatformName () {
62+ Object platformName = ofNullable (getSessionDetail ("platformName" ))
63+ .orElseGet (() -> getSessionDetail ("platform" ));
64+ return ofNullable (platformName ).map (String ::valueOf ).orElse (null );
4865 }
4966
50- default String getAutomationName () {
51- Object automationName = getSessionDetail ("automationName" );
52- return ofNullable (automationName != null ? String .valueOf (automationName ) : null ).orElse (null );
67+ /**
68+ * @return current automation name.
69+ */
70+ default @ Nullable String getAutomationName () {
71+ return ofNullable (getSessionDetail ("automationName" ))
72+ .map (String ::valueOf ).orElse (null );
5373 }
5474
5575 /**
5676 * @return is focus on browser or on native content.
5777 */
58- boolean isBrowser ();
78+ default boolean isBrowser () {
79+ return ofNullable (getSessionDetail ("browserName" ))
80+ .orElse (null ) != null ;
81+ }
5982}
0 commit comments