appium自动化测试(4)部分方法&unitest初步使用

捕捉弹窗 https://github.com/appium/appium/issues/968完整有截屏的例子:https://github.com/bitbar/testdroid-samples/blob/master/appium/sample-scripts/python/testdroid_android_hybrid.py有详细解释的例子:http://www.cnblogs.com/fnng/p/3300788.html

1、unittest
2、截屏并保存driver.save_screenshot("F:/testSpace/unittest0/1.png")

2、setUpClass方法实现,一次性设置3、中文编码:文件头添加 #coding:utf-8

完整登陆&退出用例:
  1. #coding:utf-8
  2. ## XX_login_logout_testcase
  3. import unittest
  4. import time
  5. from appium import webdriver
  6.  
  7. classLoginTestCase(unittest.TestCase):
  8. @classmethod
  9. def setUpClass(cls):
  10. print("------------------setUp Test-----------------------")
  11. desired_caps ={}
  12. desired_caps['platformName']='Android'
  13. desired_caps['platformVersion']='4.4.4'
  14. desired_caps['deviceName']='Android Emulator'
  15. desired_caps['appPackage']='com.XX.activity'
  16. desired_caps['appActivity']='.AppStartActivity'
  17. desired_caps['unicodeKeyboard']=True
  18. desired_caps['resetKeyboard']=True
  19. cls.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
  20. @classmethod
  21. def tearDownClass(cls):
  22. cls.driver.close_app()
  23. cls.driver.quit()
  24. print("-------------------- Byebye ----------------------- ")
  25. def setUp(self):
  26. print("setup")
  27. def tearDown(self):
  28. print("teardown")
  29. def test1_log_in(self):
  30. time.sleep(5)
  31. # wait for the log advertise
  32. self.driver.find_element_by_name(u"我的").click()
  33. self.driver.find_element_by_id('com.XX.activity:id/tv_userheadloginfail_login').click()# 点击登陆
  34. # log by phone number and password
  35. self.driver.find_element_by_id('com.XX.activity:id/mobile_login').click()
  36. self.driver.find_element_by_id('android:id/text1').click()
  37. self.driver.find_element_by_id('com.XX.activity:id/edt_mobilenum').send_keys("13580478329")
  38. self.driver.find_element_by_id('com.XX.activity:id/edt_password').send_keys("1234567")
  39. self.driver.find_element_by_id('com.XX.activity:id/login').click()
  40. time.sleep(5)
  41. self.driver.save_screenshot("F:/testSpace/loginTestCase1/src/loginByPhoneNumber.png")
  42. print("login ok")
  43. def test2_log_out(self):
  44. # log out
  45. self.driver.find_element_by_name(u"我的").click()
  46. self.driver.find_element_by_id('com.XX.activity:id/rl_usercontent_setting').click()
  47. self.driver.find_element_by_id('com.XX.activity:id/exit').click()
  48. time.sleep(2)
  49. self.driver.find_element_by_id('android:id/button2').click()
  50. time.sleep(5)
  51. self.driver.save_screenshot("F:/testSpace/loginTestCase1/src/logout.png")
  52. print("log out ok")
  53. print("Test2 ok")
  54. if __name__ =='__name__':
  55. unittest.main()
 
 





附件列表

 

posted @ 2016-05-27 10:35  qing_keep  阅读(1374)  评论(0编辑  收藏  举报