最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python 讀取yaml文件的兩種方法(在unittest中使用)

 更新時間:2020年12月01日 16:11:54   作者:做夢的人-  
這篇文章主要介紹了python 讀取yaml文件的兩種方法(在unittest中使用),幫助大家更好的理解和學習python,感興趣的朋友可以了解下

作者:做夢的人(小姐姐)
出處:https://www.cnblogs.com/chongyou/

python讀取yaml文件使用,有兩種方式:

1.使用ddt讀取

2,使用方法讀取ddt的內(nèi)容,在使用方法中進行調(diào)用

1.使用ddt讀取

@ddt.ddt
class loginTestPage(unittest.TestCase):
    @ddt.file_data(path)
    @ddt.unpack
    def testlogin(self,**kwargs):
        u'''
       "輸入郵件賬號、用戶名、密碼符合要求
       勾選同意協(xié)議"  1、注冊成功,跳轉到注冊成功頁面    "
        1、驗證URL,https://www.XX.com/site/register-success.html
        2、郵箱收到注冊成功郵件
        3、數(shù)據(jù)庫中user表中有成功添加注冊賬號數(shù)據(jù)"
 
        :return:
        '''
 
        self.loginPage = CBLogin(self.driver)
        log.info(kwargs)
        self.page = Page(self.driver,kwargs.get('login_url'))
 
        self.page.send_text(self.loginPage.login_sendkes_username(),kwargs.get('username'))
        self.page.send_text(self.loginPage.login_sendkes_password(),kwargs.get('password'))
        self.page.click(self.loginPage.login_click_btn())
        # 斷言登錄是否成功
        self.assertIsNotNone(self.loginPage.is_success(),"元素沒有查找到,登錄失敗")

2.使用已有的方法進行調(diào)用

class HandleYmal:
    """
    獲取測試環(huán)境的配置
    """
    def __init__(self,file_path=None):
        if file_path:
            self.file_path=file_path
        else:
            #獲取path
            root_dir=os.path.dirname(os.path.abspath('.'))
            print(root_dir)
            self.file_path=root_dir+"/config/base.yaml"
    def get_data(self):
        fp=open(self.file_path,encoding="utf-8")
        data=yaml.load(fp)
        return  data
 
 
 
@ddt.ddt
class loginTestPage(unittest.TestCase):
 
    @classmethod
    def setUpClass(cls):
        """前置應該是讀取所有內(nèi)容"""
 
        yaml=HandleYmal()
        cls.kwargs=yaml.get_data()['testenvironment']
        cls.driver = webdriver.Chrome()
 
    def testlogin(self):
        u'''
       "輸入郵件賬號、用戶名、密碼符合要求
       勾選同意協(xié)議"  1、注冊成功,跳轉到注冊成功頁面    "
        1、驗證URL,https://www.chinabrands.com/site/register-success.html
        2、郵箱收到注冊成功郵件
        3、數(shù)據(jù)庫中user表中有成功添加注冊賬號數(shù)據(jù)"
 
        :return:
        '''
 
        self.loginPage = CBLogin(self.driver)
        log.info(self.kwargs)
        self.page = Page(self.driver,self.kwargs.get('login_url'))
        self.page.send_text(self.loginPage.login_sendkes_username(),self.kwargs.get('username'))
        self.page.send_text(self.loginPage.login_sendkes_password(),self.kwargs.get('password'))
        self.page.click(self.loginPage.login_click_btn())
        # 斷言登錄是否成功
        self.assertIsNotNone(self.loginPage.is_success(),"元素沒有查找到,登錄失敗")

以上就是python 讀取yaml文件的兩種方法(在unittest中使用)的詳細內(nèi)容,更多關于python 讀取yaml文件的資料請關注腳本之家其它相關文章!

相關文章

最新評論

赤城县| 临江市| 吴川市| 景洪市| 沁阳市| 义乌市| 安塞县| 灵宝市| 阳东县| 外汇| 钦州市| 随州市| 庄浪县| 南部县| 抚松县| 衡山县| 南郑县| 玉林市| 巫山县| 桂平市| 习水县| 那坡县| 乐至县| 武定县| 天峨县| 商城县| 东台市| 柘荣县| 北安市| 郧西县| 兴文县| 南康市| 镇江市| 金塔县| 陇西县| 青浦区| 吐鲁番市| 兰州市| 阿图什市| 东山县| 阳曲县|