执行 test_menu 断言时,一直报错【AssertionError: u'\u83dc\u5355' != u''
- \u83dc\u5355
+
】
大家帮忙看先 顺便指正下代码里的注释错误和可以优化的地方。
小白一个,在这里先感谢各位大大
#-*- coding:utf-8 -*-
import time
import os
import HTMLTestRunner
import unittest
from appium import webdriver
#创建一个测试用例类
class viaTest(unittest.TestCase):
#setUp()函数放置预配置
def setUp(self):
desired_caps = {
'platformName':'Android',#系统平台名字
'deviceName':'LGD859e63011d',#设备名字
'paltformVersion':'6.0',#系统版本号
'appPackage':'mark.via',#软件包名
'appActivity':'mark.via.ui.activity.BrowserActivity'#软件activity
}
self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)#启动软件
def tearDown(self):
self.driver.quit();#退出软件
def test_add(self):
#s1 = self.driver.find_element_by_id("mark.via:id/ar")#找到返回键
#s1.click()#点击返回键
#time.sleep(5)#延时5秒
s2 = self.driver.find_element_by_id("mark.via:id/aw").click()#找到窗口按钮,并点击
time.sleep(5)
s3 = self.driver.find_element_by_id("mark.via:id/ap").click()#点击“新建窗口”按钮
time.sleep(5)
if self.assertEqual("2",self.driver.find_element_by_name("2").text):#判断 断言结果,有异常抛出异常,否则pass
raise AssertionError
else:
print "Passed"
def test_menu(self):
time.sleep(5)
menu = self.driver.find_element_by_id("mark.via:id/ax").click()#点击菜单
if self.assertEqual(u"菜单",self.driver.find_element_by_accessibility_id("菜单").text):
raise AssertionError
else:
print "Passed"
"""
try:
self.assertEqual("3",self.driver.find_element_by_name("2").text)#获取当前窗口数量,断言窗口数量是否为2,如果为2就Pass,否则失败并抛出异常
print "Passed"
except Exception,e:
#print (Exception,":",e)
raise Exception
"""
if __name__=='__main__':
"""
suite = unittest.TestLoader().loadTestsFromTestCase(viaTest)
unittest.TextTestRunner(verbosity=2).run(suite)#这两句也请帮忙解释下
"""
suite = unittest.TestSuite()#定义一个单元测试容器
suite.addTest(viaTest('test_add'))#addTest添加case到suite容器中
suite.addTest(viaTest('test_menu'))
timestr = time.strftime('%Y-%m-%d',time.localtime(time.time()))#本地日期作为报告名字
filename = 'D:\\result\\' + timestr + '.html'#文件名字及保存路径
fq = open(filename,'w')
runner = HTMLTestRunner.HTMLTestRunner(
stream=fq,
title='result',
description='report'
)
for i in range(1,2):#循环执行次数
runner.run(suite)#执行case,并生成一份测试报告
i=i+1
fq.close()