我目前正在尝试自动执行移动测试,并且想知道是否有任何方法可以定义不同的setup()方法(例如,具有不同的appPackage,appActivity)并在同一脚本中运行测试用例。 / p>
例如,我编写了以下代码,它将自动发送消息(appPackage为com.android.mms,appActivity为com.android.mms.ui.ConversationList)。但是在选择添加附件的选项后,我需要添加图片,然后将使用appPackage为com.android.documentsui和appActivity为com.android.documentsui.DocumentsActivity),这是在我的代码中case3下定义的操作
如何在同一脚本中处理此问题?预先感谢。
import os, sys
import glob
import unittest
from appium import webdriver
from time import sleep
PLATFORM_VERSION = '5.1.1'
class EntranceTests(unittest.TestCase):
def setUp(self):
print 'commandline args',sys.argv[1]
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1.1'
desired_caps['deviceName'] = 'android'
desired_caps['udid'] = sys.argv[1]
desired_caps['appPackage'] = 'com.android.mms'
desired_caps['appActivity'] = 'com.android.mms.ui.ConversationList'
url = "http://localhost:{}/wd/hub".format(sys.argv[2])
self.driver = webdriver.Remote(url, desired_caps)
def case2(self):
addmsg = self.driver.find_element_by_xpath('//android.widget.ImageButton[contains(@index, "0")]')
addmsg.click()
editreceiver = self.driver.find_element_by_id('com.android.mms:id/recipients_editor')
editreceiver.send_keys("0713414713")
message = self.driver.find_element_by_id('com.android.mms:id/embedded_text_editor_btnstyle')
message.send_keys("Test Message")
attachment = self.driver.find_element_by_id('com.android.mms:id/add_attachment_second')
attachment.click()
addpic = self.driver.find_element_by_xpath('//android.widget.TextView[contains(@text, "Pictures")]')
addpic.click()
sendmsg = self.driver.find_element_by_id('com.android.mms:id/first_send_button_sms_view')
sendmsg.click()
def case3(self):
pic = self.driver.find_element_by_xpath('//android.widget.ImageView[contains(@index, "0")]')
pic.click()
def testcase2(self):
self.case2()
self.case3()
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(EntranceTests)
unittest.TextTestRunner(verbosity=2).run(suite)
答案 0 :(得分:0)
要在应用之间切换,请使用start_activity()
。对于您的情况,它将是-
def case3(self):
pic = self.driver.find_element_by_xpath('//android.widget.ImageView[contains(@index, "0")]')
pic.click()
self.driver.start_activity("com.android.documentsui", "com.android.documentsui.DocumentsActivity")
#do soemthing in the new app