Skip to content

Commit eb56807

Browse files
Merge pull request #403 from saikrishna321/master
added getSession api to fetch deviceUDID
2 parents 84abc80 + eed919a commit eb56807

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
package io.appium.java_client;
1919

2020
import static com.google.common.base.Preconditions.checkNotNull;
21+
2122
import static io.appium.java_client.MobileCommand.CLOSE_APP;
2223
import static io.appium.java_client.MobileCommand.GET_DEVICE_TIME;
24+
import static io.appium.java_client.MobileCommand.GET_SESSION;
2325
import static io.appium.java_client.MobileCommand.GET_SETTINGS;
2426
import static io.appium.java_client.MobileCommand.GET_STRINGS;
2527
import static io.appium.java_client.MobileCommand.HIDE_KEYBOARD;
@@ -682,4 +684,13 @@ private TouchAction createTap(int x, int y, int duration) {
682684
public URL getRemoteAddress() {
683685
return remoteAddress;
684686
}
687+
688+
/**
689+
* @return a map with values that hold session details.
690+
*
691+
*/
692+
public Map<String, String> getSessionDetails() {
693+
Response response = execute(GET_SESSION);
694+
return (Map<String, String>) response.getValue();
695+
}
685696
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public class MobileCommand {
6262
public static final String TOGGLE_LOCATION_SERVICES = "toggleLocationServices";
6363
public static final String GET_DEVICE_TIME = "getDeviceTime";
6464
public static final String UNLOCK = "unlock";
65+
public static final String GET_SESSION = "getSession";
6566
public static final Map<String, CommandInfo> commandRepository = getMobileCommands();
6667

6768
public static CommandInfo getC(String url) {
@@ -111,7 +112,8 @@ private static Map<String, CommandInfo> getMobileCommands() {
111112
.put(TOGGLE_LOCATION_SERVICES,
112113
postC("/session/:sessionId/appium/device/toggle_location_services"))
113114
.put(GET_DEVICE_TIME, getC("/session/:sessionId/appium/device/system_time"))
114-
.put(UNLOCK, postC("/session/:sessionId/appium/device/unlock"));
115+
.put(UNLOCK, postC("/session/:sessionId/appium/device/unlock"))
116+
.put(GET_SESSION,getC("/session/:sessionId/"));
115117

116118
return builder.build();
117119
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNotNull;
2122
import static org.junit.Assert.assertTrue;
2223

24+
2325
import io.appium.java_client.AppiumSetting;
2426
import org.apache.commons.codec.binary.Base64;
2527
import org.apache.commons.io.FileUtils;
@@ -134,4 +136,9 @@ public class AndroidDriverTest extends BaseAndroidTest {
134136
@Test public void endTestCoverage() {
135137
driver.endTestCoverage("android.intent.action.MAIN", "");
136138
}
139+
140+
@Test public void getDeviceUDIDTest() {
141+
String deviceSerial = driver.getSessionDetails().get("deviceUDID");
142+
assertNotNull(deviceSerial);
143+
}
137144
}

0 commit comments

Comments
 (0)