Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code changes for getting all session details #1167

Merged
merged 5 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
SrinivasanTarget marked this conversation as resolved.
Show resolved Hide resolved
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);
}

}