Skip to content

Commit bbfe070

Browse files
jayandran-SampathSrinivasanTarget
authored andcommitted
Code changes for getting all session details (#1167)
* Code changes for getting all session details * Revert "Code changes for getting all session details" This reverts commit 76159eb. * Updated the comments and recommitting the changes * Organised import statement as per comments * Updated as per comments
1 parent 0a79698 commit bbfe070

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@
1616

1717
package io.appium.java_client;
1818

19+
import static io.appium.java_client.MobileCommand.GET_ALLSESSION;
1920
import static io.appium.java_client.MobileCommand.GET_SESSION;
2021
import static java.util.Optional.ofNullable;
2122
import static java.util.stream.Collectors.toMap;
2223
import static org.apache.commons.lang3.StringUtils.isBlank;
2324

25+
import com.google.common.collect.ImmutableList;
2426
import com.google.common.collect.ImmutableMap;
2527

2628
import org.openqa.selenium.remote.Response;
2729

30+
import java.util.List;
2831
import java.util.Map;
2932
import javax.annotation.Nullable;
3033

@@ -86,4 +89,16 @@ default boolean isBrowser() {
8689
return ofNullable(getSessionDetail("browserName"))
8790
.orElse(null) != null;
8891
}
92+
93+
/**
94+
* Get All Sessions details.
95+
*
96+
* @return List of Map objects with All Session Details.
97+
*/
98+
@SuppressWarnings("unchecked")
99+
default List<Map<String, Object>> getAllSessionDetails() {
100+
Response response = execute(GET_ALLSESSION);
101+
List<Map<String,Object>> resultSet = List.class.cast(response.getValue());
102+
return ImmutableList.<Map<String,Object>>builder().addAll(resultSet).build();
103+
}
89104
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public class MobileCommand {
111111
protected static final String TOGGLE_DATA;
112112
protected static final String COMPARE_IMAGES;
113113
protected static final String EXECUTE_DRIVER_SCRIPT;
114+
protected static final String GET_ALLSESSION;
114115

115116
public static final Map<String, CommandInfo> commandRepository;
116117

@@ -186,6 +187,7 @@ public class MobileCommand {
186187
TOGGLE_DATA = "toggleData";
187188
COMPARE_IMAGES = "compareImages";
188189
EXECUTE_DRIVER_SCRIPT = "executeDriverScript";
190+
GET_ALLSESSION = "getAllSessions";
189191

190192
commandRepository = new HashMap<>();
191193
commandRepository.put(RESET, postC("/session/:sessionId/appium/app/reset"));
@@ -271,6 +273,7 @@ public class MobileCommand {
271273
commandRepository.put(TOGGLE_DATA, postC("/session/:sessionId/appium/device/toggle_data"));
272274
commandRepository.put(COMPARE_IMAGES, postC("/session/:sessionId/appium/compare_images"));
273275
commandRepository.put(EXECUTE_DRIVER_SCRIPT, postC("/session/:sessionId/appium/execute_driver"));
276+
commandRepository.put(GET_ALLSESSION, getC("/sessions"));
274277
}
275278

276279
/**

src/test/java/io/appium/java_client/android/AndroidDriverTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -314,5 +314,10 @@ public void getPerformanceDataTest() {
314314
public void getCurrentPackageTest() {
315315
assertEquals(APP_ID, driver.getCurrentPackage());
316316
}
317+
318+
@Test public void validateAllSessions() {
319+
List<Map<String,Object>> jsonMap = driver.getAllSessionDetails();
320+
assertNotNull(jsonMap);
321+
}
317322

318323
}

0 commit comments

Comments
 (0)