下面列出了怎么用org.openqa.selenium.html5.Location的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testLocationPermissions() {
// first, set the geolocation to something arbitrary
double newLat = 49.2827, newLong = 123.1207;
driver.setLocation(new Location(newLat, newLong, 0));
// now navigate to the location demo
wait.until(ExpectedConditions.presenceOfElementLocated(geolocation)).click();
// if permissions were set correctly, we should get no popup and instead be
// able to read the latitude and longitude that were previously set
By newLatEl = MobileBy.AccessibilityId("Latitude: " + newLat);
By newLongEl = MobileBy.AccessibilityId("Longitude: " + newLong);
wait.until(ExpectedConditions.presenceOfElementLocated(newLatEl));
wait.until(ExpectedConditions.presenceOfElementLocated(newLongEl));
}
@Ignore
@Test public void geolocationTest() {
Location location = new Location(45, 45, 100);
try {
driver.setLocation(location);
} catch (Exception e) {
fail("Not able to set location");
}
}
@Override
public Location location() {
@SuppressWarnings("unchecked")
Map<String, Number> result = (Map<String, Number>) executeMethod.execute(
DriverCommand.GET_LOCATION, null);
if (result == null) {
return null;
}
return new Location(castToDouble(result.get("latitude")),
castToDouble(result.get("longitude")),
castToDouble(result.get("altitude")));
}
@Override
public void setLocation(Location location) {
(this.client.driver).setLocation(location);
}
@Override
public void setLocation(Location location) {
this.client.driver.setLocation(location);
}
@Override
public Location location() {
return ((LocationContext) super.getWrappedDriver()).location();
}
@Override
public void setLocation(Location arg0) {
((LocationContext) super.getWrappedDriver()).setLocation(arg0);
}
@Override
public Location location() {
return locationContext.location();
}
@Override
public void setLocation(Location location) {
locationContext.setLocation(location);
}
@Test
public void geolocationTest() {
Location location = new Location(45, 45, 100);
driver.setLocation(location);
}
@Override
public Location location() {
return locationContext.location();
}
@Override
public void setLocation(Location location) {
locationContext.setLocation(location);
}
@Override
public Location location() {
return locationContext.location();
}
@Override
public void setLocation(Location location) {
locationContext.setLocation(location);
}
@Override
public void setLocation (Location location) {
Map<String, Location> args = ImmutableMap.of("location", location);
executeMethod.execute(DriverCommand.SET_LOCATION, args);
}
@Override
public Location location() {
return locationContext.location();
}
@Override
public void setLocation(Location location) {
locationContext.setLocation(location);
}
@Override
public Location location() {
return locationContext.location();
}
@Override
public void setLocation(Location location) {
locationContext.setLocation(location);
}
@Override
public Location call() {
return Utils.getLocationContext(getUnwrappedDriver()).location();
}
/**
* Set geo location.
*
* @param location Geo location.
*/
public void setLocation(Location location) {
this.device.setLocation(location);
}
/**
* TODO(): Add docs.
*
* @param location
*/
void setLocation(Location location);