Search code examples
androidpythonautomationappiumtest-suite

How to prevent app from re-installing each time when I run tests in appium using python


I have written a python test suit for automation testing of an Android App. There are multiple test cases in this suit. I have put only 2 right now.

The problem is that, After each test case the app gets uninstalled, and installed back again. This happens with each test case. It takes so much time to get uninstalled and install back..

Appium version I am using is 1.5.0

I have tried using :

desired_caps['noReset'] = 'true'

desired_caps['fullReset'] = 'false'

and

appium --no-reset

But, of no use..

This is my python code file playpause.py :

class MaverickAndroidTests(unittest.TestCase):

    def setUp(self):
        "Setup for the test"
        desired_caps = {}
        desired_caps['browserName']=''
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '4.4.2'       
        desired_caps['deviceName'] = 'karthikphone1'
        desired_caps['app'] = '/home/karthik/appiumworkspace/tests/app-debug (8).apk'
        desired_caps['noReset'] = 'true'
        desired_caps['fullReset'] = 'false'
        desired_caps['appPackage'] = 'com.prueba.maverick'
        desired_caps['app-activity'] = '.SplashActivity' 
        desired_caps['app-wait-activity'] = '.CommonViewActivity' 
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    def test_on_play_and_pause(self):   
        self.driver.implicitly_wait(15) # seconds
        print(" ")
            element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.ID, "tabs")))
        self.assertIsNotNone(element)
        element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.XPATH, "//android.widget.TextView[@text='RECORD']")))
        self.assertIsNotNone(element)
        print element.text
        element.click() #click on RECORD tab
        element = WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.ID, "Btn_Rec")))
        self.assertEqual("PRESS TO RECORD", element.text, "not equal")
        print(element.text)
        element.click()
        time.sleep(4)   
        element = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "Btn_Rec")))
        self.assertEqual("RECORDING... PRESS TO STOP", element.text, "not equal")
        print(element.text)
        element.click()
        time.sleep(1)
        element = WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.ID, "Btn_Save")))
        element.click()
        time.sleep(2)
        print(' ')
        print('AUDIO RECORDED SUCCESSFULLY')    
        print(" ")

    def test_indefinite_times_Pausing_and_Unpausing(self):  
        element = WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.ID, "Btn_Rec")))
        self.assertEqual("PRESS TO RECORD", element.text, "not equal")
        print(element.text)
        element.click()
        time.sleep(4)   
        element = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "Btn_Rec")))
        self.assertEqual("RECORDING... PRESS TO STOP", element.text, "not equal")
        print(element.text)
        element.click()
        time.sleep(1)
        element = WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.ID, "Btn_Rec")))
        self.assertEqual("PAUSED... PRESS TO RESUME", element.text, "not equal")
        print(element.text)
        element.click()
        time.sleep(4)


    def tearDown(self):
        "Tear down the test"
    #   self.driver.quit()

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(MaverickAndroidTests)
    unittest.TextTestRunner(verbosity=2).run(suite)

I have commented the quit statement in teardown function..

Python Terminal error message :

karthik@dkarnik2-Vostro-3558:~/appiumworkspace/appium-1.4.13/submodules/sample-code/examples/python$ python playpause.py 
test_on_play_and_pause (__main__.MaverickAndroidTests) ...  

RECORD
PRESS TO RECORD
RECORDING... PRESS TO STOP

AUDIO RECORDED SUCCESSFULLY

ok
test_save_recording_without_pausing (__main__.MaverickAndroidTests) ... ERROR

======================================================================
ERROR: test_save_recording_without_pausing (__main__.MaverickAndroidTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "playpause.py", line 27, in setUp
    self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
  File "/usr/local/lib/python2.7/dist-packages/appium/webdriver/webdriver.py", line 36, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 87, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 141, in start_session
    'desiredCapabilities': desired_capabilities,
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
WebDriverException: Message: A new session could not be created. Details: Problem getting session data for driver type AndroidDriver; does it implement 'get driverData'?


----------------------------------------------------------------------
Ran 2 tests in 29.605s

FAILED (errors=1)
karthik@dkarnik2-Vostro-3558:~/appiumworkspace/appium-1.4.13/submodules/sample-code/examples/python$ 

Appium terminal error message

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: getText
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":"RECORDING... PRESS TO STOP","status":0}
[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.getText() result: "RECORDING... PRESS TO STOP"
[HTTP] <-- GET /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/4/text 200 59 ms - 100 
[HTTP] --> GET /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/4/text 
[MJSONWP] Calling AppiumDriver.getText() with args: ["4","2360f77e-917e-401d-bb65-fc8ab03a8da3"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:getText","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: getText
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":"RECORDING... PRESS TO STOP","status":0}
[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.getText() result: "RECORDING... PRESS TO STOP"
[HTTP] <-- GET /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/4/text 200 42 ms - 100 
[HTTP] --> POST /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/4/click 
[MJSONWP] Calling AppiumDriver.click() with args: ["4","2360f77e-917e-401d-bb65-fc8ab03a8da3"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click
[debug] [AndroidBootstrap] Received command result from bootstrap
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":true,"status":0}
[MJSONWP] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/4/click 200 696 ms - 76 
[HTTP] --> POST /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element 
[MJSONWP] Calling AppiumDriver.findElement() with args: ["id","Btn_Save","2360f77e-917e-401d-bb65-fc8ab03a8da3"]
[debug] [BaseDriver] Waiting up to 15000 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"Btn_Save","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"Btn_Save","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding Btn_Save using ID with the contextId:  multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.prueba.maverick:id/Btn_Save]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":{"ELEMENT":"5"},"status":0}
[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"5"}
[HTTP] <-- POST /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element 200 27 ms - 87 
[HTTP] --> POST /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/5/click 
[MJSONWP] Calling AppiumDriver.click() with args: ["5","2360f77e-917e-401d-bb65-fc8ab03a8da3"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"5"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"5"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":true,"status":0}
[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/2360f77e-917e-401d-bb65-fc8ab03a8da3/element/5/click 200 189 ms - 76 
[HTTP] --> POST /wd/hub/session 
[MJSONWP] Calling AppiumDriver.createSession() with args: [{"deviceName":"karthikphone1","app":"/home/karthik/appiumworkspace/tests/app-debug (8).apk","noReset":"true","app-wait-activity":".CommonViewActiv...
[Appium] Creating new AndroidDriver session
[Appium] Capabilities:
[Appium]   deviceName: 'karthikphone1'
[Appium]   app: '/home/karthik/appiumworkspace/tests/app-debug (8).apk'
[Appium]   noReset: 'true'
[Appium]   app-wait-activity: '.CommonViewActivity'
[Appium]   browserName: ''
[Appium]   fullReset: 'false'
[Appium]   platformVersion: '4.4.2'
[Appium]   appPackage: 'com.prueba.maverick'
[Appium]   platformName: 'Android'
[Appium]   app-activity: '.SplashActivity'
[HTTP] <-- POST /wd/hub/session 500 15 ms - 193 

Please help me..


Solution

  • On appium version 1.5 they changed the command line argument, you should now use it this way:

    appium --default-capabilities '{"noReset":true}'
    

    More info available on appium's websites: http://appium.io/docs/en/writing-running-appium/default-capabilities-arg/