allure展示环境信息
要将信息添加到Environment小部件,只需在生成报告之前在目录中创建environment.properties
(或environment.xml
)文件allure-results
。
环境属性
浏览器= Chrome
Browser.Version = 63.0
展位=生产
environment.xml
路径:
report/xml目录下
<environment>
<parameter>
<key>Browser</key>
<value>Chrome</value>
</parameter>
<parameter>
<key>Browser.Version</key>
<value>63.0</value>
</parameter>
<parameter>
<key>Stand</key>
<value>Production</value>
</parameter>
</environment>
例如:
<?xml version="1.0" encoding="utf-8"?>
<environment>
<parameter>
<key>cinder_api</key>
<value>v2</value>
</parameter>
<parameter>
<key>environment</key>
<value>192.168.54.121</value>
</parameter>
<parameter>
<key>glance_api</key>
<value>v2</value>
</parameter>
<parameter>
<key>host</key>
<value>192.168.54.121</value>
</parameter>
<parameter>
<key>keystone_api</key>
<value>v3</value>
</parameter>
<parameter>
<key>logininfo</key>
<value>{"auth": {"scope": {"project": {"domain":{"id": "default"},"name": "${project_token_name}$"}}, "identity":{"password": {"user": {"domain":{"id": "default"},"password":"admin","name":"admin"}},"methods":["password"]}}}</value>
</parameter>
<parameter>
<key>neutron_api</key>
<value>v2</value>
</parameter>
<parameter>
<key>nova_api</key>
<value>v2</value>
</parameter>
<parameter>
<key>openstack_version</key>
<value>liberty</value>
</parameter>
<parameter>
<key>tester</key>
<value>mrwuzs</value>
</parameter>
<parameter>
<key>versioncode</key>
<value>1.0</value>
</parameter>
<parameter>
<key>virtual</key>
<value>VMware</value>
</parameter>
</environment>
运行测试报告展示如下:
根据配置信息自动生成xml文件
配置文件:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/10/20 19:36
# @Author : mrwuzs
# @Site :
# @File : initialize_Env.py
# @Software: PyCharm
import os
from Common.Log import MyLog as logging
from Conf.ConfRelevance import ConfRelevance
BASE_PATH = str(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
CONF_PATH = BASE_PATH + "\Conf\cfg.ini"
ENV_PATH = BASE_PATH + "\Report\xml\environment.xml"
class Init_Env:
"""初始化环境信息,更新xml文件"""
def __init__(self):
logging.info("获取环境配置信息")
#读取配置文件,返回字典格式
self.data = ConfRelevance(CONF_PATH,"env").get_relevance_conf()
def dict_to_xml(self):
parameter = []
for k in sorted(self.data.keys()):
xml = []
v = self.data.get(k)
if k == 'detail' and not v.startswith('<![CDATA['):
v = '<![CDATA[{}]]>'.format(v)
xml.append('<key>{value}</key>'.format(value=k))
xml.append('<value>{value}</value>'.format(value=v))
parameter.append('<parameter>{}</parameter>'.format(''.join(xml)))
return '<environment>{}</environment>'.format(''.join(parameter))
def init(self):
data = self.dict_to_xml()
with open(ENV_PATH,'w') as f:
f.write(data)
if __name__ == '__main__':
Init = Init_Env()
Init.init()