-
-
Notifications
You must be signed in to change notification settings - Fork 768
chore: Add non-W3C Location-management endpoints deprecated in Selenium client #2098
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
Merged
valfirst
merged 3 commits into
appium:master
from
valfirst:add-non-w3c-location-management-endpoints-deprecated-in-selenium-client
Jan 15, 2024
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Represents the physical location. | ||
*/ | ||
@Getter | ||
@ToString | ||
@EqualsAndHashCode | ||
public class Location { | ||
private final double latitude; | ||
private final double longitude; | ||
@Nullable private final Double altitude; | ||
|
||
/** | ||
* Create {@link Location} with latitude, longitude and altitude values. | ||
* | ||
* @param latitude latitude value. | ||
* @param longitude longitude value. | ||
* @param altitude altitude value (can be null). | ||
*/ | ||
public Location(double latitude, double longitude, @Nullable Double altitude) { | ||
this.latitude = latitude; | ||
this.longitude = longitude; | ||
this.altitude = altitude; | ||
} | ||
|
||
/** | ||
* Create {@link Location} with latitude and longitude values. | ||
* | ||
* @param latitude latitude value. | ||
* @param longitude longitude value. | ||
*/ | ||
public Location(double latitude, double longitude) { | ||
this(latitude, longitude, null); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,19 +16,73 @@ | |
|
||
package io.appium.java_client.remote; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.appium.java_client.CommandExecutionHelper; | ||
import io.appium.java_client.ExecutesMethod; | ||
import io.appium.java_client.MobileCommand; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebDriverException; | ||
import org.openqa.selenium.html5.Location; | ||
import org.openqa.selenium.html5.LocationContext; | ||
import org.openqa.selenium.remote.html5.RemoteLocationContext; | ||
|
||
public interface SupportsLocation extends WebDriver, LocationContext { | ||
public RemoteLocationContext getLocationContext(); | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public interface SupportsLocation extends WebDriver, ExecutesMethod, LocationContext { | ||
|
||
@Deprecated(forRemoval = true) | ||
RemoteLocationContext getLocationContext(); | ||
|
||
/** | ||
* Gets the current device's geolocation coordinates. | ||
* | ||
* @return A {@link Location} containing the location information. Returns null if the location is not available | ||
* @deprecated This method and whole {@link LocationContext} interface are deprecated, use {@link #getLocation()} | ||
* instead. | ||
*/ | ||
@Deprecated(forRemoval = true) | ||
default Location location() { | ||
return getLocationContext().location(); | ||
} | ||
|
||
/** | ||
* Gets the current device's geolocation coordinates. | ||
* | ||
* @return A {@link Location} containing the location information. Throws {@link WebDriverException} if the | ||
* location is not available. | ||
*/ | ||
default io.appium.java_client.Location getLocation() { | ||
Map<String, Number> result = CommandExecutionHelper.execute(this, MobileCommand.GET_LOCATION); | ||
return new io.appium.java_client.Location( | ||
result.get("latitude").doubleValue(), | ||
result.get("longitude").doubleValue(), | ||
Optional.ofNullable(result.get("altitude")).map(Number::doubleValue).orElse(null) | ||
); | ||
} | ||
|
||
/** | ||
* Sets the current device's geolocation coordinates. | ||
* | ||
* @param location A {@link Location} containing the new location information. | ||
* @deprecated This method and whole {@link LocationContext} interface are deprecated, use | ||
* {@link #setLocation(io.appium.java_client.Location)} instead. | ||
*/ | ||
@Deprecated(forRemoval = true) | ||
default void setLocation(Location location) { | ||
valfirst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
getLocationContext().setLocation(location); | ||
} | ||
|
||
/** | ||
* Sets the current device's geolocation coordinates. | ||
* | ||
* @param location A {@link Location} containing the new location information. | ||
*/ | ||
default void setLocation(io.appium.java_client.Location location) { | ||
ImmutableMap.Builder<String, Object> locationParameters = ImmutableMap.builder(); | ||
locationParameters.put("latitude", location.getLatitude()); | ||
locationParameters.put("longitude", location.getLongitude()); | ||
Optional.ofNullable(location.getAltitude()).ifPresent(altitude -> locationParameters.put("altitude", altitude)); | ||
execute(MobileCommand.SET_LOCATION, Map.of("location", location)); | ||
mykola-mokhnach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.