title: How to run multiple test cases under one script while sharing different setup and teardown methods?
body: <p>I'm currently trying to do automate mobile testing and am wondering if there is any way that I can define different setup() methods (for example having different appPackage, appActivity) and run the test cases in the same script.</p>
  
  <p>For example, I have written the below code that it will automate sending a message (appPackage is com.android.mms and appActivity is com.android.mms.ui.ConversationList). But after selecting the option to add an attachment I need to add a picture which will then be using the appPackage is com.android.documentsui and appActivity is com.android.documentsui.DocumentsActivity), which is the action defined under case3 on my code.</p>
  
  <p>How can I handle this in the same script? Thanks in advance.</p>
  
  <pre><code>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)
  </code></pre>