Geo Location automation testing for geo fence feature

Hi All,
I am doing function automation testing using Appium. Now Geo fence feature has been implemented in my application. I need to test the feature in Emulator and Simulator.Can any help to how to proceed this .
Below are the sample test cases.

  1. Need to set up the geo fence for a particular location [Ex: Chicago Theatre] using Latitude & Longitude
  2. On entering or exit the geo fence area , application displaying an alert pop up with appropriate message with map view.
  3. I do not have any controls like text box or drop down to pass the location data in the app.

Note:
I found .gpx fils are used to store the lat & lon values. But I am not sure how to use the files in my Appium TestNG framework.

Hi @mani_kandan1,
You can use the setLocation method to set the latitude and longitude in Android emulator or iOS simulator:

import org.openqa.selenium.html5.Location;

Location loc = new Location(20.0, 12.5, 1000);  // latitude, longitude, altitude
driver.setLocation(loc);
1 Like

Hi @rgonalo
Thank you for your response. I have used the import & code in my project but It shows the below error
"The method setLocation(Location) is undefined for the type WebDriver. I am using Selenium v 2.44.0 and Appium v 1.2.0.1. Can you let me know if any changes are required

setLocation() is an AppiumDriver method, implemented in java-client (https://github.com/appium/java-client), not a WebDriver method:

AppiumDriver driver = new AndroidDriver(remoteAdress, capabilities);
Location loc = new Location(20.0, 12.5, 1000);  // latitude, longitude, altitude
driver.setLocation(loc);

(just to add to knowledge base)
This is implemented on the appium server, so if your languageā€™s client doesnā€™t support it, you might be able to write it. I just submitted a PR for appium/python-client
You might also be able to call it directly, for example in python:
my_webdriver.execute(ā€˜setLocationā€™,{ā€˜latitudeā€™: ā€˜31.2ā€™, ā€˜longitudeā€™: ā€˜-97.1ā€™})

hi, I am using the setLocation method using IOSDriver onā€¦8.4 simulator, xcode 6.4 and appium 1.4.8ā€¦ and it seems not working. is this method working now?

i have the same question.

I am getting this same warning in Eclipse while developing a Java test for Appium.

wd = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);
Location loc = new Location(20.0, 12.5, 1000);  // latitude, longitude, altitude
wd.setLocation(loc);

The method setLocation(Location) is undefined for the type WebDriver

Appium version 1.5.2

I had this issue as well. It was because I wasnā€™t properly declaring the web driver object properly.

Declare it as a ā€œAppiumDriverā€ object like @rgonalo did in his example and you wonā€™t get that error. Or perhaps as a IOSDriver.

So, in your case it should be as followsā€¦

AppiumDriver wd = new IOSDriver(new URL(ā€œhttp://127.0.0.1:4723/wd/hubā€), desiredCapabilities);

ā€¦ or perhapsā€¦

IOSDriver wd = new IOSDriver(new URL(ā€œhttp://127.0.0.1:4723/wd/hubā€), desiredCapabilities);

works for me on ios and android. on android you have to make sure to enable mock locations in developer settings on API >21.

I tried this Android emulator,
No errors but the location is not set properly.