#coding:utf-8
"""页面2的测试用例"""
from apiclass.api_fund importFundfrom pageclass.strategy importStrategyPagefrom common.launch_browser importlaunch_browserimportunittestfrom ddt importddt,data,unpack
@ddtclassStrategyPageTest(unittest.TestCase):
@classmethoddefsetUpClass(cls):
sso= "sso串"driver= launch_browser("chrome")
cls.page=StrategyPage(driver)
cls.page.open_strategy_page(sso)#创建页面对象
cls.fund = Fund() #创建接口对象
@classmethoddeftearDownClass(cls):
cls.page.closepage()#关闭浏览器
"""用例"""
def test01_nav(self): #净值数据对比
self.compare_nav()def test02_trends_default(self): #组合走势默认值验证
self.compare_trend_default()def test03_trends(self): #组合走势业绩表现
self.compare_trends()def test04_percents(self): #组合涨幅数据对比
self.compare_percents()def test05_settings_default(self): #验证策略配置默认数据
self.compare_settings()def test06_settings(self): #策略配置数据对比
self.compare_settings_alldays()
style_level= [(styleindex,levelindex) for styleindex in range(5) for levelindex in range(3)]
@data(*style_level)
@unpackdef test07_checkallstyles(self,styleindex,levelindex): #全量验证-选择不同的策略,验证数据正确性
self.page.choose_strategy(styleindex,levelindex) #选择策略
self.assertTrue(self.page.check_chooseresult(),"所选类型与页面显示类型不一致")#验证所选策略所有的值
self.compare_nav()
self.compare_trend_default()
self.compare_trends()
self.compare_percents()
self.compare_settings()
self.compare_settings_alldays()"""接口与页面数据比较"""
defcompare_nav(self):"""净值数据对比"""code=self.page.get_code()
self.page.get_navinfo()#页面数据
self.fund.get_fund_latestinfo(code) #获取接口数据
self.assertEqual(self.page.navlist, self.fund.navlist, code+"接口和页面的净值不一致")defcompare_trend_default(self):"""组合走势默认值验证"""code=self.page.get_code()
pattern=self.page.get_actived_pattern()
peroid=self.page.get_actived_peroid()
expect_result= self.fund.get_fund_trends(code, pattern, peroid) #获取组合走势接口数据
actual_result = self.page.get_trends() #获取页面数据
self.assertEqual(expect_result, actual_result, code+"组合走势开始时间,业务表现数据不一致")defcompare_trends(self):"""组合走势业绩表现"""code=self.page.get_code()for patternindex in range(2): #两种定投方式
self.page.choose_trends_pattern(patternindex) #点击定投列表获取时间区间
for peroidindex inrange(len(self.page.peroidlist)):
with self.subTest("choose_peroid_%s"%(peroidindex+1)):
self.page.choose_trends_peroid(peroidindex)#点击时间区间
expect_result = self.fund.get_fund_trends(code, self.page.pattern, self.page.peroid) #获取组合走势接口数据
actual_result = self.page.get_trends() #获取页面数据
self.assertEqual(expect_result, actual_result, "组合走势数据不一致%s_%s_%s"%(code,self.page.peroid,self.page.pattern))defcompare_percents(self):"""组合涨幅数据对比"""code= self.page.get_code() #获取策略信息
self.fund.get_fund_latestinfo(code) #获取接口数据
self.page.get_percents() #获取页面组合涨幅数据
self.assertEqual(self.page.percents_list, self.fund.percents_list, code+"组合涨幅数据对比不一致")defcompare_settings(self):"""验证策略配置默认数据"""code=self.page.get_code()
day= self.page.get_strategy_adjustdate().replace("-", ‘‘) #当前跳转日期
self.page.get_strategy_settings() #获取页面策略配置数据
self.fund.get_fund_strategy(self.page.strategycode, day) #获取接口数据
self.assertEqual(self.page.memo, self.fund.memo.replace("\n", " "), code+"策略分析不一致")
self.assertEqual(self.page.samples, self.fund.samples, code+"策略配置不一致")defcompare_settings_alldays(self):"""策略配置数据对比"""self.page.get_strategy_adjustdate()#获取页面策略调仓日期
for adjustdate inself.page.adjustDatelist:
with self.subTest("adjustdate_%s" %adjustdate):
self.page.choose_adjustdate(adjustdate)#选择日期并获取配置
self.compare_settings()if __name__ == ‘__main__‘:
unittest.main()