def on_created(self, event): L.i('监听到文件: yaml 发生了变化') try: gen_page_py() except Exception as e: L.e('\n!!!!!!!---pages.yaml---!!!!!!\n解析文件 pages.yaml 错误\n' '请到{}路径下检查修改后重新保存.'.format(self.watch_path))
def _find_element(self, locator, is_need_displayed=True): """查找单个元素,如果有多个返回第一个 Args: locator: 定位器 is_need_displayed: 是否需要定位的元素必须展示 Returns: 元素 Raises: NotFoundElementError 未找到元素会抛 NotFoundElementError 异常 """ if 'timeOutInSeconds' in locator: wait = locator['timeOutInSeconds'] else: wait = 20 try: if is_need_displayed: WebDriverWait(self.driver, wait).until( lambda driver: self._get_element_by_type(driver, locator).is_displayed()) else: WebDriverWait(self.driver, wait).until( lambda driver: self._get_element_by_type(driver, locator) is not None) return self._get_element_by_type(self.driver, locator) except Exception as e: L.e("[element] 页面中未能找到 %s 元素" % locator) raise NotFoundElementError
def check_environment(self): L.i('检查环境...') # 检查appium版本 if '1.4' not in self.appium_v: L.e('appium 版本有问题') exit() else: L.i('appium version {}'.format(self.appium_v)) # 检查设备 if not self.devices: L.e('没有设备连接') exit() else: L.i('已连接设备:', self.devices)
def _find_element(self, locator, is_need_displayed=True): """ :单个元素,如果有多个返回第一个 :param locator: 定位器 :param is_need_displayed: 是否需要定位的元素必须展示 :return: :raises:NotFoundElementError """ with allure.step("检查:'{0}'".format(locator.get('name'))): try: if is_need_displayed: return WebDriverWait(self.driver, locator['time']).until( lambda driver: self._get_element_by_type(driver, locator), '查找元素'.format(locator.get('name'))) except Exception as e: print(e) L.e("页面中未能找到 %s 元素" % locator) raise Exception("页面中未能找到 [%s]" % locator.get('name'))
def _find_element(self, locator, is_need_displayed=True): """查找单个元素,如果有多个返回第一个 Args: locator: 定位器 is_need_displayed: 是否需要定位的元素必须展示 Returns: 元素 Raises: NotFoundElementError 未找到元素会抛 NotFoundElementError 异常 """ if 'timeOutInSeconds' in locator: wait = locator['timeOutInSeconds'] else: wait = 20 try: if is_need_displayed: WebDriverWait( self.driver, wait).until(lambda driver: self._get_element_by_type( driver, locator).is_displayed()) else: WebDriverWait( self.driver, wait).until(lambda driver: self._get_element_by_type( driver, locator) is not None) return self._get_element_by_type(self.driver, locator) except Exception as e: L.e("[element] 页面中未能找到 %s 元素" % locator) filename = locator['name'] self.screenshot('no_element_%s' % filename) file = tools.Find.find_screen('no_element_%s' % filename) allure.attach('no_element_%s.png' % filename, file, allure.attach_type.PNG) raise NotFoundElementError
run case with key word: python3 run.py -k <keyword> """ if __name__ == '__main__': env = Environment() xml_report_path = env.get_environment_info().xml_report html_report_path = env.get_environment_info().html_report # 开始测试 args = [ '-s', '-q', '--allure_features=My stdio1', '--alluredir', xml_report_path ] # args = ['-s', '-q'],'--allure_features=My stdio' self_args = sys.argv[1:] pytest.main(args) # 生成html测试报告 cmd = 'allure generate %s -o %s' % (xml_report_path, html_report_path) # try: Shell.invoke(cmd) except: L.e("Html测试报告生成失败,确保已经安装了Allure-Commandline") # 查找html报告并发送 # time.sleep(2) # from utils.mail import Mail # mail = Mail() # mail.sendMail()