RobotFramework 实战1——数据检查自动化

RobotFramework 实战1——数据检查自动化_第1张图片

RobotFramework 实战1——数据检查自动化_第2张图片

 

RobotFramework 实战1——数据检查自动化_第3张图片

 

RobotFramework 实战1——数据检查自动化_第4张图片

 

 

RobotFramework 实战1——数据检查自动化_第5张图片

 

 

RobotFramework 实战1——数据检查自动化_第6张图片

 

 

具体代码如下:

 

*** Settings ***
Suite Setup date_wsj
Library DatabaseLibrary
Resource ../../../flow.txt

*** Test Cases ***
001-App产品原创稿件阅读量-近1日
#计算出产品变量的个数
${proLen} get Length ${app}
#产品个数就是循环的次数
: FOR ${X} IN RANGE 0 ${proLen} 1
\ #查询出昨日的数值
\ ${original_read_cnt_yesterday} Query select product_name,original_read_cnt from edm_fact_cs_product_summary_d where product_type='APP'and product_name='${app[${X}]}' and summary_date>='${yesterday}'
\ #查询出条数(是list的形式)
\ ${qr} Query select product_name,original_read_cnt from edm_fact_cs_product_summary_d where product_type='APP'and product_name='${app[${X}]}' and original_read_cnt > '0'and summary_date>='${monthAgo}'
\ #将条数换成数值(获取list的长度,将list中的元素个数转换为数值)
\ ${len} Get Length ${qr}
\ #如果结果为0,继续执行
\ Continue For Loop If ${len}==0
\ #计算出平均值
\ ${original_read_cnt_Average} Query select product_name,sum(original_read_cnt) /${len} from edm_fact_cs_product_summary_d where product_type='APP'and product_name='${app[${X}]}' and original_read_cnt > '0'and summary_date>='${monthAgo}'group by product_name
\ #计算出最大值
\ ${Max_Average} Evaluate ${original_read_cnt_Average[0][1]}*2
\ #计算出最小值
\ ${Min_Average} Evaluate ${original_read_cnt_Average[0][1]}*0.7
\ #昨日值与最大值和最小值比较,若在这个范围内,则昨日数据正常
\ Run Keyword And Continue On Failure Should Be True ${Max_Average}>=${original_read_cnt_yesterday[0][1]}>=${Min_Average}
\ #打印日志(注意,list[x][y]的用法,此用例中sql查询结果均为list)
\ log ${qr[0]}:${Max_Average}>=${original_read_cnt_yesterday[0][1]}>=${Min_Average}

001-App产品原创稿件阅读量-近1周
${proLen} get Length ${app}
: FOR ${X} IN RANGE 0 ${proLen} 1
\ ${original_read_cnt_week} Query SELECT product_name,summary_start_date,summary_end_date,original_read_cnt FROM edm_fact_cs_product_summary_w where product_type='APP'and \ product_name='${app[${X}]}'and summary_end_date>='${weekAgo}'order by summary_start_date desc;
\ ${qr} Query SELECT product_name,summary_start_date,summary_end_date,original_read_cnt FROM edm_fact_cs_product_summary_w where product_type='APP'and \ product_name='${app[${X}]}'and original_read_cnt > '0'and summary_start_date>='${halfYearAgo}'order by summary_start_date desc;
\ ${len} Get Length ${qr}
\ Continue For Loop If ${len}==0
\ ${original_read_cnt_Average} Query select product_name,sum(original_read_cnt) /${len} from edm_fact_cs_product_summary_w where product_type='APP'and product_name='${app[${X}]}' and original_read_cnt > '0'and summary_start_date>='${halfYearAgo}'group by product_name
\ ${Max_Average} Evaluate ${original_read_cnt_Average[0][1]}*2
\ ${Min_Average} Evaluate ${original_read_cnt_Average[0][1]}*0.7
\ Run Keyword And Continue On Failure Should Be True ${Max_Average}>=${original_read_cnt_week[0][3]}>=${Min_Average}
\ log ${qr[0][0]}:${Max_Average}>=${original_read_cnt_week[0][3]}>=${Min_Average}

001-App产品原创稿件阅读量-近1月
${proLen} get Length ${app}
: FOR ${X} IN RANGE 0 ${proLen} 1
\ ${original_read_cnt_month} Query SELECT product_name,summary_start_date,summary_end_date,original_read_cnt FROM edm_fact_cs_product_summary_m where product_type='APP'and product_name='${app[${X}]}'and summary_end_date>='${monthAgo}'order by summary_start_date desc;
\ ${qr} Query SELECT product_name,summary_start_date,summary_end_date,original_read_cnt FROM edm_fact_cs_product_summary_m where product_type='APP'and product_name='${app[${X}]}'and original_read_cnt > '0'and summary_start_date>='${yearAgo}'order by summary_start_date desc;
\ ${len} Get Length ${qr}
\ Continue For Loop If ${len}==0
\ ${original_read_cnt_Average} Query select product_name,sum(original_read_cnt) /${len} from edm_fact_cs_product_summary_m where product_type='APP'and product_name='${app[${X}]}' and original_read_cnt > '0'and summary_start_date>='${yearAgo}'group by product_name
\ ${Max_Average} Evaluate ${original_read_cnt_Average[0][1]}*2
\ ${Min_Average} Evaluate ${original_read_cnt_Average[0][1]}*0.7
\ Run Keyword And Continue On Failure Should Be True ${Max_Average}>=${original_read_cnt_month[0][3]}>=${Min_Average}
\ log ${qr[0][0]}:${Max_Average}>=${original_read_cnt_month[0][3]}>=${Min_Average}

你可能感兴趣的:(RobotFramework 实战1——数据检查自动化)