使用python自带的unittest测试框架,用例继承自unittest.TestCase类。

1 引入接口类和页面类

2 setUp函数中打开页面,定义接口对象

3 tearDown函数中关闭页面

4 test打头的函数都是用例。因页面和接口的相关方法都已封装好,所以用例会比较简洁。

5 当一个用例需根据参数不同执行多次时,可使用ddt数据驱动,或unittest自带的subTest。

# coding:utf-8
"""
页面2的测试用例
""" from apiclass.api_fund import Fund
from pageclass.strategy import StrategyPage
from common.launch_browser import launch_browser
import unittest
from ddt import ddt,data,unpack @ddt
class StrategyPageTest(unittest.TestCase): @classmethod
def setUpClass(cls):
sso = "sso串"
driver = launch_browser("chrome")
cls.page = StrategyPage(driver)
cls.page.open_strategy_page(sso) # 创建页面对象
cls.fund = Fund() # 创建接口对象 @classmethod
def tearDownClass(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)
@unpack
def 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() """接口与页面数据比较"""
def compare_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+"接口和页面的净值不一致") def compare_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+"组合走势开始时间,业务表现数据不一致") def compare_trends(self):
"""组合走势业绩表现"""
code = self.page.get_code()
for patternindex in range(2): #两种定投方式
self.page.choose_trends_pattern(patternindex) #点击定投列表获取时间区间
for peroidindex in range(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)) def compare_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+"组合涨幅数据对比不一致") def compare_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+"策略配置不一致") def compare_settings_alldays(self):
"""策略配置数据对比"""
self.page.get_strategy_adjustdate() # 获取页面策略调仓日期
for adjustdate in self.page.adjustDatelist:
with self.subTest("adjustdate_%s" % adjustdate):
self.page.choose_adjustdate(adjustdate) # 选择日期并获取配置
self.compare_settings() if __name__ == '__main__':
unittest.main()

the end!

python UI自动化实战记录七:页面2用例编写的更多相关文章

  1. python UI自动化实战记录五:测试页面2 pageobject

    该部分记录测试页面2-StrategyPage,所有页面2上的元素定位.操作.获取属性等方法都写在该类中. 1 页面2继承自BasePage: 2 页面2第一部分写的是所有的定位器 3 页面2第二部分 ...

  2. python UI自动化实战记录六:页面1用例编写

    使用python自带的unittest测试框架,用例继承自unittest.TestCase类. 1 引入接口类和页面类 2 setUp函数中打开页面,定义接口对象 3 tearDown函数中关闭页面 ...

  3. python UI自动化实战记录四:测试页面1-pageobject

    该部分记录测试页面1-IndexPage,所有首页上的元素定位.操作.获取属性等方法都写在该类中. 1 首页类继承自BasePage 2 首页类第一部分写的是所有的定位器 3 首页类第二部分类的方法, ...

  4. python UI自动化实战记录十:执行测试及测试报告

    使用简单的unittest.TextTestRunner. 思路: 1 在report目录下创建当日测试报告目录 20190113 2 创建测试报告文件 f = 时间戳.txt 3 加载测试集,运行测 ...

  5. python UI自动化实战记录二:请求接口数据并提取数据

    该部分记录如何获取预期结果-接口响应数据,分成两步: 1 获取数据源接口数据 2 提取后续页面对比中要用到的数据 并且为了便于后续调用,将接口相关的都封装到ProjectApi类中. 新建python ...

  6. python UI自动化实战记录三:pageobject-基类

    脚本思路: 使用pageobject模式,写一个basepage基类,所有页面的通用方法封装到基类中.比如打开页面,关闭页面,等待时间,鼠标移到元素上,获取单个元素,获取一组元素,获取元素的子元素,截 ...

  7. python UI自动化实战记录十一: 总结

    首先说说为什么想起来用自动化脚本来实现该项目的自动化. 工作还是以手工测试为主,业务驱动型的项目大概就是这样,业务不停地变,不断的迭代. 自动化测试实施的先决条件: 一 得有时间. 如果有时间大部分的 ...

  8. python UI自动化实战记录一:测试需求与测试思路

    测试需求: 项目包含两个数据展示页面,数据均来自于四个数据源接口. 测试操作步骤: 选择5个大类型中的一个,每个大类型下有3个子类型,选择任一子类型,页面数据更新.需验证页面上的数据与数据源接口数据一 ...

  9. python UI自动化实战记录八:添加配置

    添加配置文件写入测试地址等,当环境切换时只需修改配置文件即可. 1 在项目目录下添加文件 config.ini 写入: [Domain] domain = http://test.domain.cn ...

随机推荐

  1. C 标准库 - string.h之strcpy使用

    strcpy Copies the C string pointed by source into the array pointed by destination, including the te ...

  2. WPF实现无刷新动态切换多语言(国际化)

    1. 在WPF中国际化使用的是 .xaml文件的格式 如图:Resource Dictionary (WPF) 2. 创建默认的语言文件和其他语言文件 这里以英语为默认语言,新建一个 Resource ...

  3. 基于URL权限拦截的实现

    一.实现原理 1.实现原理   本示例采用SpringMVC的拦截器来实现一个基于URL的权限拦截. 2.权限管理流程 二.数据库搭建 1.用户表(sys_user) (1)表结构 (2)表字段说明 ...

  4. Redis双机热备方案--转

    http://luyx30.blog.51cto.com/1029851/1350832 参考资料: http://patrick-tang.blogspot.com/2012/06/redis-ke ...

  5. Windows加密API的层次

    Windows平台下的应用程序可以分为托管的.NET程序和本机的Win32(以及Win64)两大类..NET有着类似于JAVA的虚拟机和二进制码托管运行环境,提供了在不同Windows平台上的代码可携 ...

  6. vue+cordova项目

    教你用Cordova打包Vue项目   现在国内越来越多的开发者使用Vue开发混合app,但是当大家开发完成过后才发现不知道该怎么将Vue项目打包成app.据我现在的了解打包Vue项目目前流行的就是使 ...

  7. requset获取post提交的请求参数

    1.请求体的内容通常是通过post来提交的,格式是 username=zhansan&password=123&hobby=football||&hobby=basketbal ...

  8. Spring 中任意位置获取 session 和 request

    在web.xml中添加监听: <listener> <listener-class>org.springframework.web.context.ContextLoaderL ...

  9. 谷歌在线appspot平台教你学Hacker(由浅如深)-XSS篇

    练习链接 http://google-gruyere.appspot.com/ 点开是纯英文的 直接点翻译即可 一 .part1 http://google-gruyere.appspot.com/p ...

  10. 快速了解RabbitMQ消息队列

    MQ 是什么?队列是什么,MQ 我们可以理解为消息队列,队列我们可以理解为管道.以管道的方式做消息传递. 场景: 1.其实我们在双11的时候,当我们凌晨大量的秒杀和抢购商品,然后去结算的时候,就会发现 ...