Skip to content

Commit 5f36e28

Browse files
committed
chore: Add non-W3C Location-management endpoints deprecated in Selenium client
1 parent 43bbd48 commit 5f36e28

File tree

7 files changed

+120
-4
lines changed

7 files changed

+120
-4
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public class AppiumDriver extends RemoteWebDriver implements
7373
// frequently used command parameters
7474
@Getter
7575
private final URL remoteAddress;
76+
@Deprecated(forRemoval = true)
7677
protected final RemoteLocationContext locationContext;
7778
private final ExecuteMethod executeMethod;
7879
private final Set<String> absentExtensionNames = new HashSet<>();
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client;
18+
19+
import lombok.Getter;
20+
import lombok.ToString;
21+
22+
import javax.annotation.Nullable;
23+
24+
/**
25+
* Represents the physical location.
26+
*/
27+
@Getter
28+
@ToString
29+
public class Location {
30+
private final double latitude;
31+
private final double longitude;
32+
private final Double altitude;
33+
34+
/**
35+
* Create {@link Location} with latitude, longitude and altitude values.
36+
*
37+
* @param latitude latitude value.
38+
* @param longitude longitude value.
39+
* @param altitude altitude value (can be null).
40+
*/
41+
public Location(double latitude, double longitude, @Nullable Double altitude) {
42+
this.latitude = latitude;
43+
this.longitude = longitude;
44+
this.altitude = altitude;
45+
}
46+
47+
/**
48+
* Create {@link Location} with latitude and longitude values.
49+
*
50+
* @param latitude latitude value.
51+
* @param longitude longitude value.
52+
*/
53+
public Location(double latitude, double longitude) {
54+
this(latitude, longitude, null);
55+
}
56+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ public class MobileCommand {
187187
public static final String GET_CURRENT_CONTEXT_HANDLE = "getCurrentContextHandle";
188188
public static final String SWITCH_TO_CONTEXT = "switchToContext";
189189

190+
public static final String GET_LOCATION = "getLocation";
191+
public static final String SET_LOCATION = "setLocation";
192+
190193
public static final Map<String, CommandInfo> commandRepository;
191194

192195
static {
@@ -365,6 +368,9 @@ public class MobileCommand {
365368
commandRepository.put(GET_CONTEXT_HANDLES, getC("/session/:sessionId/contexts"));
366369
commandRepository.put(GET_CURRENT_CONTEXT_HANDLE, getC("/session/:sessionId/context"));
367370
commandRepository.put(SWITCH_TO_CONTEXT, postC("/session/:sessionId/context"));
371+
372+
commandRepository.put(GET_LOCATION, getC("/session/:sessionId/location"));
373+
commandRepository.put(SET_LOCATION, postC("/session/:sessionId/location"));
368374
}
369375

370376
/**

src/main/java/io/appium/java_client/android/AndroidDriver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ public AndroidBatteryInfo getBatteryInfo() {
252252
}
253253

254254
@Override
255+
@Deprecated(forRemoval = true)
255256
public RemoteLocationContext getLocationContext() {
256257
return locationContext;
257258
}

src/main/java/io/appium/java_client/android/geolocation/SupportsExtendedGeolocationCommands.java

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

1919
import io.appium.java_client.CommandExecutionHelper;
2020
import io.appium.java_client.ExecutesMethod;
21-
import org.openqa.selenium.remote.DriverCommand;
21+
import io.appium.java_client.MobileCommand;
2222

2323
import java.util.Map;
2424

@@ -31,7 +31,7 @@ public interface SupportsExtendedGeolocationCommands extends ExecutesMethod {
3131
* @param location The location object to set.
3232
*/
3333
default void setLocation(AndroidGeoLocation location) {
34-
CommandExecutionHelper.execute(this, Map.entry(DriverCommand.SET_LOCATION,
34+
CommandExecutionHelper.execute(this, Map.entry(MobileCommand.SET_LOCATION,
3535
Map.of("location", location.build())
3636
));
3737
}

src/main/java/io/appium/java_client/ios/IOSDriver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ class IOSAlert implements Alert {
280280
}
281281

282282
@Override
283+
@Deprecated(forRemoval = true)
283284
public RemoteLocationContext getLocationContext() {
284285
return locationContext;
285286
}

src/main/java/io/appium/java_client/remote/SupportsLocation.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,70 @@
1616

1717
package io.appium.java_client.remote;
1818

19+
import io.appium.java_client.CommandExecutionHelper;
20+
import io.appium.java_client.ExecutesMethod;
21+
import io.appium.java_client.MobileCommand;
1922
import org.openqa.selenium.WebDriver;
23+
import org.openqa.selenium.WebDriverException;
2024
import org.openqa.selenium.html5.Location;
2125
import org.openqa.selenium.html5.LocationContext;
2226
import org.openqa.selenium.remote.html5.RemoteLocationContext;
2327

24-
public interface SupportsLocation extends WebDriver, LocationContext {
25-
public RemoteLocationContext getLocationContext();
28+
import java.util.Map;
29+
import java.util.Optional;
2630

31+
public interface SupportsLocation extends WebDriver, ExecutesMethod, LocationContext {
32+
33+
@Deprecated(forRemoval = true)
34+
RemoteLocationContext getLocationContext();
35+
36+
/**
37+
* Gets the physical location of the browser.
38+
*
39+
* @return A {@link Location} containing the location information. Returns null if the location is not available
40+
* @deprecated This method and whole {@link LocationContext} interface are deprecated, use {@link #getLocation()}
41+
* instead.
42+
*/
43+
@Deprecated(forRemoval = true)
2744
default Location location() {
2845
return getLocationContext().location();
2946
}
3047

48+
/**
49+
* Gets the physical location.
50+
*
51+
* @return A {@link Location} containing the location information. Throws {@link WebDriverException} if the
52+
* location is not available.
53+
*/
54+
default io.appium.java_client.Location getLocation() {
55+
Map<String, Number> result = CommandExecutionHelper.execute(this, MobileCommand.GET_LOCATION);
56+
return Optional.ofNullable(result).map(r ->
57+
new io.appium.java_client.Location(
58+
r.get("latitude").doubleValue(),
59+
r.get("longitude").doubleValue(),
60+
Optional.ofNullable(r.get("altitude")).map(Number::doubleValue).orElse(null)
61+
)
62+
).orElseThrow(() -> new WebDriverException("Cannot retrieve location"));
63+
}
64+
65+
/**
66+
* Sets the physical location.
67+
*
68+
* @param location A {@link Location} containing the new location information.
69+
* @deprecated This method and whole {@link LocationContext} interface are deprecated, use
70+
* {@link #setLocation(io.appium.java_client.Location)} instead.
71+
*/
72+
@Deprecated(forRemoval = true)
3173
default void setLocation(Location location) {
3274
getLocationContext().setLocation(location);
3375
}
76+
77+
/**
78+
* Sets the physical location.
79+
*
80+
* @param location A {@link Location} containing the new location information.
81+
*/
82+
default void setLocation(io.appium.java_client.Location location) {
83+
execute(MobileCommand.SET_LOCATION, Map.of("location", location));
84+
}
3485
}

0 commit comments

Comments
 (0)