[AutoQC] Run Testcase over wifi without usb

Run Appium Tests over WiFi on Real Devices


NOTE BEFORE USE

  • Can connect via wifi up to 14 devices only.
  • If using a Samsung device, please change the USB mode from MTP to MIDI.
  • Each account uses a device.
  • Please disconnect from the wifi when it is no longer needed.
  • Please run the first step (first time) again if:
    – The device is powered off or restarted.
    – Device has changed IP.
    – Disconnected for too long.
    – The adb server is down (autoQC Team)

1. CONNECT FOR THE FIRST TIME

  • First of all, connect your mobile phone to your machine via USB cable.

  • Open command prompt and run the command: adb devices.

  • This would list down the mobile devices that are currently connected to your machine, as shown in the below image.
    adb1

  • Please make sure that your mobile device and system are connected to the same WiFi network.

  • Add device with udid (example: a6945810)
    image

  • Fill in the testcase: Insert the string “connectwifi” into the “value_insert” column for action “start_app_rtsurvey/start_app_rtwork”. See the example below:

  • Run the testcase as usual. The server will automatically connect to the device via wifi.

2. CONNECT FOR THE NEXT TIME

  • Now, disconnect your mobile device from your machine. You will not need your USB cable any more.

  • Find out the IP address of your mobile device. On your mobile device, go to Settings > WiFi > Advanced > IP address and note down.

  • Add new device with “Serial Number” is replaced with ip address combination and then run your test scripts (Use test-case as the first time).
    image

3. COMMON ERROR

  • 3.1 Inactive device:
    If you see in the console as the image below, then please check again:
    – Is the device connected ? (cable/wifi)
    – Is the Serial Number (UDID) correct?
    – Is the device status checked to be device?
    image
    If you’ve done everything above but remain the same, please contact the autoQC team.

  • 3.2 Device 192.168.11.xxx was not in list of connected devices
    You only get this error when running for the first time, it will look like the image below:


    → Please run it again

  • 3.3 The connection is full
    connectfull
    → If you get this error, please contact autoQC team.

  • 3.4 The instrumentation process cannot be initialized


    → If you only get this error when starting to run on wifi, please contact autoQC team.


AutoQC TEAM


Reference: http://www.automationtestinghub.com/run-appium-tests-over-wifi-without-usb/

1. CODE

  • List the device being connected, save to device.txt.
    shell_exec('adb devices > ./'.$filename.'/device.txt');

  • Check the device for use with the list above:
    – If the device is connecting via cable, connect to the device via wifi, then run with udid.
    – If the device is connecting via wifi, then run with ip:port.
    – If the device is not connected, print “Inactive Device” to script.

    $dv = file_get_contents('./'.$filename.'/device.txt');
        $dvline = explode("\n", $dv);
        foreach ($dvline as $key => $value) {
            if(trim($value) !== '' && $key !== 0){
                $status = "";
                //check the name of the device (physically connected)
                $re = '/(^\w.*)\t.*$/';
                if (preg_match($re, trim($value), $match)){
                   $dvwf = $match[1];
                   $flagip = 0;
                }
                //check the name of the device (wifi connected)
                $re = '/(^\d.*):55.{2}\t.*$/';
                if (preg_match($re, trim($value), $match)){
                   $dvwf = $match[1];
                   $flagip = 1;
                }
                //check status
                $re = '/^\w.*\t(.*)$/';
                if (preg_match($re, trim($value), $match)){
                   $status = $match[1];
                }

                if ($status == "device" && $dvwf == $device['serial_number']){        
                    if ($flagip == 0) {
                        shell_exec('adb -s '.$dvwf.' shell "ip addr show wlan0  | grep \'inet \' | cut -d\' \' -f6|cut -d/ -f1" > ./'.$filename.'/ipdv.txt');
                        $ipdv = file_get_contents('./'.$filename.'/ipdv.txt');
                        if (strpos($dv, trim($ipdv))){
                            $result .= "//Already connected via IP".PHP_EOL;
                            $flagdv = 1;
                            break;
                        }else{
                            $dvport = 5559;
                            for ($port = $dvport; strpos($dv, trim($port)); $port = $dvport) { 
                                if ($port < 5585) {
                                    $dvport = $port + 2;
                                    continue;
                                }else{
                                    $countconn = 1;
                                    break;
                                }
                            }
                            if ($countconn == 1){
                                $result .= "The connection is FULL".PHP_EOL;
                            }else{
                                $result .= "//Start connecting via IP".PHP_EOL;
                                shell_exec('adb -s '.$dvwf.' tcpip '.$dvport);
                                shell_exec('adb connect '.trim($ipdv).':'.$dvport.' > ./'.$filename.'/re.txt');
                                $res = file_get_contents('./'.$filename.'/re.txt');
                            }
                        }
                    }elseif ($flagip == 1){
                        $result .= "//Connecting via Wifi".PHP_EOL;
                        preg_match('/(^\d.*:55.{2})\t.*$/', trim($value), $match);
                        $ipdv = $match[1];
                    }
                    $flagdv = 1;
                    break;
                }
            }    
        }
        if ($flagdv == 0) {
            $result .= "Inactive Device".PHP_EOL;
        };

2. FIX COMMON ERROR

  • Check Inactive Device:
    Check adb server status on restart after running testcase.
    If you see:

    adb server is out of date. killing…
    * daemon started successfully *

    → Check adb server version and follow the link below.

  • The connection is full:
    Delete manually on the server:
    adb disconnect 192.168.11.xxx:55xx (if the device is offline when viewing in the “adb devices” list)
    Or run the clearIP action to remove the inactive IP (IP has offline status) → (File test-case: testclean.xlsx (12.6 KB) )

  • The instrumentation process cannot be initialized:
    Run Command Prompt (Local):
    adb uninstall io.appium.uiautomator2.server
    adb uninstall io.appium.uiautomator2.server.test
    And then run again under the local.

Reference link:
https://code.i-harness.com/en/q/230798d
https://helpex.vn/question/phien-ban-may-chu-adb-khong-phu-hop-voi-khach-hang-nay-5cbd376eae03f6064c26434b