Forum Discussion

MarekFric's avatar
MarekFric
Occasional Contributor
9 years ago
Solved

Get Internet connection state

Hi all,

 

Is it possible to get Internet connection state ? I would like to find out if my connected device has Internet connection or not. Googling I found only approach for programmers - http://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-timeouts.

 

For TestComplete I found only check for WiFi state - https://support.smartbear.com/viewarticle/73449/ but Mobile.Device.Connections doesn't have property InternetConnection

 

Marek

 

  • HKosova's avatar
    HKosova
    9 years ago

    Hi Marek,

     

    Your device appears to have a version of ping that can only run as a standard user. However, adb shell and TestComplete's ShellExecute run commands as root by default, hence the error. This link suggests changing file permissions for ping to make it compatible with adb shell -- if that's OK in your case. I couldn't find a general way to run adb shell commands as a standard/non-root user though.

     

    Other possible solutions would be to use external apps. For example:

    • Write a helper Android app (or find an existing one) that would check Internet connectivity. See these links for code examples.
    • If you have an instrumented application with a WebView, you can try navigating the WebView to some site, and check if the page loads successfully.

    Hope this helps.

11 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi Marek,

     

    Assuming you're using Android devices, you can try pinging some well-known host, for example, google.com.

    // JScript
    var strResult = Mobile.Device("emulator-5554").ShellExecute("ping google.com");

    If the device has Internet connection, the command output will be like this:

    PING google.com (109.195.185.102) 56(84) bytes of data.

    Otherwise it will be something like:

    ping: unknown host google.com

     

    • MarekFric's avatar
      MarekFric
      Occasional Contributor

      Hi Helen. Thanks for your advice, but I don't know why I get:

       

      PING www.google.a (213.81.185.160) 56(84) bytes of data.
      64 bytes from wildcard.zoznam.sk (213.81.185.160): icmp_seq=1 ttl=249 time=9.23 ms
      64 bytes from wildcard.zoznam.sk (213.81.185.160): icmp_seq=2 ttl=249 time=9.61 ms
      64 bytes from wildcard.zoznam.sk (213.81.185.160): icmp_seq=3 ttl=249 time=9.71 ms
      64 bytes from wildcard.zoznam.sk (213.81.185.160): icmp_seq=4 ttl=249 time=9.87 ms
      64 bytes from wildcard.zoznam.sk (213.81.185.160): icmp_seq=5 ttl=249 time=10.4 ms
      64 bytes from wildcard.zoznam.sk (213.81.185.160): icmp_seq=6 ttl=249 time=9.55 ms

       

      when I used following: 'adb shell ping www.google.a'