| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #encoding:utf-8
- import os
- import time
- import unittest
- from time import sleep
- from appium import webdriver
- PATH = lambda p: os.path.abspath(
- os.path.join(os.path.dirname(__file__), p)
- )
- class TongyinPerson(unittest.TestCase):
- appcount=1
- def setUp(self):
- print '\n-------- Prepare To Start --------'
- desired_caps = {}
- desired_caps['platformName'] = 'Android'
- desired_caps['platformVersion'] = '6.0'
- desired_caps['deviceName'] = 'M9N7N15104001905'
- #desired_caps['app'] = PATH('./hjy-family-3.1.3.apk')
- desired_caps['appPackage'] = ''
- desired_caps['appActivity'] = 'com.djt.personreadbean.login.StartAnimalAct'
- desired_caps['unicodeKeyboard'] = True
- desired_caps['resetKeyboard'] = True
-
- self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
- def test_script(self):
- sleep(4)
- timepoint = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
- app_num=['15310000001','1531123456789','15310000001','15899999991']
- app_pwd=['000001','123456','1','999991']
- for i in range(4):
- num=app_num[i]
- pwd=app_pwd[i]
- try:
- print '\n-------- %d time(s) Running... --------'%TongyinPerson.appcount
- textfields = self.driver.find_elements_by_class_name("android.widget.EditText")
- textfields[0].send_keys(num)
- textfields[1].send_keys(pwd)
- sleep(1)
- print 'note:the account is :',num,' ,the password is :',pwd
- sleep(1)
- self.driver.find_element_by_id("com.djt.personreadbean:id/btn_login").click()
- self.driver.get_screenshot_as_file("E:\\report\\screenshot\\screen_"+timepoint+".png")
- except:
- print '-------- Have been logged! --------'
- self.driver.get_screenshot_as_file("E:\\report\\screenshot\\log_screen_"+timepoint+".png")
- try:#判断宝贝
- sleep(1)
- self.driver.find_element_by_xpath("//android.widget.RelativeLayout/android.widget.ListView/android.widget.RelativeLayout[2]").click()
- sleep(1)
- except:
- print '------ Only one Baby ------'
- sleep(6)
- try:
- sleep(3)
- self.driver.find_element_by_name(u"更多").click()
- sleep(2)
- self.driver.find_element_by_name(u"注销").click()
- sleep(2)
- self.driver.find_element_by_name(u"是").click()
- sleep(8)
- except:
- print '-------- account or password is wrong! --------'
- print '-------- Please sign in first --------'
- print '-------- OVER --------\n'
- TongyinPerson.appcount += 1
- self.driver.quit()
-
- if __name__ == '__main__':
- suite=unittest.TestSuite()
- suite.addTest(TongyinPerson("test_script"))
- timestr = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
- filename="E:\\report\\report_"+timestr+".html"
- fp = file(filename,"wb")
- runner = Demo.HTMLTestRunner(stream=fp, title=u'登录测试报告', description=u'测试用例详情')
- runner.run(suite)
- fp.close()
|