*** Settings *** Library urllib3 Library String Library DateTime Library Collections Library RequestsLibrary Library DatabaseLibrary Library OperatingSystem Library ImageHorizonLibrary *** Keywords *** 读取TXT文件 #读取TXT文件 ${file} Get File ${CURDIR}\\phone-test.txt #读取文件 ${skip-line} Set Variable 1 #跳过第一行 ${lines} Set Variable -1 #读取整个文件,从第二行开始 ${content} Get Lines Containing String ${file} ${skip-line} ${lines} FOR ${id} IN ${content} ${id} String.Split String ${id} \n END Set Global Variable ${id} 生成随机手机号 ${phoneList} Create List ${phoneList} Create List ${num} Evaluate random.choice(["139","188","185","136","158","151","132","156","189","187","135","134"]) random ${number} Evaluate "".join(random.sample("01234567897",8)) random,string ${phone} Evaluate ${num}${number} Append To List ${phoneList} ${phone} Set Global Variable ${phoneList} 写入数据到txt文件 ${file_path} Set Variable ${EXECDIR}\\Phone.txt Append To File ${file_path} ${phone},888888\n 游客登录${dating}平台 #游客登录婚介平台 Disable Warnings Create Session dating ${${dating}.dating域名} ${${dating}.CHeader} ${reps} GET On Session dating /dating-agency-service/user/get/marriage-information/tourist-recommend ${message} Get From Dictionary ${reps.json()} message Should Be Equal As Strings ${message} successful 用户获取${dating}平台短信验证码 #用户获取婚介平台短信验证码 Disable Warnings FOR ${account} IN @{id} Create Session dating ${${dating}.dating域名} ${${dating}.AHeader} ${data} Set Variable { \ \ \ \ "purpose": 1, \ \ \ \ "verifiableAccount": "${account}", \ \ \ \ "verifiableAccountType": 1 } #获取短信验证码请求参数 ${reps} POST On Session dating /dating-agency-uec/authorize/get/auth-captcha ${data.encode('utf-8')} ${message} Get From Dictionary ${reps.json()} message #获取接口相应的message END Should Be Equal As Strings ${message} successful #断言是否相等 Sleep 2 数据库查询用户生效且未过期的验证码 #数据库中查询手机号验证码 ${captcha_list} Create List FOR ${account} IN @{id} ${Time} Get Current Date result_format=%Y-%m-%d %H:%M:%S Connect To Database Using Custom Params pymysql database='dating_agency_uec',user='root',password='qniaothreetwoonego',host='8.135.8.221' ${check} Query SELECT code FROM da_captcha WHERE verifiable_account = '${account}' AND status = 1 AND is_delete = 0 AND expired_time > '${Time}' #查询手机号获取的验证码 ${captcha} Set Variable ${check[0][0]} Set Global Variable ${captcha} Append To List ${captcha_list} ${captcha} Disconnect From Database END Set Global Variable ${captcha_list} 数据库查询用户生效且已过期的验证码 #数据库中查询手机号验证码 ${captcha_list} Create List FOR ${account} IN @{id} ${Time} Get Current Date result_format=%Y-%m-%d %H:%M:%S Connect To Database Using Custom Params pymysql database='dating_agency_uec',user='root',password='qniaothreetwoonego',host='8.135.8.221' ${check} Query SELECT code FROM da_captcha WHERE verifiable_account = '${account}' AND status = 1 AND is_delete = 0 AND expired_time < '${Time}' #查询手机号获取的验证码 ${captcha} Set Variable ${check[0][0]} Append To List ${captcha_list} ${captcha} Disconnect From Database END Set Global Variable ${captcha} Set Global Variable ${captcha_list} 用户手机号验证码登录${dating}平台 #用户手机号验证码登录婚介平台 ${userid_list} Create List ${Cheader_list} Create List ${Aheader_list} Create List FOR ${account} ${captcha} IN ZIP ${id} ${captcha_list} Disable Warnings Create Session dating ${${dating}.dating域名} ${${dating}.AHeader} ${data} Set Variable { \ \ "account":"${account}", \ \ "accountType":2, \ \ "captcha":"${captcha}" } #手机号验证码登录参数 ${reps} POST On Session dating /dating-agency-uec/authorize/by-captcha ${data.encode('utf-8')} ${code} Get From Dictionary ${reps.json()} code #获取相应状态码 ${token} Get From Dictionary ${reps.json()['data']} token #获取token ${userId} Get From Dictionary ${reps.json()['data']} userId #获取用户id ${message} Get From Dictionary ${reps.json()} message ${login_header} Set Variable {'Content-Type':'application/json','X-APP-ID':'50325897884795881','Authorization':'QNT ${token}'} #更新header ${client_header} Set Variable {'Content-Type':'application/json','X-APP-ID':'50325897884795880','Authorization':'QNT ${token}'} Append To List ${userid_list} ${userId} Append To List ${Cheader_list} ${client_header} Append To List ${Aheader_list} ${login_header} Run Keyword If ${code}==0 Should Be Equal As Strings ${message} successful ... ELSE Should Be Equal As Strings ${message} 验证码错误或无效验证码,请重试! END Set Global Variable ${userid_list} Set Global Variable ${Aheader_list} Set Global Variable ${Cheader_list} Set Global Variable ${login_header} Set Global Variable ${client_header} 用户手机号验证码登录${dating}平台-888888 #用户手机号验证码登录婚介平台 ${userid_list} Create List ${Cheader_list} Create List ${Aheader_list} Create List ${phoneList} Create List FOR ${account} IN @{id} Disable Warnings Create Session dating ${${dating}.dating域名} ${${dating}.AHeader} ${data} Set Variable { \ \ "account":"${account}", \ \ "accountType":2, \ \ "captcha":888888 } #手机号验证码登录参数 ${reps} POST On Session dating /dating-agency-uec/authorize/by-captcha ${data.encode('utf-8')} ${code} Get From Dictionary ${reps.json()} code #获取相应状态码 ${token} Get From Dictionary ${reps.json()['data']} token #获取token ${userId} Get From Dictionary ${reps.json()['data']} userId #获取用户id ${message} Get From Dictionary ${reps.json()} message ${login_header} Set Variable {'Content-Type':'application/json','X-APP-ID':'50325897884795881','Authorization':'QNT ${token}','X-Organization-Id':'963432943739605555'} #更新header ${client_header} Set Variable {'Content-Type':'application/json','X-APP-ID':'50325897884795880','Authorization':'QNT ${token}'} Append To List ${userid_list} ${userId} Append To List ${Cheader_list} ${client_header} Append To List ${Aheader_list} ${login_header} Append To List ${phoneList} ${account} Run Keyword If ${code}==0 Should Be Equal As Strings ${message} successful ... ELSE Should Be Equal As Strings ${message} 验证码错误或无效验证码,请重试! END Set Global Variable ${phoneList} Set Global Variable ${userid_list} Set Global Variable ${Aheader_list} Set Global Variable ${Cheader_list} Set Global Variable ${login_header} Set Global Variable ${client_header} 用户手机号验证码登录${dating}平台-phone #用户手机号验证码登录婚介平台 ${userid_list} Create List ${Cheader_list} Create List ${Aheader_list} Create List ${phoneList} Create List Disable Warnings FOR ${phone} IN @{phoneList} Create Session dating ${${dating}.dating域名} ${${dating}.AHeader} ${data} Set Variable { \ \ "account":"${phone}", \ \ "accountType":2, \ \ "captcha":888888 } #手机号验证码登录参数 ${reps} POST On Session dating /dating-agency-uec/authorize/by-captcha ${data.encode('utf-8')} ${code} Get From Dictionary ${reps.json()} code #获取相应状态码 ${token} Get From Dictionary ${reps.json()['data']} token #获取token ${userId} Get From Dictionary ${reps.json()['data']} userId #获取用户id ${message} Get From Dictionary ${reps.json()} message ${login_header} Set Variable {'Content-Type':'application/json','X-APP-ID':'50325897884795881','Authorization':'QNT ${token}','X-Organization-Id':'963432943739605555'} #更新header ${client_header} Set Variable {'Content-Type':'application/json','X-APP-ID':'50325897884795880','Authorization':'QNT ${token}'} Append To List ${userid_list} ${userId} Append To List ${Cheader_list} ${client_header} Append To List ${Aheader_list} ${login_header} Append To List ${phoneList} ${phone} Run Keyword If ${code}==0 Should Be Equal As Strings ${message} successful ... ELSE Should Be Equal As Strings ${message} 验证码错误或无效验证码,请重试! END Set Global Variable ${phoneList} Set Global Variable ${userid_list} Set Global Variable ${Aheader_list} Set Global Variable ${Cheader_list} Set Global Variable ${login_header} Set Global Variable ${client_header} 用户手机号错误验证码登录${dating}平台 #用户手机号验证码登录婚介平台 FOR ${account} IN @{id} Disable Warnings Create Session dating ${${dating}.dating域名} ${${dating}.AHeader} ${data} Set Variable { \ \ "account":"${account}", \ \ "accountType":2, \ \ "captcha":"${captcha}" } #手机号验证码登录参数 ${reps} POST On Session dating /dating-agency-uec/authorize/by-captcha ${data.encode('utf-8')} ${code} Get From Dictionary ${reps.json()} code #获取相应状态码 ${message} Get From Dictionary ${reps.json()} message Run Keyword If ${code}==0 Should Be Equal As Strings ${message} successful ... ELSE Should Be Equal As Strings ${message} 验证码错误或无效验证码,请重试! END 查询用户的${dating}组织 #查询用户在婚介的组织数据 ${Aheader} Create List FOR ${userId} ${login_header} IN ZIP ${userid_list} ${Aheader_list} Disable Warnings Create Session dating ${${dating}.dating域名} ${login_header} ${reps} GET On Session dating /dating-agency-uec/user/list/own-organization params=userId=${userid} ${data} Get From Dictionary ${reps.json()} data #获取用户组织数据 ${message} Get From Dictionary ${reps.json()} message Should Be Equal As Strings ${message} successful Run Keyword If ${data}==[] log 未获取到组织信息! ... ELSE log ${data} END 获取${dating}平台用户baseinfo #获取baseinfo FOR ${admin_header} IN @{Aheader_list} Create Session dating ${${dating}.dating域名} ${admin_header} ${reps} GET On Session dating dating-agency-uec/user/get/base-info ${phone} Get From Dictionary ${reps.json()['data']} phone #登录用户手机号 ${matchmakerFlag} Get From Dictionary ${reps.json()['data']} matchmakerFlag #登录用户是否是红娘 END Set Global Variable ${phone} Set Global Variable ${matchmakerFlag} 扫描${dating}红娘二维码 #解析二维码图片 #${filepath} Evaluate open('./matchmaker.png','rb') FOR ${client_header} IN @{Cheader_list} Create Session dating ${${dating}.dating域名} ${client_header} ${reps} GET On Session dating dating-agency-uec/user/verify/qrcode params=&qrCodeRecordId=972626840957095936 ${code} Get From Dictionary ${reps.json()} code END 获取${dating}平台用户baseinfo并判断是否是红娘 #获取baseinfo FOR ${admin_header} IN @{Aheader_list} Create Session dating ${${dating}.dating域名} ${admin_header} ${reps} GET On Session dating dating-agency-uec/user/get/base-info ${phone} Get From Dictionary ${reps.json()['data']} phone #登录用户手机号 ${matchmakerFlag} Get From Dictionary ${reps.json()['data']} matchmakerFlag #登录用户是否是红娘 Run Keyword If ${matchmakerFlag}==False 注册婚介红娘 ... ELSE 查询婚介平台红娘列表 END Set Global Variable ${phone} Set Global Variable ${matchmakerFlag} 注册${dating}红娘 #注册成为红娘 FOR ${client_header} IN @{Cheader_list} Create Session dating ${${dating}.dating域名} ${client_header} ${reps} POST On Session dating dating-agency-uec/user/create/matchmaker ${matchmakerId} Get From Dictionary ${reps.json()} data ${message} Get From Dictionary ${reps.json()} message Should Be Equal As Strings ${message} successful END 查询${dating}平台红娘列表 FOR ${admin_header} IN @{Aheader_list} Create Session dating ${${dating}.dating域名} ${admin_header} ${reps} GET On Session dating dating-agency-uec/user/page/matchmaker params=pageSize=10&pageNum=1 ${matchmaker_list} Get From Dictionary ${reps.json()['data']} records #红娘列表 Set Global Variable ${matchmaker_list} 红娘列表 END 红娘列表 FOR ${matchmaker} IN @{matchmaker_list} ${PhoneNum} Get From Dictionary ${matchmaker} phone Exit For Loop If ${PhoneNum}==${phone} END Set Global Variable ${PhoneNum} 数据库删除用户数据 FOR ${userId} IN @{userid_list} Connect To Database Using Custom Params pymysql database='dating_agency_uec',user='root',password='qniaothreetwoonego',host='8.135.8.221' ${update_account} Execute Sql String UPDATE da_account \ SET is_delete=1 WHERE user_id='${userId}' ${update_user} Execute Sql String UPDATE da_user \ SET is_delete=1 WHERE id='${userId}' Disconnect From Database END 创建一个列表 ${result} Create List 4 5 6 ${pid_list} Create List 7 8 9 Set Global Variable ${result} Set Global Variable ${pid_list} 同时执行多个参数的FOR循环 ${id-list} Create List 1 2 FOR ${id} ${pid} ${i} IN ZIP ${id-list} ${pid_list} ${result} ${data} Set Variable { \ \ \ \ "id": "${id}", \ \ \ \ "result": "${i}", \ \ \ \ "pid": "${pid}" } END ${tempdir} Set Variable ${EXECDIR} #获取脚本执行路径 FOR循环 ${L1} Create List {'c':3} FOR ${i} IN @{L1} ${output} Set Variable {'item':${data}} END