示例#1
0
def inspect_element():
    """审查所有的元素是否正确"""
    start_time = timestamp()
    for i in os.listdir(ELEMENT_PATH):
        _path = os.path.join(ELEMENT_PATH, i)
        if os.path.isfile(_path):
            with open(_path, encoding='utf-8') as f:
                data = yaml.safe_load(f)
                for k in data.values():
                    pattern, value = k.split('==')
                    if pattern not in LOCATE_MODE:
                        raise AttributeError('【%s】路径中【%s]元素没有指定类型' % (i, k))
                    if pattern == 'xpath':
                        assert '//' in value, '【%s】路径中【%s]元素xpath类型与值不配' % (i,
                                                                            k)
                    if pattern == 'css':
                        assert '//' not in value, '【%s】路径中【%s]元素css类型与值不配' % (
                            i, k)
                    if pattern in ('id', 'name', 'class'):
                        assert value, '【%s】路径中【%s]元素类型与值不匹配' % (i, k)
    end_time = timestamp()
    print("校验元素done!用时%.9f秒!" % (end_time - start_time))
示例#2
0
def pytest_terminal_summary(terminalreporter, exitstatus, config):
    """收集测试结果"""
    result = {
        "total": terminalreporter._numcollected,
        'passed': len(terminalreporter.stats.get('passed', [])),
        'failed': len(terminalreporter.stats.get('failed', [])),
        'error': len(terminalreporter.stats.get('error', [])),
        'skipped': len(terminalreporter.stats.get('skipped', [])),
        # terminalreporter._sessionstarttime 会话开始时间
        'total times': timestamp() - terminalreporter._sessionstarttime
    }
    print(result)
    if result['failed'] or result['error']:
        send_report()