Skip to content

Commit 112ce77

Browse files
committed
AppiumDriver now implements LocationContext
1 parent 8e259c7 commit 112ce77

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
import com.google.common.collect.ImmutableMap;
2222
import io.appium.java_client.internal.JsonToMobileElementConverter;
2323
import org.openqa.selenium.*;
24+
import org.openqa.selenium.html5.Location;
25+
import org.openqa.selenium.html5.LocationContext;
2426
import org.openqa.selenium.remote.*;
27+
import org.openqa.selenium.remote.html5.RemoteLocationContext;
2528

2629
import javax.xml.bind.DatatypeConverter;
2730
import java.net.URL;
@@ -33,19 +36,23 @@
3336
import static io.appium.java_client.MobileCommand.*;
3437

3538
public class AppiumDriver extends RemoteWebDriver implements MobileDriver, ContextAware, Rotatable, FindsByIosUIAutomation,
36-
FindsByAndroidUIAutomator, FindsByAccessibilityId {
39+
FindsByAndroidUIAutomator, FindsByAccessibilityId, LocationContext {
3740

3841
private final static ErrorHandler errorHandler = new ErrorHandler(new ErrorCodesMobile(), true);
3942
private URL remoteAddress;
4043
private ComplexFind complexFind;
44+
private RemoteLocationContext locationContext;
45+
private ExecuteMethod executeMethod;
4146

4247
public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){
4348

4449
super(remoteAddress, desiredCapabilities);
4550
this.setElementConverter(new JsonToMobileElementConverter(this));
4651

52+
this.executeMethod = new AppiumExecutionMethod(this);
4753
this.remoteAddress = remoteAddress;
4854
complexFind = new ComplexFind(this);
55+
locationContext = new RemoteLocationContext(executeMethod);
4956

5057
ImmutableMap.Builder<String, CommandInfo> builder = ImmutableMap.builder();
5158
builder
@@ -93,6 +100,10 @@ protected Response execute(String command) {
93100
return execute(command, ImmutableMap.<String, Object>of());
94101
}
95102

103+
@Override
104+
public ExecuteMethod getExecuteMethod() {
105+
return executeMethod;
106+
}
96107

97108
/**
98109
* Reset the currently running app for this session
@@ -626,6 +637,16 @@ public List<WebElement> findElementsByAccessibilityId(String using) {
626637
return findElements("accessibility id", using);
627638
}
628639

640+
@Override
641+
public Location location() {
642+
return locationContext.location();
643+
}
644+
645+
@Override
646+
public void setLocation(Location location) {
647+
locationContext.setLocation(location);
648+
}
649+
629650
private TouchAction createTap(WebElement element, int duration) {
630651
TouchAction tap = new TouchAction(this);
631652
return tap.press(element).waitAction(duration).release();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.appium.java_client;
2+
3+
import com.google.common.collect.ImmutableMap;
4+
import org.openqa.selenium.remote.ExecuteMethod;
5+
import org.openqa.selenium.remote.Response;
6+
7+
import java.util.Map;
8+
9+
public class AppiumExecutionMethod implements ExecuteMethod {
10+
private final AppiumDriver driver;
11+
12+
public AppiumExecutionMethod(AppiumDriver driver) {
13+
this.driver = driver;
14+
}
15+
16+
public Object execute(String commandName, Map<String, ?> parameters) {
17+
Response response;
18+
19+
if (parameters == null || parameters.isEmpty()) {
20+
response = driver.execute(commandName, ImmutableMap.<String, Object>of());
21+
} else {
22+
response = driver.execute(commandName, parameters);
23+
}
24+
25+
return response.getValue();
26+
}
27+
}

src/test/java/io/appium/java_client/MobileDriverIOSTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.junit.Before;
2424
import org.junit.Test;
2525
import org.openqa.selenium.ScreenOrientation;
26+
import org.openqa.selenium.html5.Location;
2627
import org.openqa.selenium.remote.DesiredCapabilities;
2728

2829
import java.io.File;
@@ -130,4 +131,10 @@ public void orientationTest() {
130131
assertEquals(ScreenOrientation.LANDSCAPE, driver.getOrientation());
131132
}
132133

134+
@Test
135+
public void geolocationTest() {
136+
Location location = new Location(45, 45, 100);
137+
driver.setLocation(location);
138+
}
139+
133140
}

0 commit comments

Comments
 (0)