class DenpdentData(): def __init__(self,caseid): self.caseid = caseid self.grdata = GetRunData() self.dpmethod = Method() self.opera_xls = OperationExcel() def run_dapent(self): dprow = self.opera_xls.get_depent_rows(self.caseid) opera_json = OperationJson('../data/xxcookies.json') cookie = opera_json.GetData("PHPSESSID") dpcookies = {"PHPSESSID":cookie} dpurl = self.grdata.get_run_url(dprow) dprequests_way = self.grdata.get_run_requests_way(dprow) dpheader = self.grdata.get_run_headers_for_json(dprow) # dpcookies = self.grdata.get_run_cookie(dprow) dpdata = self.grdata.get_run_data_for_json(dprow) print(dpcookies) dpres = self.dpmethod.MainWay(dprequests_way,dpurl,cookies=dpcookies,data=dpdata,headers=dpheader) return dpres.text def get_data_for_key(self,row): depend_data = self.grdata.get_run_data_depend(row) response_data = self.run_dapent() r = BeautifulSoup(response_data,"html.parser") dp_data = r.find_all('div',depend_data)[0].string dp_data = re.split(r' +',dp_data)[1] # 寻渔记-日照铭万网络科技有限公司版权所有 dp_data = dp_data.strip() #寻渔记-日照铭万网络科技有限公司版权所有 鲁公网安备 37110302000118号 鲁ICP备17003630号-1 return dp_data
class RunMain(): def __init__(self): self.grd = GetRunData() self.method = Method() self.ascontain = IsContain() self.smail = SendMail() def GoOnRun(self): pass_count = [] fail_count = [] rows_count = self.grd.get_row_count() for i in range(1, rows_count): is_run = self.grd.get_run_is(i) if is_run: url = self.grd.get_run_url(i) requests_way = self.grd.get_run_requests_way(i) header = self.grd.get_run_headers_for_json(i) cookie = self.grd.get_run_cookie(i) data = self.grd.get_run_data_for_json(i) expect = self.grd.get_run_expect(i) caseid = self.grd.get_run_case_depend(i) depent_data = self.grd.get_run_data_depend(i) field_data = self.grd.get_run_field_depend(i) print( '=======================================现在第%s行分割线======================================' % i) if cookie == 'write': res = self.method.MainWay(requests_way, url, headers=header) opera_cok = OperationCookies(res) opera_cok.write_cookies() print('==========写入成功==========') else: opera_json = OperationJson('../data/xxcookies.json') cookie = opera_json.GetData("PHPSESSID") cookies = {"PHPSESSID": cookie} if caseid != None: dp = DenpdentData(caseid) dp_data = dp.get_data_for_key(i) data[field_data] = dp_data print('1:%s,2.%s,3.%s,4.%s' % (caseid, depent_data, field_data, dp_data)) print('=' * 80) print(data) res = self.method.MainWay(requests_way, url, cookies=cookies, data=data, headers=header).text else: res = self.method.MainWay(requests_way, url, cookies=cookies, data=data, headers=header).text if self.ascontain.is_contain(expect, res): print('pass') self.grd.write_result_data(i, 'pass') pass_count.append(i) else: print('fail') self.grd.write_result_data(i, 'fail') fail_count.append(i) self.smail.send_mail(pass_count, fail_count)