Skip to content

Commit 983c176

Browse files
Merge pull request #733 from TikhomirovSergey/master
#732 FIX
2 parents 9e3946c + 89b22dd commit 983c176

File tree

2 files changed

+35
-37
lines changed

2 files changed

+35
-37
lines changed

src/main/java/io/appium/java_client/AppiumDriver.java

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
package io.appium.java_client;
1818

1919
import static com.google.common.base.Preconditions.checkNotNull;
20-
import static io.appium.java_client.remote.MobileCapabilityType.AUTOMATION_NAME;
2120
import static io.appium.java_client.remote.MobileCapabilityType.PLATFORM_NAME;
22-
import static java.util.Optional.ofNullable;
21+
import static org.apache.commons.lang3.StringUtils.containsIgnoreCase;
2322

2423
import com.google.common.collect.ImmutableMap;
2524

@@ -72,9 +71,6 @@ public class AppiumDriver<T extends WebElement>
7271
private URL remoteAddress;
7372
private RemoteLocationContext locationContext;
7473
private ExecuteMethod executeMethod;
75-
private final String platformName;
76-
private final String automationName;
77-
7874

7975
/**
8076
* @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}
@@ -89,20 +85,6 @@ public AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities) {
8985
locationContext = new RemoteLocationContext(executeMethod);
9086
super.setErrorHandler(errorHandler);
9187
this.remoteAddress = executor.getAddressOfRemoteServer();
92-
93-
Object capabilityPlatform1 = getCapabilities().getCapability(PLATFORM_NAME);
94-
Object capabilityAutomation1 = getCapabilities().getCapability(AUTOMATION_NAME);
95-
96-
Object capabilityPlatform2 = capabilities.getCapability(PLATFORM_NAME);
97-
Object capabilityAutomation2 = capabilities.getCapability(AUTOMATION_NAME);
98-
99-
platformName = ofNullable(ofNullable(super.getPlatformName())
100-
.orElse(capabilityPlatform1 != null ? String.valueOf(capabilityPlatform1) : null))
101-
.orElse(capabilityPlatform2 != null ? String.valueOf(capabilityPlatform2) : null);
102-
automationName = ofNullable(ofNullable(super.getAutomationName())
103-
.orElse(capabilityAutomation1 != null ? String.valueOf(capabilityAutomation1) : null))
104-
.orElse(capabilityAutomation2 != null ? String.valueOf(capabilityAutomation2) : null);
105-
10688
this.setElementConverter(new JsonToMobileElementConverter(this, this));
10789
}
10890

@@ -282,15 +264,8 @@ public URL getRemoteAddress() {
282264
return remoteAddress;
283265
}
284266

285-
@Override public String getPlatformName() {
286-
return platformName;
287-
}
288-
289-
@Override public String getAutomationName() {
290-
return automationName;
291-
}
292-
293267
@Override public boolean isBrowser() {
294-
return !getContext().toLowerCase().contains("NATIVE_APP".toLowerCase());
268+
return super.isBrowser()
269+
&& !containsIgnoreCase(getContext(), "NATIVE_APP");
295270
}
296271
}

src/main/java/io/appium/java_client/HasSessionDetails.java

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818

1919
import static io.appium.java_client.MobileCommand.GET_SESSION;
2020
import static java.util.Optional.ofNullable;
21+
import static java.util.stream.Collectors.toMap;
2122
import static org.apache.commons.lang3.StringUtils.isBlank;
2223

2324
import com.google.common.collect.ImmutableMap;
2425

2526
import org.openqa.selenium.remote.Response;
2627

2728
import java.util.Map;
29+
import javax.annotation.Nullable;
2830

2931
public 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

Comments
 (0)