学习笔记-参数化

2019-12-12  本文已影响0人  sofiiii

1. 参数化

@pytest.mark.parametrize("参数名1","参数名2",...[(参数1,参数2),(参数3,参数4)])

2. 数据驱动

3. yaml读取文件

import yaml
yaml.save_load(open('fileName','r'))
    def read_yaml_list(self,ele_name):
        #读取yaml列表数据
        for data in self.data:
            for key in data.keys():
                if key == ele_name:
                    return data[ele_name]

    def get_yaml_value(self,title,section,option):
        '''
        获取yaml文件中指定section下指定的value
        :param title: yaml的title
        :param section: yaml下的section
        :param option: key值
        :return: key值对应的value
        '''
        eleloc_title_dict = self.data[title]
        eleloc_dict = eleloc_title_dict[section]
        eleloc_value = eleloc_dict[option]
        return eleloc_value

    def get_yaml_all_items(self, title):
        '''
        获取yaml文件中指定title下所有的元素定位
        :param title: yaml的title
        :return: 返回指定yaml文件title下所有的元素定位
        '''
        eleloc_dict = self.data[title]
        return eleloc_dict

    def get_yaml_section_items(self, title, section):
        '''
        获取yaml文件中指定section下所有的元素定位
        :param title: yaml的title
        :param section: title下指定的section
        :return: 返回指定section下所有元素定位
        '''
        eleloc_title_dict = self.data[title]
        eleloc_dict = eleloc_title_dict[section]
        return eleloc_dict

4. yaml数据存储

- ele_image_id: com.sudiyi.apps.launcher:id/image_logo 
上一篇 下一篇

猜你喜欢

热点阅读