login.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #encoding:utf-8
  2. import os
  3. import time
  4. import unittest
  5. from time import sleep
  6. from appium import webdriver
  7. PATH = lambda p: os.path.abspath(
  8. os.path.join(os.path.dirname(__file__), p)
  9. )
  10. class TongyinPerson(unittest.TestCase):
  11. appcount=1
  12. def setUp(self):
  13. print '\n-------- Prepare To Start --------'
  14. desired_caps = {}
  15. desired_caps['platformName'] = 'Android'
  16. desired_caps['platformVersion'] = '6.0'
  17. desired_caps['deviceName'] = 'M9N7N15104001905'
  18. #desired_caps['app'] = PATH('./hjy-family-3.1.3.apk')
  19. desired_caps['appPackage'] = ''
  20. desired_caps['appActivity'] = 'com.djt.personreadbean.login.StartAnimalAct'
  21. desired_caps['unicodeKeyboard'] = True
  22. desired_caps['resetKeyboard'] = True
  23. self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
  24. def test_script(self):
  25. sleep(4)
  26. timepoint = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
  27. app_num=['15310000001','1531123456789','15310000001','15899999991']
  28. app_pwd=['000001','123456','1','999991']
  29. for i in range(4):
  30. num=app_num[i]
  31. pwd=app_pwd[i]
  32. try:
  33. print '\n-------- %d time(s) Running... --------'%TongyinPerson.appcount
  34. textfields = self.driver.find_elements_by_class_name("android.widget.EditText")
  35. textfields[0].send_keys(num)
  36. textfields[1].send_keys(pwd)
  37. sleep(1)
  38. print 'note:the account is :',num,' ,the password is :',pwd
  39. sleep(1)
  40. self.driver.find_element_by_id("com.djt.personreadbean:id/btn_login").click()
  41. self.driver.get_screenshot_as_file("E:\\report\\screenshot\\screen_"+timepoint+".png")
  42. except:
  43. print '-------- Have been logged! --------'
  44. self.driver.get_screenshot_as_file("E:\\report\\screenshot\\log_screen_"+timepoint+".png")
  45. try:#判断宝贝
  46. sleep(1)
  47. self.driver.find_element_by_xpath("//android.widget.RelativeLayout/android.widget.ListView/android.widget.RelativeLayout[2]").click()
  48. sleep(1)
  49. except:
  50. print '------ Only one Baby ------'
  51. sleep(6)
  52. try:
  53. sleep(3)
  54. self.driver.find_element_by_name(u"更多").click()
  55. sleep(2)
  56. self.driver.find_element_by_name(u"注销").click()
  57. sleep(2)
  58. self.driver.find_element_by_name(u"是").click()
  59. sleep(8)
  60. except:
  61. print '-------- account or password is wrong! --------'
  62. print '-------- Please sign in first --------'
  63. print '-------- OVER --------\n'
  64. TongyinPerson.appcount += 1
  65. self.driver.quit()
  66. if __name__ == '__main__':
  67. suite=unittest.TestSuite()
  68. suite.addTest(TongyinPerson("test_script"))
  69. timestr = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
  70. filename="E:\\report\\report_"+timestr+".html"
  71. fp = file(filename,"wb")
  72. runner = Demo.HTMLTestRunner(stream=fp, title=u'登录测试报告', description=u'测试用例详情')
  73. runner.run(suite)
  74. fp.close()