def channel_name_iscorrect(self, channel_name, td_index): logger.info("断言:查询到的所有渠道名是否正确,返回True or False") # 获取所有的tr 对象 为一个列表 tr_list = self.get_element( loc.table_tbody, module="获取所有tr为一个列表").find_elements_by_tag_name("tr") channle_list = [] # 遍历 tr 列表 for tr in tr_list: # 获取每个tr下所有td的对象 为一个列表 td_list = tr.find_elements_by_tag_name("td") # 在td的对象列表中获取指定位置的td值并添加到空列表中 channle_list.append(td_list[td_index].text) logger.info("已获取的一列渠道名称列表{}".format(channle_list)) # 遍历 td 值的列表,如果列表中的值与指定的值相等就在新列表中加"false" list_value = [] for td_value in channle_list: if (td_value != channel_name): list_value.append("false") break if "false" in list_value: return False else: return True
def test_23_click_device_more_info(self, click_device_manage): logger.info("正常用例-指定SN查询后点击更多按钮成功") click_device_manage[5].input_SN_and_find(DMSPD.SN) time.sleep(1) click_device_manage[5].click_device_more_info_obj() assert click_device_manage[4].click_device_more_info_assert() == True
def get_element_attribute(self, loc, module, attribute_name, timeout=20, poll_frequency=0.5): """ :param loc: 元素定位 :param module: 页面+页面操作行为 :param attribute_name: 元素属性名称 :param timeout: 超时时限 :param poll_frequency: 轮询时间 :return: 无 """ # 1.等待元素可见 # 2.获取该元素 # 3.获取元素属性值 self.wait_element_visible(loc, module, timeout, poll_frequency) ele = self.get_element(loc, module, timeout, poll_frequency) logger.info(f"{module}→→→获取元素属性值:{loc}") try: attribute_text = ele.get_attribute(attribute_name) except: logger.exception("元素属性值获取失败...") # 出错后截图 self.screen_shots(module) raise else: return attribute_text
def test_22_page_out_of_largest(self, click_device_manage): logger.info("异常用例-输入大于当前最大页面的数字,页面跳转至最后一页") click_device_manage[5].input_page_number_jump_obj( DMSPD.out_of_largest_page_number, DMSPD.enter_keyboard) assert click_device_manage[4].input_out_of_largest_page_assert( ) == True
def click_keyboard(self, loc, module, text, timeout=20, poll_frequency=0.5): """ :param loc: :param module: :param timeout: :param poll_frequency: :return: """ # 1.等待元素可见 # 2.获取该元素 # 3.键盘操作 self.wait_element_visible(loc, module, timeout, poll_frequency) ele = self.get_element(loc, module, timeout, poll_frequency) logger.info(f"键盘操作:{text}") try: if len(text) == 1: ele.send_keys(text) else: ele.send_keys(text[0], text[1]) except: logger.Exception("键盘操作失败...") raise
def test_06_input_SN(self, click_device_manage): logger.info("正常用例-输入完整的SN,点击查询成功") click_device_manage[5].input_SN_and_find(DMSPD.SN) time.sleep(2) assert click_device_manage[4].SN_iscorrect(DMSPD.SN, DMSPD.SN_td_index) == True assert click_device_manage[4].SN_number_isone() == True
def get_element_text(self, loc, module, timeout=20, poll_frequency=0.5): """ :param loc: 元素定位 :param module: 页面+页面操作行为 :param timeout: 超时时限 :param poll_frequency: 轮询时间 :return: 文本信息 """ # 1.等待元素可见 # 2.获取该元素 # 3.获取该元素文本信息 self.wait_element_visible(loc, module, timeout, poll_frequency) ele = self.get_element(loc, module, timeout, poll_frequency) # 有的元素有时候获取不到文本,等待一秒后获取 time.sleep(1) logger.info(f"{module}→→→获取元素文本信息:{loc}") try: text = ele.text except: logger.exception("元素文本信息获取失败...") # 出错后截图 self.screen_shots(module) raise else: return text
def channel_name_iscontain(self, channel_name, td_index): logger.info("断言:查询到的所有渠道名是否包含输入内容,返回True or False") # 获取所有的tr 对象 为一个列表 tr_list = self.get_element( loc.table_tbody, module="获取所有tr为一个列表").find_elements_by_tag_name("tr") channel_list = [] # 遍历 tr 列表 for tr in tr_list: # 获取每个tr下所有td的对象 为一个列表 td_list = tr.find_elements_by_tag_name("td") # 在td的对象列表中获取指定位置的td的值并添加到空列表中 channel_list.append(td_list[td_index].text) logger.info("已获取的一列渠道名称列表{}".format(channel_list)) # 遍历 td 值的列表 进行比对,如果某一个字符串中不包含指定的值,则在list_value列表中添加"false" list_value = [] for td_value in channel_list: if (td_value.find(channel_name) == -1): list_value.append("false") break if "false" in list_value: return False else: return True
def test_04_input_complete_channel(self, click_device_manage): logger.info("正常用例-输入完整的渠道名zzzz,点击查询成功") click_device_manage[5].input_channle_and_find(DMSPD.complete_channel_2) time.sleep(2) assert click_device_manage[4].channel_name_iscorrect( DMSPD.complete_channel_2, DMSPD.channel_td_index) == True
def jump_to_isvisible(self): logger.info("断言:设备管理子界面_跳至元素是否可见,返回True or False") try: self.wait_element_visible(loc.find_button, module="设备管理子界面_跳至元素可见") except: return False else: return True
def test_11_select_device_model_find(self, click_device_manage): logger.info("正常用例-选择机型NT212,点击查询") click_device_manage[5].select_device_model_and_find_NT212() time.sleep(2) assert click_device_manage[ 4].select_device_model_and_find_NT212_assert( DMSPD.hareware_model_td_index, DMSPD.device_model_NT212) == True
def test_64_click_refresh_button_set_the_item( self, device_more_info_device_info): logger.info("正常用例:点击设备信息-点击设置项旁的刷新按钮") device_more_info_device_info[7].click_set_the_item_obj() sleep(1) device_more_info_device_info[7].click_set_the_item_refresh_button_obj() assert device_more_info_device_info[6].click_refresh_button_assert( ) == True
def test_65_click_refresh_button_WIFI_info(self, device_more_info_device_info): logger.info("正常用例:点击设备信息-点wifi信息旁的刷新按钮") device_more_info_device_info[7].click_wifi_info_obj() sleep(1) device_more_info_device_info[7].click_wifi_info_refresh_button_obj() assert device_more_info_device_info[6].click_refresh_button_assert( ) == True
def test_66_click_refresh_button_printer_info( self, device_more_info_device_info): logger.info("正常用例:点击设备信息-点击打印信息旁的刷新按钮") device_more_info_device_info[7].click_printer_info_obj() sleep(1) device_more_info_device_info[7].click_printer_info_refresh_button_obj() assert device_more_info_device_info[6].click_refresh_button_assert( ) == True
def click_refresh_button_assert(self): logger.info("断言:点击更多-设备信息,页面跳转成功,点击刷新按钮,刷新花朵元素可见,返回True or False") try: self.wait_element_visible(loc.refresh_flower, module="更多-点击设备信息-本机信息-点击刷新按钮") except: return False else: return True
def test_05_input_incomplete_channel(self, click_device_manage): logger.info("正常用例-输入不完整的存在渠道-阿,点击查询成功") click_device_manage[5].input_channle_and_find( DMSPD.notcomplete_channel) time.sleep(2) assert click_device_manage[4].channel_name_iscontain( DMSPD.notcomplete_channel, DMSPD.channel_td_index) == True
def click_printer_info_assert(self): logger.info("断言:点击打印信息-列表展开,打印头坏点元素可见,返回True or False") try: self.wait_element_visible(loc.printer_head_broken, module='打印信息-列表展开,打印头坏点元素可见') except: return False else: return True
def click_set_the_item_assert(self): logger.info("断言:点击设置项-列表展开-打印浓度元素可见,返回True or False") try: self.wait_element_visible(loc.density, module="设置项-列表展开-打印浓度元素可见") except: return False else: return True
def click_wifi_info_assert(self): logger.info("断言:点击wifi信息-信息强度元素可见,返回True or False") try: self.wait_element_visible(loc.wifi_length, "WiFi信息-信号强度") except: return False else: return True
def test_69_click_log_button_to_off(self, device_more_info_device_log): logger.info("正常用例:点击设备log-点击log开关按钮关闭log开关") sleep(3) device_more_info_device_log[7].click_log_button_to_on_obj() sleep(3) device_more_info_device_log[7].click_log_button_to_off_obj() sleep(3) assert device_more_info_device_log[6].click_log_button_to_off_assert( ) == True
def content_is_no_exist(self): logger.info("断言:查询不存在的内容,返回True or False") # 如果SN不存在则查询内容为空 try: self.wait_element_visible(loc.no_data, module="查询不存在的内容") except: return False else: return True
def test_42_click_refresh_button_mobile_net(self, device_more_info_device_info): logger.info("正常用例:点击设备信息-查看移动网络信息-点击刷新按钮") device_more_info_device_info[7].click_mobile_net_info_obj() sleep(1) device_more_info_device_info[ 7].click_mobile_net_info_refresh_button_obj() assert device_more_info_device_info[6].click_refresh_button_assert( ) == True
def test_01_login_success(self, init_set, text): logger.info("正常用例---登录成功") init_set[1].login(text) time.sleep(3) # 断言:账号元素、iot设备管理元素 可见 为 True assert init_set[2].account_isvisible() == True assert init_set[2].iot_device_manage_isvisible() == True
def click_fourth_page_assert(self): logger.info("断言: 点击第4页进行跳页,第4页框框被选中,被选中后的元素可见 返回True 否则返回 False") try: self.wait_element_visible(loc.selected_fourth_page, module="子界面-被选中的第四页框框") except: return False else: return True
def jump_tenth_page_assert(self): logger.info("断言:跳转框输入10,跳转到第10页,第10页框框被选中,元素可见返回 True 否则返回False") try: self.wait_element_visible(loc.selected_tenth_page, module="子界面-被选中的第10页框框") except: return False else: return True
def input_out_of_largest_page_assert(self): logger.info("断言:跳转框输入大于当前最大页面的页面数,跳到最后一页,最后一页框框被选中,元素可见返回True,否则False") try: self.wait_element_visible(loc.selected_end_page, module="子界面-被选中最后一页框框") except: return False else: return True
def click_mobile_net_info_assert(self): logger.info("断言:点击设备信息-点击移动网络信息-展开列表-信号强度元素可见") try: self.wait_element_visible(loc.mni_signal_strength, module="点击移动网络信息-展开列表-信号强度元素可见") except: return False else: return True
def click_device_log_assert(self): logger.info("断言:点击设备LOG-进入设备log页面,跳转元素可见,返回True or False") try: self.wait_element_visible(loc.device_log_jump_to, module="点击设备LOG-进入设备log页面_跳转元素可见") except: return False else: return True
def test_68_click_log_button_to_on(self, device_more_info_device_log): logger.info("正常用例:点击设备log-点击log开关按钮打开log开关") sleep(3) device_more_info_device_log[7].click_log_button_to_on_obj() sleep(3) assert device_more_info_device_log[6].click_log_button_to_on_assert( ) == True HandleMysql().read_mysql( do_yaml.read_yaml("mysql", "update_log_swith_off"), [0, DMIPD.SN]) HandleMysql().close()
def click_local_device_info_assert(self): logger.info( "断言:点击设备信息-本机信息-收回展示信息,收回后loc.ldi_fold元素存在 ,返回True or Fasle") try: self.wait_element_presence(loc.ldi_fold, module="点击本机信息-展示信息收回-loc.ldi_fold存在") except: return False else: return True