Search code examples
androidmonkeyrunnerandroidviewclient

Installing a package using Android viewClient


I am trying to implement Androidviewclient to run viewbased scripts , is there any way i can install new packages using androidviewclient like the way we can with monkeyrunner using "device.installPackage()"


Solution

  • EDIT

    AndroidViewClient/culebra version 11.0.7 implements ViewClient.installPackage() and also introduces a new command line option --install-apk that generates a test precondition based on the result of the installation of the APK. See https://github.com/dtmilano/AndroidViewClient/wiki/Test-Cookbook#installing-apks-as-preconditions for details.

    installPackage has not been implemented in AdbClient because it can be replaced by subprocess:

    #! /usr/bin/env python
    # -*- coding: utf-8 -*-
    '''
    Copyright (C) 2013-2014  Diego Torres Milano
    Created on 2015-11-14 by Culebra v10.8.2
                          __    __    __    __
                         /  \  /  \  /  \  /  \ 
    ____________________/  __\/  __\/  __\/  __\_____________________________
    ___________________/  /__/  /__/  /__/  /________________________________
                       | / \   / \   / \   / \   \___
                       |/   \_/   \_/   \_/   \    o \ 
                                               \_____/--<
    @author: Diego Torres Milano
    @author: Jennifer E. Swofford (ascii art snake)
    '''
    
    
    import re
    import sys
    import os
    import subprocess
    
    
    try:
        sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
    except:
        pass
    
    from com.dtmilano.android.viewclient import ViewClient
    
    TAG = 'CULEBRA'
    
    _s = 5
    _v = '--verbose' in sys.argv
    
    
    kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
    device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
    kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True}
    vc = ViewClient(device, serialno, **kwargs2)
    
    apk="/path/to/my/app-debug.apk"
    subprocess.check_call([vc.adb, "install", "-r", apk], shell=False)