本帖最后由 晓芳 于 2017-7-26 14:47 编辑
也不行,不知道怎么回事 就是没有报告完整代码:
#usr/bin/python
#encoding:utf-8
import time
import unittest
import HTMLTestRunner #引入 HTMLTestRunner 包
from appium import webdriver
from ddt import ddt, data, unpack
@ddt
class MyTestCase(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.2.2'
desired_caps['deviceName'] = '192.168.190.101:5551'
desired_caps['appPackage'] = 'com.yin'
desired_caps['appActivity'] = 'com.yin.activity.WelcomeActivity'
desired_caps["unicodeKeyboard"] = "True"
desired_caps["resetKeyboard"] = "True"
self.driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
time.sleep(5)
self.driver.find_element_by_name(u"我的").click()
time.sleep(5)
self.driver.find_element_by_name(u"立即登录").click()
@data(["xiao","1qaz",False],["xiao","123456",True])
@unpack
def testLogIn(self,username,password,expectedresult):
self.driver.find_element_by_name("请输入用户名/手机号").send_keys(username)
self.driver.find_element_by_name(username).click()
self.driver.find_element_by_xpath("//android.widget.EditText[contains(@NAF,'true')]").send_keys(password)
self.driver.find_element_by_class_name("android.widget.Button").click()
time.sleep(5)
try:
if self.driver.find_element_by_class_name("android.widget.Button").is_displayed():
exist = True
print("密码不正确,请重新输入")
except Exception,e:
exist = False
print("成功登录")
self.assertEqual(exist, expectedresult)
self.driver.find_element_by_xpath("//android.widget.ImageView[contains(@NAF,'true')]").click()
time.sleep(5)
self.driver.find_element_by_name(u"退出登录").click()
self.driver.find_element_by_name(u"确定").click()
def tearDown(self):
self.driver.quit()
if __name__ =="__main__":
#unittest.main()
mysuite = unittest.TestSuite()
mysuite.addTest(MyTestCase("testLoginIn"))
#mysuite.addTest(MyTestCase("testLogInOK"))
#myrunner = unittest.TextTestRunner(verbosity=2)
#timestr = time.strftime('%Y-%m-%d %X',time.localtime(time.time()))
#打开一个文件,将result写入此file中
filename="D:\\pyresult.html"
print(filename)
fp = open(filename,'wb')
#定义测试报告
runner =HTMLTestRunner(stream=fp,title=u'百度搜索测试报告',description=u'用例执行情况:')
#运行测试用例
runner.run(mysuite)
#关闭报告文件
fp.close()
|