如何在每次使用python在appium中运行测试时阻止app安装?

时间:2015-01-07 09:14:24

标签: android python appium

当我运行测试时,每次调用新的测试用例时,应用程序都会安装新的,我希望测试在已安装的应用程序上运行,我该怎么做? 或者至少每次使用appium运行测试时都会阻止应用重新安装?

我觉得很难,因为app有8页的欢迎屏幕,每次重新安装应用程序都必须编写代码,以便通过欢迎屏幕和欢迎消息进行刷卡。 这是我的代码

import os

from time import sleep


import unittest

from appium import webdriver


# Returns absolute path relative to this file and not cwd
    PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p))
class SimpleAndroidTests(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
#Specify platform below(Android, iOS)
        desired_caps['platformName'] = 'Android'
#Specify OS version(Settings->About phone -> android version)
        desired_caps['platformVersion'] = '4.4.4'
#Obtain the Device name from Adb[For Android](Terminal Command: "adb devices")
        desired_caps['deviceName'] = 'TA93304QZD'
#Specify the path to Application
        desired_caps['app'] = PATH('Media Drive-com.sandisk.scotti-55-v2.0.3.apk')

        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    def tearDown(self):
        # end the session
    self.driver.quit()

    def test_images_copy(self):
        self.driver.implicitly_wait(5)

        for i in range(0,4):
            self.driver.find_element_by_id("com.sandisk.scotti:id/txt_Next").click()
            self.driver.implicitly_wait(5)
        self.driver.find_element_by_id("com.sandisk.scotti:id/txt_Close").click()
        self.driver.implicitly_wait(5)
        self.driver.find_element_by_name("OK").click()
        self.driver.implicitly_wait(5)
        self.driver.find_element_by_id("com.sandisk.scotti:id/txt_Photo").click()
        self.driver.implicitly_wait(5)
        self.driver.find_element_by_id("com.sandisk.scotti:id/btn_Switch_Local").click()
        self.driver.implicitly_wait(5)
        self.driver.find_element_by_id("com.sandisk.scotti:id/txt_Name").click()
        self.driver.implicitly_wait(5)
if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(SimpleAndroidTests)
    unittest.TextTestRunner(verbosity=2).run(suite)

3 个答案:

答案 0 :(得分:6)

您还可以在大写字母中添加noReset:

desired_caps['noReset'] = True

答案 1 :(得分:4)

appium的--no-reset选项应该有帮助

答案 2 :(得分:2)

您也可以手动在设备上安装该应用,而不是使用desired_caps ['app']启动Appium,您只需传递包名称和第一个活动即可:

desired_caps['appPackage'] = 'com.acme.test'
desired_caps['appActivity'] = 'MyFirstActivity'