Forum Discussion

gavemula's avatar
gavemula
Occasional Contributor
5 years ago

The Mock location unable to setup for Android and iOS devices with the Testcomplete methods

The Mock location is unable to set up for Android and iOS devices with the Testcomplete methods.  I have tried with the below VB script with valid Lattitude and longitude values, the script result shows as with the given longitude and latitude values but when we check in google maps or in any other applications the location still shows the current location.

 

Sub MockGPSLocation
  Call Mobile.SetCurrent("Nexus 7")
  ' Enable GPS
  Mobile.Device.GPS.GPSEnabled = true
  ' Enable the "Allow mock locations" property
  Mobile.Device.GPS.AllowMockLocations = true
  ' Obtain current location data
  Longt = Mobile.Device.GPS.Location.Longitude
  Lat = Mobile.Device.GPS.Location.Latitude
  Alt = Mobile.Device.GPS.Location.Altitude
  Acc = Mobile.Device.GPS.Location.Accuracy
  ' Output the location data
  Call Log.Message("The current device location is:")
  Call Log.Message("Longitude: "&Longt)
  Call Log.Message("Latitude: "&Lat)
  Call Log.Message("Altitude: "&Alt)
  Call Log.Message("Accuracy: "&Acc)
  ' Open Google Maps in the browser and pass the current coordinates as URL parameters
  Call Browsers.Item(Browsers.btIExplorer).Run("http://maps.google.com/maps?q=loc:"&Lat&","&Longt)
    
  ' Change the coordinates
  Longt = Longt+0.005
  Lat = Lat+0.005
  
  ' Specify a mock location
  Call Mobile.Device.GPS.SetLocation(Longt,Lat,Alt,Acc)
  
  ' Output the new location data
  Call Log.Message("The device mock location is:")
  Call Log.Message("Longitude: "&Longt)
  Call Log.Message("Latitude: "&Lat)
  Call Log.Message("Altitude: "&Alt)
  Call Log.Message("Accuracy: "&Acc)
  
  ' Open a new tab in the browser
  Call Sys.Browser("iexplore").BrowserWindow(0).Keys("^t")
  Call Delay(1000)
  ' Open the new location in Google Maps
  Call Sys.Browser("iexplore").Page("about:Tabs").ToUrl("http://maps.google.com/maps?q=loc:"&Lat&","&Longt)
End Sub  ' Disable mock locations
  Mobile.Device.GPS.AllowMockLocations = false

 

See Also

  • gavemula's avatar
    gavemula
    5 years ago

    Hi AlexKaras,

     

    Please find the below my inline comments:

     

    --You executed TestComplete script that enabled geolocation mocking on the device, modified current location (by increasing both longitude and latitude by 0.005) and finished with the geolocation mocking on the device been left enabled;----Yes, I have given longitude and latitude for a deferent location(eg: my current location is India mock location given as USA), I ran the script after updating the required settings in mobile device from developer options(GPS location on,Device only, mock location app as Testcompleteandroid agent etc..)

    -- Then you manually opened some other application on the device and this application showed initial location. (Not the location with the coordinates increased by 0.005.) --- I opened google maps to check my current location but it is still showing the current location instead of mock location.

     

    I have raised a ticket with SmartBear after a couple of discussions with the team, Smartbear confirmed there is a defect and informed us that they going to provide patch/release in a few days.  This issue is exist for both android and iOS devices.

     

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Disclaimer: I did not actively work with mobile geolocation testing thus most probably will be of little help here...

     

    Did I get you right that:

    -- You executed TestComplete script that enabled geolocation mocking on the device, modified current location (by increasing both longitude and latitude by 0.005) and finished with the geolocation mocking on the device been left enabled;

    -- Then you manually opened some other application on the device and this application showed initial location. (Not the location with the coordinates increased by 0.005.)

    Is the above correct?

     

    If the above is correct, then, upon reading the documentation, I have no other idea but the Remarks section from the "AllowMockLocations Property" help topic: "Some Android devices disallow changing GPS settings from applications. This limitation is set by the manufacturer and cannot be bypassed. To allow mock locations on such devices, set the required settings manually."

     

    If this is not your case, I would recommend to create a Support ticket via the https://support.smartbear.com/message/?prod=TestComplete form.

    I will appreciate it if you update this thread with the reply from Support.

     

    • gavemula's avatar
      gavemula
      Occasional Contributor

      Hi AlexKaras,

       

      Please find the below my inline comments:

       

      --You executed TestComplete script that enabled geolocation mocking on the device, modified current location (by increasing both longitude and latitude by 0.005) and finished with the geolocation mocking on the device been left enabled;----Yes, I have given longitude and latitude for a deferent location(eg: my current location is India mock location given as USA), I ran the script after updating the required settings in mobile device from developer options(GPS location on,Device only, mock location app as Testcompleteandroid agent etc..)

      -- Then you manually opened some other application on the device and this application showed initial location. (Not the location with the coordinates increased by 0.005.) --- I opened google maps to check my current location but it is still showing the current location instead of mock location.

       

      I have raised a ticket with SmartBear after a couple of discussions with the team, Smartbear confirmed there is a defect and informed us that they going to provide patch/release in a few days.  This issue is exist for both android and iOS devices.

       

       

      • sonya_m's avatar
        sonya_m
        SmartBear Alumni (Retired)

        Thank you for the update gavemula ! I am glad to hear the fix will become available soon.

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Thank you for the valuable ideas, Alex!

       

      gavemula Does this help?