Forum Discussion

googleid_109625's avatar
googleid_109625
New Contributor
11 years ago
Solved

Android device is getting unplugged when executing InstallPackage or RemovePackage, unable to execute fully automated tests.

Hello.

I'm executing my newly created test on real Android device through USB cable. Everything works fine, but I have one problem that have to be solved or SmartBear TestComplete is going to be useless for me. 

I've added a LOOP in front and end of testcase, so it's running full test whole time untill I stop it manually. 



Right now it's working like that:

- Install apk on real device (RunTestedApp function)

- Run test (runs apk and go through registration process)

- At the end of test, go to label that's at start of testcase

- Uninstall apk on real device (RunTestedApp function)

- Install apk on real device again and test goes on again (RunTestedApp function)



My problem is:

After it complete my whole testcase 100% successfully, it goes to the start of testcase. When it goes to the start of testcase, it's executing RunTestedApp function again, what makes my application data clear (because of RemovePackage function before InstallPackage, and yes, I want that this way because I can't find other way to clear application data). And now, on this step, when it's uninstalling apk or installing apk (problem exists when installing and uninstalling, totally randomized, occurs more often when uninstalling) my Android device is getting UNPLUGGED in TestComplete. To make it visible again I have to plug it off and plug it on again. 



This problem causes very big issue for me, I'm not able to run fully automated tests.



If that problem exists because some sort of "new files" are added when registration process goes on and later TestComplete is having problems uninstalling apk, it needs to be fixed, because like I said earlier, that problem is a serious problem for me.



Also I have a simple JScript that calls InstallPackage, LaunchPackage and RemovePackage.



Here's it:






function Test()


{


  // Obtain the PackageObject object


  var DeviceObj = Mobile.Device("");


  var PackManagerObj = DeviceObj.PackageManager;


  var PackObj = PackManagerObj.GetPackageFromAPK("C:\\RX-Android-20140313-1130_poland_smartbear.apk");


  // Install the package


  PackManagerObj.InstallPackage(PackObj);


  // Launch the default activity for the package


  PackManagerObj.LaunchPackage(PackObj);


  // Remove the package


  PackManagerObj.RemovePackage(PackObj);


}





After running my script, It looks like this:


1. Installs apk (InstallPackage)


2. Runs apk (LaunchPackage)


3. Closes apk (RemovePackage)


4. Test stops with an error "The Android device was disconnected. Failed to remove package~." 


Important note in this point: Application on Mobile Device is getting successfully uninstalled, but TestComplete returns an error that he couldn't remove package. No idea why, but that's causing serious issue for me, I'm unable to do fully automated tests.




 


Tested on Samsung Galaxy S3, S4 and Nexus 7 -> exactly same problem exists on all devices.



Also I've splitted this script up and I've made 3 different scripts -> 1 for Install, 1 for Run and 1 for Remove scripts. I did it and reworked my testcase to something like that:



1. Run JScript InstallPackage only


2. Run JScript RunPackage only

3. Run whole testcase

4. At the end of testcase before "GoToLabel" function (it goes to label "start" on the beginning of testcase, making it unlimited loop), run JScript RemovePackage only -> AT THIS POINT - ofcourse - I'm getting an "Android device has been disconnected." error, full log is attached.


 


 


Best regards,


Jacob.




  • Hi Jakub,


     


    As far as I understand from the support case you've submitted, the problem doesn't persist in TestComplete 10.10, right?


     

5 Replies

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Jakub,


     


    As far as I understand from the support case you've submitted, the problem doesn't persist in TestComplete 10.10, right?


     

  • That's right, version 10.10 fixed my problem.



    But still I have to use JScripts I've posted in first post for Install, Run and RemovePackage instead of RunTestedApp function (when I'm using RunTestedApp function, same problem happens that I've posted in my first post). Atleast I'm able to JScripts instead of RunTestedApp function, so problem doesn't exist for me anymore (kind of workaround).



    Best regards,

    Jacob.
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Jakub,


     


    I suggest that you let the Support Team know this - they can investigate why this behavior happens in their test lab.


     

    • suvidhshetty's avatar
      suvidhshetty
      Contributor

      Hi Jakob,

       

      We are facing similar issue while executing the tests in loop. After executing some tests the TestComplete will not be able to find the application process even if the application is visible on the screen.

       

      Were you able to get any resolution for your issue if yes please do share with us.

       

      Thanks!

      • anhvu's avatar
        anhvu
        Frequent Contributor

        All,

         

        I got the same issue and I have come over it by the script below.

         

        Note: You should add the CMD (command prompt to the TestedApp)

         

        function Restart_USB_Port()
        {
        if(Sys["Process"]("cmd")["Exists"] == true)
        {
        Sys["Process"]("cmd")["Terminate"]();
        Delay(1000)
        }
        //Open CMD
        TestedApps["cmd"]["Run"]()
        Delay(2000)
        //1- ***** Check the Music is playing or not
        if(Sys["Process"]("cmd")["Exists"] == true)
        {
        var pcmd = Sys["Process"]("cmd")

        var cmdEdit = pcmd["Window"]("ConsoleWindowClass", "*.exe", 1)
        cmdEdit["Keys"]("adb usb[Enter]")
        Delay(15000) // This hard delay is the average time for a USB port refreshes and recognizes the device.
        }
        else
        {
        Log["Warning"]("Restart_USB: The CMD is not displayed ")
        }
        }

         

        Hope it help.