简体   繁体   English

使用python在appium中运行测试时如何防止每次重新安装应用程序

[英]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 .我已经为Android App 的自动化测试编写了一个python 测试套件 There are multiple test cases in this suit.该套装中有多个测试用例。 I have put only 2 right now.我现在只放了2个。

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我使用的 Appium 版本是1.5.0

I have tried using :我试过使用:

desired_caps['noReset'] = 'true' required_caps['noReset'] = 'true'

desired_caps['fullReset'] = 'false' required_caps['fullReset'] = 'false'

and

appium --no-reset appium --no-reset

But, of no use..但是,没用。。

This is my python code file playpause.py :这是我的 python 代码文件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 : Python 终端错误消息:

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 Appium 终端错误信息

[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..请帮帮我..

On appium version 1.5 they changed the command line argument, you should now use it this way:在 appium 1.5 版中,他们更改了命令行参数,您现在应该这样使用它:

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

More info available on appium's websites: http://appium.io/docs/en/writing-running-appium/default-capabilities-arg/在 appium 的网站上提供更多信息: http ://appium.io/docs/en/writing-running-appium/default-capabilities-arg/

Comment this before each test case,在每个测试用例之前评论这个,

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

and run it only during the end of last test case.并仅在最后一个测试用例结束时运行它。 Since this will kill the appium session因为这会杀死 appium 会话

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 每当我在Windows机器上运行测试时,如何防止appium重新安装apk - How to prevent appium from re-installing apk each time when i run tests on windows machine 每当我使用python在appium中运行测试时,如何防止安装app? - How to prevent app from installing every time i run an test in appium using python? 通过重新安装App防止用户获取免费耗材 - Prevent User from Getting Free Consumables by Re-Installing App Android应用程序:如何防止用户重新安装先前安装并随后卸载的应用程序? - Android App: How to prevent a user from re-installing an app that was previously installed and afterwards uninstalled? 重新安装应用程序后如何保存共享偏好 (Android) - How to save Shared preference after re-installing the app (Android) 重新安装或更新时如何从Android应用程序中删除共享首选项文件? - How to delete the shared preference file from Android application when re-installing or updating? 如何在重新安装应用程序后从android应用程序中的资产中删除该文件? - How can i remove the file from assets in android application after re-installing the application? 每次在笔记本电脑上打开应用程序时都会重新安装 Android Studio - Android Studio re-installing every time I open the application on my laptop 如何使用Appium在真实设备上从jenkins安装* .apk并运行用python编写的测试? - How can I install *.apk from jenkins on real device with Appium and run tests written in python? 如何在不重新安装新应用程序的情况下附加到Eclipse中的Java进程? - how to attach to java process in eclipse without re-installing fresh app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM