def test01_tender_done(self): # 1、注册图片验证码接口 self.reg_login.api_get_img_code(123123) # 2、注册手机验证码 self.reg_login.api_get_sms_code("13600001111", "8888") # 3、注册 r = self.reg_login.api_post_register("13600001111", "test123", "8888", "666666", None) print("-->>>>>注册:", r.json()) # 4、登录 r = self.reg_login.api_post_login("13600001111", "test123") print("-->>>>>登录:",r.json()) # 5、请求开户 result = ApiGet.get_apitrust(self.session).api_trust_register() # 6、三方开户 r = html_parser(result) self.session.post(r[0], r[1]) # 7、获取充值验证码 ApiGet.get_apitrust(self.session).api_trust_verify_code() # 8、请求充值 result = ApiGet.get_apitrust(self.session).api_trust_recharge(1000, 8888) r = html_parser(result) self.session.post(r[0], r[1]) # 9、请求投资 r = ApiGet.get_apitender(self.session).api_tender() # 10、三方投资 r = html_parser(result) result = self.session.post(r[0], r[1]) assert "OK" in result.text
def get_fengyun_words(): words_list = [] fengyun_res = util.get_html_text(baidu_fengyun_url) # 得到实时热点关键词 now_hot_words = util.html_parser( fengyun_res, '//*[@id="hot-list"]/li/a[@class="list-title"]/text()') words_list = words_list + now_hot_words # 得到七日关注热词 seven_day_words = util.html_parser( fengyun_res, '//*[@id="main"]/div[1]/div[1]/div[3]/div[2]/ul/li/a[@class="list-title"]/text()' ) words_list = words_list + seven_day_words # 得到今日上榜热词 new_hot_words_tmp = util.html_parser( fengyun_res, '//*[@id="flip-list"]/div[1]/div/div/a/text()') new_hot_words = [] for one_word in new_hot_words_tmp: new_one_word = str(one_word).strip() new_hot_words.append(new_one_word) words_list = words_list + new_hot_words # 得到民生热点词 man_life_words = util.html_parser( fengyun_res, '//*[@id="box-cont"]/div[4]/div[2]/div/div[2]/div[1]/ul/li/div[1]/a[@class="list-title"]/text()' ) words_list = words_list + man_life_words # 得到热门搜索 hot_search_words = util.html_parser( fengyun_res, '//*[@id="box-cont"]/div[8]/div[2]/div/div[2]/div[1]/ul/li/div[1]/a[@class="list-title"]/text()' ) words_list = words_list + hot_search_words words_set = set(words_list) return words_set
def test03_trust_recharge(self, amount, img_code, expect_msg): # 调用 充值验证码 self.trust.api_trust_verify_code() # 调用 充值接口 result = self.trust.api_trust_recharge(amount, img_code) if expect_msg == "OK": # html提取 r = html_parser(result) # 3、三方充值 result = self.session.post(url=r[0], data=r[1]) try: # 断言 assert expect_msg in result.text log.info("断言充值成功,断言信息:{} 实际结果为:{}".format( expect_msg, result.text)) except Exception as e: log.error(e) raise else: try: # 断言 common_assert(result, expect_msg=expect_msg) log.info("断言充值成功,断言信息:{} 实际结果为:{}".format( expect_msg, result.text)) except Exception as e: log.error(e) raise
def search_hot_words(one_hot_word): new_url = baidu_url + one_hot_word html_text = util.get_html_text(new_url) # 获取百度快照url href_list = util.html_parser( html_text, '//div[@class="result c-container "]/div[@class="f13"]/a[@class="m"]/@href' ) return href_list
def get_article_by_href(one_href): article_html = util.get_html_text(one_href) # 获取文章标题 article_title = util.html_parser(article_html, '//*[@id="article"]/div[1]/h2/text()') # 获取文章的内容 article_content = util.html_parser(article_html, '//p/span[@class="bjh-p"]/text()') # 获取文章的图片 article_imgs = util.html_parser(article_html, '//div[@class="img-container"]/img/@src') if article_title and article_content: tmp = {} tmp["title"] = article_title[0] tmp["desc"] = article_content[0] tmp["content"] = article_content tmp['imgs'] = article_imgs return tmp else: return 0
def test02_tender_public(self, expect_msg): # 1、调用投资 result = self.tender.api_tender() # 2、提取html r = html_parser(result) # 3、请求三方接口 result = self.session.post(r[0], r[1]) try: # 4、断言 assert expect_msg in result.text log.info("断言成功!预期结果:{} 实际结果:{}".format(expect_msg, result.text)) except Exception as e: log.error(e) raise
def test01_trust_register(self, expect_msg): # 1、调用开户 result = self.trust.api_trust_register() # 2、开户结果断言 form print("开户结果为:", result.json()) r = html_parser(result) # 3、请求三方开户 result = self.session.post(url=r[0], data=r[1]) try: # 4、三方开户结果断言 assert expect_msg in result.text except Exception as e: # 日志 log.error(e) # 抛异常 raise
def search_baijia_articles(one_word): new_url = baidu_url + one_word + "%20百家号" html_str = util.get_html_text(new_url) href_res = util.html_parser( html_str, '//div[@class="result c-container "]/h3[@class="t"]/a/@href') return href_res