I have very recently started using Appium. I have got a scenario where in I need to enable GPS and then perform few test cases and later turn off the GPS.
Can any one please help me how can I enable/disable GPS settings using Appium.
So that you need to launch
1)Settings app, go to location and enable(ON) it first and
2) Then you can perform your test cases by launching another app by driver.startActivity(“appPackage”,“appActivity”);
3)After all test case are done, You can repeat the same for disabling (OFF) as above in 1st step.
In capabilities you can give Settings appPackage and appActivity…so that you may able to perform Enable/disable in the above 1st step, and you can repeat the same in the end…!!!
Manually I have to enable/disable location service in mobile setting or in application setting ?
if application means i can’t fine any option like enabling location services …
In my device appPackage and appActivity are as below…You can modify like as you required…!!! Please make sure that run your appium server with the given port ,before you run the script.
public class Settings_App {
static AndroidDriver driver; @BeforeTest
public static void setUp() throws Exception{
DesiredCapabilities mycap= new DesiredCapabilities();
mycap.setCapability(“deviceName”,“Android”);
mycap.setCapability(CapabilityType.VERSION,“4.4.2”);
mycap.setCapability(“appPackage”,“com.android.settings”);
mycap.setCapability(“appActivity”,".Settings");
mycap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT,60);
driver=new AndroidDriver(new URL(“http://0.0.0.0:4724/wd/hub”),mycap);
} @AfterTest
public static void tearDown() {
driver.quit();
} @Test
public static void settingsTest() throws Exception{
System.out.println(driver.currentActivity());
driver.scrollTo(“Location”);
driver.findElement(By.name(“Location”)).click();
driver.findElement(By.className(“android.widget.Switch”)).click();
Thread.sleep(5000);
driver.startActivity(“newAppPackage”,“newAppActivity”);
//Prerform of your Test cases…
/**
* After all test case are done, you can do the same.
*/
driver.startActivity(“com.android.settings”, “.Settings”);
System.out.println(driver.currentActivity());
driver.scrollTo(“Location”);
driver.findElement(By.name(“Location”)).click();
driver.findElement(By.className(“android.widget.Switch”)).click();
FAILED CONFIGURATION: @BeforeTest setUp
java.lang.NoSuchMethodError: io.appium.java_client.android.AndroidDriver.substituteMobilePlatform(Lorg/openqa/selenium/Capabilities;Ljava/lang/String;)Lorg/openqa/selenium/Capabilities;
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:40)
at com.appium.com.appium.gps.Settings_App.setUp(Settings_App.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:641)
at org.testng.TestRunner.run(TestRunner.java:609)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
@dduphorn As of now, I am unable to figure out a way to get the current status of GPS.
I checked the appium github page and found an open enhancement Get GPS location on Android #5047
Once that is released then we should be able to directly get the current location.