18
18
19
19
import static io .appium .java_client .MobileCommand .GET_SESSION ;
20
20
import static java .util .Optional .ofNullable ;
21
+ import static java .util .stream .Collectors .toMap ;
21
22
import static org .apache .commons .lang3 .StringUtils .isBlank ;
22
23
23
24
import com .google .common .collect .ImmutableMap ;
24
25
25
26
import org .openqa .selenium .remote .Response ;
26
27
27
28
import java .util .Map ;
29
+ import javax .annotation .Nullable ;
28
30
29
31
public interface HasSessionDetails extends ExecutesMethod {
30
32
/**
@@ -34,26 +36,47 @@ public interface HasSessionDetails extends ExecutesMethod {
34
36
@ SuppressWarnings ("unchecked" )
35
37
default Map <String , Object > getSessionDetails () {
36
38
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
37
43
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 ();
39
52
}
40
53
41
- default Object getSessionDetail (String detail ) {
54
+ default @ Nullable Object getSessionDetail (String detail ) {
42
55
return getSessionDetails ().get (detail );
43
56
}
44
57
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 );
48
65
}
49
66
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 );
53
73
}
54
74
55
75
/**
56
76
* @return is focus on browser or on native content.
57
77
*/
58
- boolean isBrowser ();
78
+ default boolean isBrowser () {
79
+ return ofNullable (getSessionDetail ("browserName" ))
80
+ .orElse (null ) != null ;
81
+ }
59
82
}
0 commit comments