本文目录一览:
php+ajax检测用户名只能检测英文 中文却检测不了 怎么回事
有可能的原因是页面编码和php编码不同。
可以使用js的encodeURIComponent 对要检测的字符进行编码再传递
有用记得采纳
python http接口测试脚本怎么写
1. 用Python封装被测试接口,对于HTTP接口我们通常会采用 GET和POST 2种调用方式去访问,所以必须把这2种方式都封装进去
# -*- coding:gb2312 -*-
import urllib2,urllib
”’
函数说明:url 特殊字符编码转换
作者:xiaonan
输入参数:待转换的字符串数据
输出参数:转换完成后的字符串数据
”’
def urlcode(data):
return urllib2.quote(str(data))
”’
函数说明:获取用户信息的API接口
作者:xiaonan
输入参数:用户名(uname),HTTP接口调用方式(GET或者POST)
输出参数:HTTP接口调用返回数据
”’
def GetUserInfo(uname,method):
if method == ‘GET’:
url = ”+urlcode(uname)
result = urllib2.urlopen(url).read()
return result
if method == ‘POST’:
url = ”
values = {‘uname’ : uname}
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
result = response.read()
return result
2. 编写、组织测试脚本, 准备测试数据
根据Testcase的具体业务逻辑用事先准备好的测试数据去调用封装好的API接口,验证实际返回结果是否与预期返回结果一致.
测试数据可以以各种形式存放,如Excel数据表:
TestCaseName uname method Expected Result
TestCase1 aaaa GET ….
TestCase2 aaaa POST ….
TestCase3 bbbb GET ….
… … … ….
# -*- coding:gb2312 -*-
import xlrd
”’
函数说明: Testcase 脚本
作者:xiaonan
输入参数:测试数据,API接口
输出参数:测试日志,测试报告
”’
def GetUser():
bk = xlrd.open_workbook(excel文件名称) # 打开excel文件
sh = bk.sheet_by_name(excel表名)# 打开excel表
nrows = sh.nrows # 获取总行数
for i in range(1,nrows):
TestCase = sh.cell_value(i,0)
uname = sh.cell_value(i,1)
method = sh.cell_value(i,2)
EX_Result=sh.cell_value(i,3)
WriterLog(‘Testcase Name:’+TestCase+’TestData: uname = ‘+uname+’ ,method = ‘+method+’ ,EX_Result = ‘ + ,EX_Result) # 写测试日志
AC_result = GetUserInfo(uname,method) # 调用API接口
WriterLog(‘AC_result = ‘ + AC_result) # 写测试日志
if EX_Result == AC_result: #实际结果与预期结果对比
WriterLog(…) #写测试日志
WriterReport(…)#写测试报告
else
WriterLog(…)#写测试日志
WriterReport(…)#写测试报告
3. 组织测试套,用驱动文件去调用执行所有测试套件,完成相关测试,并生成测试日志及测试报告.
# -*- coding:gb2312 -*-
”’
函数说明: Testsuit Driver驱动脚本
作者:xiaonan
输入参数:TestCase 脚本
输出参数:测试日志,测试报告
”’
if __name__ == ‘__main__’:
…
WriterLog() #写测试日志
GetUser() # TestCase 脚本
…
…
Report(….) # 统计汇总所有测试报告数据,以文件或页面形式呈现.
4. 执行测试脚本,分析测试结果. 根据测试报告,如果有Bug则提交.
js脚本+flash 图片轮播问题
看看在JS转义一下行不行,实在不行就把链接地址,转换成urlcode码,然后在解码,就可以了。
原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/180149.html