Friday, 21 March 2014

Android Sample Telnet Commands


Connect your emulator from a command prompt:
Eg#   telnet localhost 5556


Telnet Commands:
1.  Help
2. SMS Send 1234567890 Hello!
3. Help Power
4. Power Capacity 100
5. Power ac  
6. Window scale 0.5 (Changing the size of a emulator dynamically)
7. avd start
8. avd stop
9. avd snapshot
10. avd status - Get the current status of the emulator
11. GSM Call 1234567890 - Make call
12. GSM Cancel 1234567890 - Reject the call Or Hit F4 from the emulator window
13. Geo Fix <Longitude Value> <Latitude Value>.

To simulate the GPS points your android emulator run the below java program,Please make sure that Your emulator running on the correct phone numner.

import java.io.IOException; import java.io.PrintStream; import java.net.Socket; import java.net.UnknownHostException; class GPSDemo { static final int PAUSE = 4000; // ms static final float START_LONGITUDE = 51, START_LATITUDE = -1.3f; static final int NO_SAMPLE = 100; static final float DELTA_LONGITUDE = 0.000005f, DELTA_LADITUDE = 0.000005f; public static void main(String[] args) { try { Socket socket = new Socket("localhost", 5554); // usually 5554 PrintStream out = new PrintStream(socket.getOutputStream()); float longitude = START_LONGITUDE, latitude = START_LATITUDE; String str; for (int i = 0; i < NO_SAMPLE; i++) { str = "geo fix " + latitude + " " + longitude + "\n"; out.print(str); System.out.print(str); Thread.sleep(PAUSE); longitude += DELTA_LONGITUDE; latitude += DELTA_LADITUDE; } } catch (UnknownHostException e) { System.exit(-1); } catch (IOException e) { System.exit(-1); } catch (InterruptedException e) { System.exit(-1); } } }

7 comments:

  1. Hi sridhar,

    I am doing Automation testing using Appium. Could you please elaborate[Steps] more how to hit the above commands and execute the program.I have got the below response when I hit the commands


    C:\Users\MiddleWare>adb devices
    List of devices attached
    emulator-5554 device

    C:\Users\MiddleWare>avd start
    'avd' is not recognized as an internal or external command,
    operable program or batch file.

    C:\Users\MiddleWare>SMS Send 1234567890 Hello!
    'SMS' is not recognized as an internal or external command,
    operable program or batch file.


    ReplyDelete
    Replies
    1. If you have already created AVD,
      Please follow the below commands to start the emulator.

      C:\> emulator -avd sridhar
      Syntax: emulator -avd <>

      In the above question, seems to be you have already started the emulator so no need to use avd start again. And any how to start the emulator from command line refer above command.

      So to trigger the SMS or call or any events to Emulator, first connect to your Emulator from command line with the below command.

      C:\> telnet localhost .

      adb devices will give the info like emulator-5554 device, where 5554 is the port number.

      Example: telnet localhost 5554

      Once you connected to avd with the above command then send the below command.
      SMS Send 1234567890 Hello!








      Delete
    2. HI Sridhar,

      Thanks for the quick response. I've started the emulator from command prompt. But I could not execute the telnet commands . Please find the below response,


      C:\>emulator -avd CIM_Mani

      C:\>Creating filesystem with parameters:
      Size: 69206016
      Block size: 4096
      Blocks per group: 32768
      Inodes per group: 4224
      Inode size: 256
      Journal blocks: 1024
      Label:
      Blocks: 16896
      Block groups: 1
      Reserved block group size: 7
      Created filesystem with 11/4224 inodes and 1302/16896 blocks
      could not get wglGetExtensionsStringARB
      could not get wglGetExtensionsStringARB
      could not get wglGetExtensionsStringARB
      could not get wglGetExtensionsStringARB
      could not get wglGetExtensionsStringARB
      could not get wglGetExtensionsStringARB
      could not get wglGetExtensionsStringARB
      could not get wglGetExtensionsStringARB
      Failed to create Context 0x3005
      emulator: WARNING: Could not initialize OpenglES emulation, using software rende
      rer.
      emulator: warning: opening audio input failed


      C:\>telnet localhost 5554
      'telnet' is not recognized as an internal or external command,
      operable program or batch file.

      C:\>telnet localhost CIM_Mani
      'telnet' is not recognized as an internal or external command,
      operable program or batch file.


      Delete
    3. Follow the below link to activate telnet on your machine.

      http://www.wikihow.com/Activate-Telnet-in-Windows-7

      Delete
    4. You can refer the above test program to simulate the GPS by using scripts. Or else you can use Fake GPS app (you can download it from playstore). By using this app you can set a fake location on the device.

      I did it with Java program.

      Thanks

      Delete
  2. Hi Sridhar,

    I need to automate geo fence based application. Currently I am using Appium Framework for functional testing. Could you please let me know how to pass the latitude and longitude values inside test script.
    note:
    I do not have any text box or Input controls on the application to pass the values . I found .gpx files can be used to store location data. But I am not sure how to use the files in testing framework.

    ReplyDelete
  3. Follow the below link to activate telnet on your machine.

    http://www.wikihow.com/Activate-Telnet-in-Windows-7

    ReplyDelete