【问题标题】:How to prevent app from re-installing each time when I run tests in appium using python每次我使用python在appium中运行测试时如何防止应用程序重新安装
【发布时间】:2016-07-11 16:25:48
【问题描述】:

我为 Android 应用程序自动化测试编写了 python 测试套件。这套衣服有多个测试用例。我现在只放了2个。

问题在于,在每个测试用例之后,应用程序都会被卸载,然后重新安装。每个测试用例都会发生这种情况。 卸载并重新安装需要花费很多时间..

我使用的Appium版本是1.5.0

我尝试过使用:

desired_caps['noReset'] = 'true'

desired_caps['fullReset'] = 'false'

appium --no-reset

但是,没有用..

这是我的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)

我已经在拆卸函数中注释了退出语句..

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

[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 

请帮帮我..

【问题讨论】:

    标签: android python automation appium test-suite


    【解决方案1】:

    在 appium 1.5 版中,他们更改了命令行参数,您现在应该这样使用它:

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

    更多信息请访问 appium 网站: http://appium.io/docs/en/writing-running-appium/default-capabilities-arg/

    【讨论】:

    • 我什至在设置函数中声明了noReset = true.. 那不行吗??
    【解决方案2】:

    在每个测试用例之前注释这个,

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

    并且仅在最后一个测试用例结束时运行它。因为这会杀死 appium 会话

    【讨论】:

    • test_on_play_and_pause(self)' and test_indefinite_times_Pausing_and_Unpausing(self)' 是 2 个测试用例。对吗?!
    • def tearDown(self) 在我的测试服中只使用了一次。在测试服的末尾只有一个teardown 方法..
    • 它会卸载应用程序,如果它之前存在的话。在测试test_on_play_and_pause(self) 时它会安装应用程序,在测试后它会卸载应用程序。再次安装并测试 test_indefinite_times_Pausing_and_Unpausing(self) 。在此之后测试结束..
    • 我现在没有笔记本..我会在星期二拿回来..我会按照你说的去做,看看会发生什么..还是谢谢..:)
    • 如果我删除退出功能代码,我会收到错误,说WebDriverException: Message: A new session could not be created. Details: Problem getting session data for driver type AndroidDriver; does it implement 'get driverData'?
    猜你喜欢
    • 1970-01-01
    • 2018-03-12
    • 1970-01-01
    • 2014-11-28
    • 2019-11-26
    • 2023-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多