def test_005_Guild_video_banner(self): """龖江湖-视频页顶部banner""" try: bbs_button = self.driver.find_element(By.ID, "jianghu") bbs_button.click() self.driver.implicitly_wait(10) time.sleep(0.5) content = PublicShell(self.driver).is_elementExits( By.ID, "topic_join_LinearLayout") # 首次进入提示 if content: alret_esc = self.driver.find_element_by_id("jorum_close_im") alret_esc.click() video = self.driver.find_element_by_id('select_tv_video') # 视频按钮 video.click() req = Four_Vesion_Api().findAdvertiseContent_260(position="P13") result = req.json()['appAdvertiseDtoList'] if len(result) != 0: banner_center = self.driver.find_element( By.ID, "bannerContainer") banner_image = self.driver.find_element( By.ID, "bannerViewPager") if len(result) > 1: # banner焦点图 banner_focus = self.driver.find_element( By.XPATH, '//*[contains(@resource-id,"circleIndicator")]') banner_focus_list = banner_focus.find_elements( By.CLASS_NAME, 'android.widget.ImageView') assert len(banner_focus_list) == len( result), u"首页banner广告数一致" for i in range(len(banner_focus_list)): banner_image.click() self.driver.implicitly_wait(1) if self.driver.current_activity == ".MainActivity": error_img = os.path.join(IMG_PATH, "home_banner_error.png") self.driver.save_screenshot(error_img) else: self.driver.back() x = banner_image.location["x"] y = banner_image.location["y"] + int( banner_image.size['height'] / 2) x1 = x + banner_image.size['width'] y1 = y self.driver.swipe(x, y, x1, y1) else: banner_image.click() if self.driver.current_activity == ".MainActivity": error_img = os.path.join(IMG_PATH, "home_banner_error.png") self.driver.save_screenshot(error_img) else: self.driver.back() except Exception as e: raise e
def test_004_search_collection(self, content): """搜索--藏品""" try: collection_button = self.driver.find_element(By.ID, "collection_radio_button") collection_button.click() self.driver.implicitly_wait(10) time.sleep(2) req = Four_Vesion_Api().searchLotPage_420(content) if req.json()['total'] == "0": is_error_toast = PublicShell(self.driver).is_elementExits(By.XPATH, "//*[contains(@text, '暂无相关藏品')]") assert is_error_toast == True else: resutlt = req.json()['rows'] search_list_view = self.driver.find_element_by_id('cn.dcpai.auction:id/search_result_list_view') search_list_view_size = search_list_view.size init_hight = search_list_view.location['y'] # 结果列表页左上方高度 results_list_view = search_list_view.find_elements(By.ID, 'lot_item_layout') one_view_size = results_list_view[0].size # 每个结果的尺寸大小 show_num = search_list_view_size['height'] / (one_view_size['height']+10) # 每页可见数量 show_num = round(show_num) # 可见列数(采用四舍五入的方式。因为显示不全可能会导致无法读取数据) cycle_index = int(len(resutlt) / show_num) for i in range(cycle_index): for j in range(show_num): textviews = results_list_view[j].find_elements(By.CLASS_NAME, "android.widget.TextView") lot_name = results_list_view[j].find_element(By.ID, "search_result_lot_name").text # 藏品名称 lot_type = results_list_view[j].find_element(By.ID, "search_result_lot_status").text # 藏品类型 lot_begin_price = results_list_view[j].find_element(By.ID, "search_result_lot_price").text # 藏品起拍价 lot_marketPriceValue = results_list_view[j].find_element(By.ID, "search_evaluation_price").text # 藏品市场估价 lot_endtime = textviews[-1].text api_lot_name = resutlt[i * show_num + j]['name'] assert lot_name == api_lot_name, u"藏品名字展示和接口返回一致" api_lot_begin_price = resutlt[i * show_num + j]['beginPrice'] assert float(api_lot_begin_price) == float(''.join(re.findall('[0-9]', lot_begin_price))), u"藏品起拍价展示和接口返回一致" lot_marketPriceValue = lot_marketPriceValue[5:] # 去掉市场估价: api_lot_marketPriceValue = resutlt[i * show_num + j]['marketPriceValue'] assert lot_marketPriceValue == api_lot_marketPriceValue, u"市场估价一致" if resutlt[i * show_num + j]['auctionState'] == "F": api_endtime = resutlt[i * show_num + j]['endTime'] if resutlt[i * show_num + j]['leave']: api_status = "已流拍" else: api_status = "已成交" assert lot_endtime.replace(" ","") == api_endtime[:10]+api_status self.driver.swipe \ (results_list_view[show_num - 1].location["x"], results_list_view[show_num - 1].location["y"] + one_view_size['height'], results_list_view[show_num - 1].location["x"], init_hight, duration=4000) self.driver.implicitly_wait(10) time.sleep(4) except Exception as e: raise e
def test_002_Dashop_product_banner(self): """龖商城-商品顶部banner""" try: shop_button = self.driver.find_element(By.ID, "main_mall") shop_button.click() self.driver.implicitly_wait(10) product_element = self.driver.find_element_by_id('tv_goodslist') product_element.click() time.sleep(0.5) req = Four_Vesion_Api().findAdvertiseContent_260(position="P11") result = req.json()['appAdvertiseDtoList'] if len(result) != 0: banner_center = self.driver.find_element( By.ID, "bannerContainer") banner_image = self.driver.find_element( By.ID, "bannerViewPager") if len(result) > 1: # banner焦点图 banner_focus = self.driver.find_element( By.XPATH, '//*[contains(@resource-id,"circleIndicator")]') banner_focus_list = banner_focus.find_elements( By.CLASS_NAME, 'android.widget.ImageView') assert len(banner_focus_list) == len( result), u"首页banner广告数一致" for i in range(len(banner_focus_list)): banner_image.click() self.driver.implicitly_wait(1) if self.driver.current_activity == ".MainActivity": error_img = os.path.join(IMG_PATH, "home_banner_error.png") self.driver.save_screenshot(error_img) else: self.driver.back() x = banner_image.location["x"] y = banner_image.location["y"] + int( banner_image.size['height'] / 2) x1 = x + banner_image.size['width'] y1 = y self.driver.swipe(x, y, x1, y1) else: banner_image.click() if self.driver.current_activity == ".MainActivity": error_img = os.path.join(IMG_PATH, "home_banner_error.png") self.driver.save_screenshot(error_img) else: self.driver.back() except Exception as e: raise e
def test_04_hasregister_again(self): """已注册的号码重新注册""" try: # 已注册的号码 all_phone = Mysql().sql_result('select username from user') tel = random.choice(all_phone)[0] ele_mobile = self.driver.find_element_by_id("et_mobile") ele_code = self.driver.find_element_by_id('et_code') ele_get_code = self.driver.find_element(By.ID, "btn_get_code") ele_nikename = self.driver.find_element(By.ID, "et_nickname") ele_password = self.driver.find_element_by_id('et_password') ele_commit = self.driver.find_element_by_id('btn_register') req = Four_Vesion_Api().sendAuthenticationCode_112(tel) time.sleep(0.5) db_code = Mysql().reslut_replace( f'SELECT message FROM sms_send_his WHERE phone={tel} ORDER BY id DESC LIMIT 1' ) code = re.findall('验证码是(.*),5分钟', db_code) code = code[0] ele_mobile.clear() ele_mobile.send_keys(tel) ele_code.clear() ele_code.send_keys(code) ele_nikename.clear() ele_nikename.send_keys(Public_Function().random_name(3)) pwd = '123456' ele_password.clear() ele_password.send_keys(pwd) ele_commit.click() assert self.driver.current_activity == '.activity.MobileRegActivity', u"已注册的号码再次注册功能正常" except Exception as e: raise e
def test_005_search_user(self, content): """搜索--藏友""" try: user_button = self.driver.find_element(By.ID, "friden_radio_button") user_button.click() self.driver.implicitly_wait(10) time.sleep(1) req = Four_Vesion_Api().findESMemberPage_204(keyword=content) if req.json()['total'] == '0': is_error_toast = PublicShell(self.driver).is_elementExits(By.XPATH, "//*[contains(@text, '暂无相关藏友')]") assert is_error_toast == True else: resutlt = req.json()['rows'] search_list_view = self.driver.find_element_by_id('cn.dcpai.auction:id/search_result_list_view') search_list_view_size = search_list_view.size init_hight = search_list_view.location['y'] # 结果列表页左上方高度 results_list_view = search_list_view.find_elements_by_class_name('android.widget.LinearLayout') one_view_size = results_list_view[0].size # 每个结果的尺寸大小 show_num = search_list_view_size['height'] / one_view_size['height'] # 每页可见数量 show_num = round(show_num) # 可见列数(采用四舍五入的方式。因为显示不全可能会导致无法读取数据) cycle_index = int(len(resutlt) / show_num) for i in range(cycle_index): for j in range(show_num): textviews = results_list_view[j].find_elements(By.CLASS_NAME, "android.widget.TextView") user_icon = results_list_view[j].find_element(By.ID, "search_member_icon") # 用户头像 user_name = textviews[0].text # 藏友名字 user_level = textviews[1].text # 藏友等级 user_message = textviews[2].text # 私信 user_focus = textviews[3].text # 关注 api_user_name = resutlt[i * show_num + j]['nickname'] assert user_name == api_user_name, u"藏友名字展示和接口返回一致" api_user_level = resutlt[i * show_num + j]['level'] assert api_user_level == ''.join(re.findall('[0-9]', user_level)), u"藏友等级展示和接口返回一致" assert user_message == "私信" if resutlt[i * show_num + j]['focus']: api_user_focus = "已关注" else: api_user_focus = "加关注" assert api_user_focus == user_focus, u"关注信息一致" self.driver.swipe \ (results_list_view[show_num - 1].location["x"], results_list_view[show_num - 1].location["y"] + one_view_size['height'], results_list_view[show_num - 1].location["x"], init_hight, duration=4000) self.driver.implicitly_wait(10) time.sleep(4) except Exception as e: raise e
def test_006_search_user(self, content): """搜索--门派""" try: guild_button = self.driver.find_element(By.ID, "guild_radio_button") guild_button.click() self.driver.implicitly_wait(10) time.sleep(1) req = Four_Vesion_Api().searchForumPage_300(keyword=content) if req.json()['total'] == '0': is_error_toast = PublicShell(self.driver).is_elementExits(By.XPATH, "//*[contains(@text, '暂无相关门派')]") assert is_error_toast == True else: resutlt = req.json()['rows'] search_list_view = self.driver.find_element_by_id('cn.dcpai.auction:id/search_result_list_view') search_list_view_size = search_list_view.size init_hight = search_list_view.location['y'] # 结果列表页左上方高度 results_list_view = search_list_view.find_elements(By.ID, "guild_item") one_view_size = results_list_view[0].size # 每个结果的尺寸大小 show_num = search_list_view_size['height'] / (one_view_size['height']+10) # 每页可见数量 show_num = round(show_num) # 可见列数(采用四舍五入的方式。因为显示不全可能会导致无法读取数据) cycle_index = int(len(resutlt) / show_num) for i in range(cycle_index): for j in range(show_num): textviews = results_list_view[j].find_elements(By.CLASS_NAME, "android.widget.TextView") guild_icon = results_list_view[j].find_element(By.ID, "search_guild_tag_image") # 门派头像 guild_member_icon = results_list_view[j].find_element(By.ID, "search_guild_master_icon") # 门派掌门头像 guild_master_identity = results_list_view[j].find_element(By.ID, "search_guild_master_identity") # 门派身份 guild_name = textviews[0].text # 门派名字 guild_info = textviews[1].text # 门派信息 guild_desc = textviews[2].text # 说明 api_guild_name = resutlt[i * show_num + j]['name'] assert guild_name == api_guild_name, u"藏友名字展示和接口返回一致" api_guild_info = f"声望 {resutlt[i * show_num + j]['reputation']} · " \ f"话题{resutlt[i * show_num + j]['postCount']} · " \ f"成员{resutlt[i * show_num + j]['memberCount']}" assert api_guild_info == guild_info, u"门派信息和接口返回一致" api_guild_desc = resutlt[i * show_num + j]['declaration'] assert api_guild_desc == guild_desc, u"信息一致" self.driver.swipe \ (results_list_view[show_num - 1].location["x"], results_list_view[show_num - 1].location["y"] + one_view_size['height'], results_list_view[show_num - 1].location["x"], init_hight, duration=4000) self.driver.implicitly_wait(10) time.sleep(4) except Exception as e: raise e
def test_03_except_password_register(self): """密码长度不满足要求""" try: # 已注册的号码 all_phone = Mysql().sql_result('select username from user') while True: tel = random.randint(19800000000, 19899999999) if (str(tel), ) not in all_phone: break ele_mobile = self.driver.find_element_by_id("et_mobile") ele_code = self.driver.find_element_by_id('et_code') ele_get_code = self.driver.find_element(By.ID, "btn_get_code") ele_nikename = self.driver.find_element(By.ID, "et_nickname") ele_password = self.driver.find_element_by_id('et_password') ele_commit = self.driver.find_element_by_id('btn_register') req = Four_Vesion_Api().sendAuthenticationCode_112(tel) time.sleep(0.5) db_code = Mysql().reslut_replace( f'SELECT message FROM sms_send_his WHERE phone={tel} ORDER BY id DESC LIMIT 1' ) code = re.findall('验证码是(.*),5分钟', db_code) code = code[0] ele_mobile.clear() ele_mobile.send_keys(tel) ele_code.clear() ele_code.send_keys(code) ele_nikename.clear() ele_nikename.send_keys(Public_Function().random_name(3)) ele_commit.click() assert self.driver.current_activity == '.activity.MobileRegActivity', u"密码为空时注册功能正常" sort_pwd = '12345' long_pwd = '12345123451234512' ele_password.clear() ele_password.send_keys(sort_pwd) ele_commit.click() long_name = Public_Function().random_name(16) assert self.driver.current_activity == '.activity.MobileRegActivity', u"密码长度低于6位时注册功能正常" ele_password.clear() if not Public_Function().is_emulator(): ele_password.send_keys(long_pwd) ele_commit.click() assert self.driver.current_activity == '.activity.MobileRegActivity', u"密码长度高于16位时注册功能正常" ele_nikename.clear() ele_nikename.send_keys(long_name) ele_password.send_keys("123456") ele_commit.click() assert self.driver.current_activity == '.activity.MobileRegActivity', u"昵称长度高于16位时注册功能正常" except Exception as e: raise e
def test_06_register(self): """正常注册""" try: all_phone = Mysql().sql_result('select username from user') while True: tel = random.randint(19800000000, 19899999999) if (str(tel), ) not in all_phone: break ele_mobile = self.driver.find_element_by_id("et_mobile") ele_code = self.driver.find_element_by_id('et_code') ele_get_code = self.driver.find_element(By.ID, "btn_get_code") ele_nikename = self.driver.find_element(By.ID, "et_nickname") ele_password = self.driver.find_element_by_id('et_password') ele_commit = self.driver.find_element_by_id('btn_register') ele_mobile.clear() ele_mobile.send_keys(tel) req = Four_Vesion_Api().sendAuthenticationCode_112(tel) time.sleep(0.5) db_code = Mysql().reslut_replace( f'SELECT message FROM sms_send_his WHERE phone={tel} ORDER BY id DESC LIMIT 1' ) code = re.findall('验证码是(.*),5分钟', db_code) code = code[0] ele_code.clear() ele_code.send_keys(code) ele_password.clear() ele_password.send_keys('123456') ele_nikename.clear() nikename = Public_Function().random_name(3) ele_nikename.send_keys(nikename) ele_commit.click() assert self.driver.current_activity == '.MainActivity', u"注册成功后返回登主界面" user_nickname = self.driver.find_element_by_id('tv_nickname') assert user_nickname.text == nikename except Exception as e: raise e
def test_002_search_topic(self, content): """话题搜索""" try: ele_search_txt = self.driver.find_element_by_id('search_src_text') ele_search_txt.clear() ele_search_txt.send_keys(content) # enter键确认 self.driver.press_keycode(66) assert self.driver.current_activity == ".activity.JianghuSearchWebViewActivity", u"搜索结果acitivity正确" req = Four_Vesion_Api().searchPostPage_300(content) # 默认按照热度进行排序 resutl = req.json()['rows'] # 搜索结果列表 search_list_view = self.driver.find_element_by_id('cn.dcpai.auction:id/search_result_list_view') search_list_view_size = search_list_view.size init_hight = search_list_view.location['y'] # 结果列表页左上方高度 no_result = PublicShell(self.driver).is_elementExits(By.ID, "error_title") if no_result: assert req.json() == {"rows": [], "total": "0"}, u"接口内容返回正常" result_element = self.driver.find_element(By.ID, "error_title") assert "暂无相关" in result_element.text else: results_list_view = search_list_view.find_elements_by_class_name('android.widget.LinearLayout') one_view_size = results_list_view[0].size # 每个结果的尺寸大小 row_show_num = int(search_list_view_size['width'] / one_view_size['width']) column_show_num = search_list_view_size['height'] / one_view_size['height'] # 可见列数 column_show_num = round(column_show_num) # 可见列数(采用四舍五入的方式。因为显示不全可能会导致无法读取数据) show_num = row_show_num * column_show_num cycle_index = int(len(resutl) / show_num) for i in range(cycle_index): for j in range(show_num): post_title = results_list_view[j].find_element(By.XPATH, "//*[@resource-id='cn.dcpai.auction:id/search_post_title']").text api_post_title = resutl[i * show_num + j]['subject'] assert post_title == api_post_title, u"话题title展示和接口返回一致" post_author = results_list_view[j].find_element(By.XPATH, "//*[contains(@resource-id,'search_post_author_name')]").text api_post_author = resutl[i * show_num + j]['memberNickname'] assert post_author[:6] in api_post_author, u"话题title展示和接口返回一致" api_img_num = len(resutl[i * show_num + j]['images'].split(",")) if api_img_num > 1: post_img_num = results_list_view[j].find_element(By.XPATH, "//*[contains(@resource-id,'search_post_num')]").text assert str(api_img_num) == re.findall('[0-9]', post_img_num)[0], u"话题图片数量一致" post_onlook_num = results_list_view[j].find_element(By.XPATH, "//*[contains(@resource-id,'search_post_onlooking_count')]").text api_post_onlook_num = resutl[i * show_num + j]['observerCount'] assert post_onlook_num == api_post_onlook_num, u"围观数量一致" self.driver.swipe \ (results_list_view[show_num - 1].location["x"], results_list_view[show_num - 1].location["y"] + one_view_size['height'], results_list_view[show_num - 1].location["x"], init_hight, duration=4000) self.driver.implicitly_wait(10) time.sleep(4) newreq = Four_Vesion_Api().searchPostPage_300(content, sort="N") # 默认按照热度进行排序 newresutl = newreq.json()['rows'] # 最新排序按钮 new_sort_element = self.driver.find_element(By.ID, "search_post_filter_sort_time") new_sort_element.click() self.driver.implicitly_wait(10) time.sleep(3) for i in range(cycle_index): for j in range(show_num): post_title = results_list_view[j].find_element(By.XPATH, "//*[@resource-id='cn.dcpai.auction:id/search_post_title']").text api_post_title = newresutl[i * show_num + j]['subject'] assert post_title == api_post_title, u"话题title展示和接口返回一致" post_author = results_list_view[j].find_element(By.XPATH, "//*[contains(@resource-id,'search_post_author_name')]").text api_post_author = newresutl[i * show_num + j]['memberNickname'] assert post_author[:6] in api_post_author, u"话题title展示和接口返回一致" api_img_num = len(newresutl[i * show_num + j]['images'].split(",")) if api_img_num > 1: post_img_num = results_list_view[j].find_element(By.XPATH, "//*[contains(@resource-id,'search_post_num')]").text assert str(api_img_num) == re.findall('[0-9]', post_img_num)[0], u"话题图片数量一致" post_onlook_num = results_list_view[j].find_element(By.XPATH, "//*[contains(@resource-id,'search_post_onlooking_count')]").text api_post_onlook_num = newresutl[i * show_num + j]['observerCount'] assert post_onlook_num == api_post_onlook_num, u"围观数量一致" self.driver.swipe \ (results_list_view[show_num - 1].location["x"], results_list_view[show_num - 1].location["y"] + one_view_size['height'], results_list_view[show_num - 1].location["x"], init_hight, duration=4000) self.driver.implicitly_wait(10) time.sleep(4) except Exception as e: raise e
def test_003_search_filtrate_topic(self, content): """话题搜索--筛选""" try: filtrate_button = self.driver.find_element(By.ID, "search_post_filter_category") filtrate_button.click() self.driver.implicitly_wait(10) # 筛选类别列表 type_list_view = self.driver.find_element_by_android_uiautomator \ ('new UiSelector().resourceId("cn.dcpai.auction:id/type_recycler")') req = Four_Vesion_Api().findAllPostType_320() api_type_list = [] for result in req.json(): api_type_list.append(result['name']) type_list = type_list_view.find_elements(By.XPATH, "//*[contains(@resource-id, 'type_name')]") for every_type in type_list: assert every_type.is_enabled() == True index = type_list.index(every_type) if index == 0: assert every_type.text == "全部" else: assert every_type.text == api_type_list[index - 1] random_num = random.randint(1, len(type_list)-1) type_list[random_num].click() # 随机选择一个分类(全部除开)进行查询 self.driver.implicitly_wait(10) time.sleep(4) typeReq = Four_Vesion_Api().searchPostPage_300(keyword=content, typeId=random_num, sort="N") if typeReq.json()['total'] == '0': is_error_toast = PublicShell(self.driver).is_elementExits(By.XPATH, "//*[contains(@text, '暂无相关话题')]") assert is_error_toast == True else: resutl = typeReq.json()['rows'] search_list_view = self.driver.find_element_by_id('cn.dcpai.auction:id/search_result_list_view') search_list_view_size = search_list_view.size init_hight = search_list_view.location['y'] # 结果列表页左上方高度 results_list_view = search_list_view.find_elements_by_class_name('android.widget.LinearLayout') one_view_size = results_list_view[0].size # 每个结果的尺寸大小 row_show_num = int(search_list_view_size['width'] / one_view_size['width']) column_show_num = search_list_view_size['height'] / one_view_size['height'] # 可见列数 column_show_num = round(column_show_num) # 可见列数(采用四舍五入的方式。因为显示不全可能会导致无法读取数据) show_num = row_show_num * column_show_num cycle_index = int(len(resutl) / show_num) for i in range(cycle_index): for j in range(show_num): post_title = results_list_view[j].find_element(By.XPATH, "//*[contains(@resource-id,'search_post_title')]").text api_post_title = resutl[i * show_num + j]['subject'] assert post_title == api_post_title, u"话题title展示和接口返回一致" post_author = results_list_view[j].find_element(By.XPATH, "//*[contains(@resource-id,'search_post_author_name')]").text api_post_author = resutl[i * show_num + j]['memberNickname'] assert post_author[:6] in api_post_author, u"话题title展示和接口返回一致" api_img_num = len(resutl[i * show_num + j]['images'].split(",")) if api_img_num > 1: post_img_num = results_list_view[j].find_element(By.XPATH, "//*[@resource-id='cn.dcpai.auction:id/search_post_num']").text assert str(api_img_num) == re.findall('[0-9]', post_img_num)[0], u"话题图片数量一致" post_onlook_num = results_list_view[j].find_element(By.XPATH, "//*[contains(@resource-id,'search_post_onlooking_count')]").text api_post_onlook_num = resutl[i * show_num + j]['observerCount'] assert post_onlook_num == api_post_onlook_num, u"围观数量一致" self.driver.swipe \ (results_list_view[show_num - 1].location["x"], results_list_view[show_num - 1].location["y"] + one_view_size['height'], results_list_view[show_num - 1].location["x"], init_hight, duration=4000) self.driver.implicitly_wait(10) time.sleep(4) except Exception as e: raise e
def test_006_Living_banner(self): """直播页顶部banner""" try: home = self.driver.find_element(By.ID, "main_page") home.click() self.driver.implicitly_wait(10) time.sleep(0.5) living_button = self.driver.find_element_by_id('home_live') living_button.click() self.driver.implicitly_wait(10) time.sleep(0.5) assert self.driver.current_activity == '.live.ui.LiveListActivity' assert PublicShell(self.driver).is_elementExits( By.XPATH, "//*[contains(@text, '全部')]") == True assert PublicShell(self.driver).is_elementExits( By.XPATH, "//*[contains(@text, '轰啪')]") == True assert PublicShell(self.driver).is_elementExits( By.XPATH, "//*[contains(@text, '秒啪')]") == True assert PublicShell(self.driver).is_elementExits( By.XPATH, "//*[contains(@text, '讲堂')]") == True assert PublicShell(self.driver).is_elementExits( By.XPATH, "//*[contains(@text, '巡展直播')]") == True req = Four_Vesion_Api().findAdvertiseContent_260(position="P15") result = req.json()['appAdvertiseDtoList'] if len(result) != 0: banner_center = self.driver.find_element( By.ID, "bannerContainer") banner_image = self.driver.find_element( By.ID, "bannerViewPager") if len(result) > 1: # banner焦点图 banner_focus = self.driver.find_element( By.XPATH, '//*[contains(@resource-id,"circleIndicator")]') banner_focus_list = banner_focus.find_elements( By.CLASS_NAME, 'android.widget.ImageView') assert len(banner_focus_list) == len( result), u"首页banner广告数一致" for i in range(len(banner_focus_list)): banner_image.click() self.driver.implicitly_wait(1) if self.driver.current_activity == ".MainActivity": error_img = os.path.join(IMG_PATH, "home_banner_error.png") self.driver.save_screenshot(error_img) else: self.driver.back() x = banner_image.location["x"] y = banner_image.location["y"] + int( banner_image.size['height'] / 2) x1 = x + banner_image.size['width'] y1 = y self.driver.swipe(x, y, x1, y1) else: banner_image.click() if self.driver.current_activity == ".MainActivity": error_img = os.path.join(IMG_PATH, "home_banner_error.png") self.driver.save_screenshot(error_img) else: self.driver.back() self.driver.back() # 退回到主页 except Exception as e: raise e