Skip to content

Commit

Permalink
Code changes for getting all session details (#1167)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jayandran-Sampath authored and SrinivasanTarget committed Jul 2, 2019
1 parent 0a79698 commit bbfe070
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/io/appium/java_client/HasSessionDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@

package io.appium.java_client;

import static io.appium.java_client.MobileCommand.GET_ALLSESSION;
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.ImmutableList;
import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.remote.Response;

import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -86,4 +89,16 @@ default boolean isBrowser() {
return ofNullable(getSessionDetail("browserName"))
.orElse(null) != null;
}

/**
* Get All Sessions details.
*
* @return List of Map objects with All Session Details.
*/
@SuppressWarnings("unchecked")
default List<Map<String, Object>> getAllSessionDetails() {
Response response = execute(GET_ALLSESSION);
List<Map<String,Object>> resultSet = List.class.cast(response.getValue());
return ImmutableList.<Map<String,Object>>builder().addAll(resultSet).build();
}
}
3 changes: 3 additions & 0 deletions src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public class MobileCommand {
protected static final String TOGGLE_DATA;
protected static final String COMPARE_IMAGES;
protected static final String EXECUTE_DRIVER_SCRIPT;
protected static final String GET_ALLSESSION;

public static final Map<String, CommandInfo> commandRepository;

Expand Down Expand Up @@ -186,6 +187,7 @@ public class MobileCommand {
TOGGLE_DATA = "toggleData";
COMPARE_IMAGES = "compareImages";
EXECUTE_DRIVER_SCRIPT = "executeDriverScript";
GET_ALLSESSION = "getAllSessions";

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,10 @@ public void getPerformanceDataTest() {
public void getCurrentPackageTest() {
assertEquals(APP_ID, driver.getCurrentPackage());
}

@Test public void validateAllSessions() {
List<Map<String,Object>> jsonMap = driver.getAllSessionDetails();
assertNotNull(jsonMap);
}

}

0 comments on commit bbfe070

Please sign in to comment.