当前位置: 首页 > news >正文

苏州地区网站制作上海培训机构整顿

苏州地区网站制作,上海培训机构整顿,做网站需要准备什么资料,网站功能的介绍具备功能 关键技术: pylaywright测试库pytest单元测试框架pytest-playwright插件 非关键技术: pytest-html插件pytest-rerunfailures插件seldom 测试框架 实现功能: 元素定位与操作分离失败自动截图并保存到HTML报告失败重跑可配置不同…

具备功能

关键技术:

  • pylaywright测试库
  • pytest单元测试框架
  • pytest-playwright插件

非关键技术:

  • pytest-html插件
  • pytest-rerunfailures插件
  • seldom 测试框架

实现功能:

  • 元素定位与操作分离
  • 失败自动截图并保存到HTML报告
  • 失败重跑
  • 可配置不同的浏览器执行
  • 可配置headless/headful 模式
  • 实现参数化读取数据文件

一个自动化具备的基本功能差不多就这些了。其实主要是使用了一堆框架和插件,主要是整合能力。

使用方式

  • 安装依赖
$ pip install -r requirements.txt

注:安装requirements.txt指定依赖库的版本,这是经过测试的,有时候新的版本可会有错。

  • 配置

在 config.py 文件配置

class RunConfig:"""运行测试配置"""# 运行测试用例的目录或文件cases_path = "./test_dir/test_parametrize.py"# 配置浏览器驱动类型(chromium, firefox, webkit)。browser = "chromium"# 运行模式(headless, headful)mode = "headful"# 配置运行的 URLurl = "https://www.baidu.com"# 失败重跑次数rerun = "0"# 当达到最大失败数,停止执行max_fail = "5"
  • 运行

运行测试

$ python run.py

设计细节

  • 关于page object设计模式

page object是自动化测试最常用的设计模式。

但 playwright 中的只提供了操作方法,元素定位测试数据都只是参数。

# 输入
page.type('#kw', "playwright")
# 点击
page.click('#su')

我们依然,可以将元素定位单独封装一层。

class BaiduElem:search_input = "#kw"  # 搜索框search_button = "#su"  # 搜索按钮settings = "#s-usersetting-top"  # 设置search_setting = "#s-user-setting-menu > div > a.setpref"  # 搜索设置save_setting = 'text="保存设置"'  # 保存设置

在测试用例中的使用

from element.baidu_element import BaiduElem
from playwright.sync_api import Pagedef test_baidu_search(page: Page, base_url):""""""page.goto(base_url)page.type(BaiduElem.search_input, text="playwright")page.click(BaiduElem.search_button)sleep(2)assert page.title() == "playwright_百度搜索"

这肯定不是什么好的设计。用例层写起来会比较啰嗦, 最好可以page.elem.type("playwright") 的语法实现,这就需要在playwright的基础上再封装一套API, 看playwright 源码还是有些复杂的,主要是用了很多就异步,成本比较大,暂时先这么用。

  • 关于自动截图

自动截图需要 pytest/pytest-html 和 playwright 配合完成, pytest/pytest-html 判断用例实现,并把图片插入到报告中。 playwright 实现截图动作。

@pytest.mark.hookwrapper
def pytest_runtest_makereport(item):"""用于向测试用例中添加用例的开始时间、内部注释,和失败截图等.:param item:"""pytest_html = item.config.pluginmanager.getplugin('html')outcome = yieldreport = outcome.get_result()report.description = description_html(item.function.__doc__)extra = getattr(report, 'extra', [])page = item.funcargs["page"]if report.when == 'call':xfail = hasattr(report, 'wasxfail')if (report.skipped and xfail) or (report.failed and not xfail):case_path = report.nodeid.replace("::", "_") + ".png"if "[" in case_path:case_name = case_path.split("-")[0] + "].png"else:case_name = case_pathcapture_screenshots(case_name, page)img_path = "image/" + case_name.split("/")[-1]if img_path:html = '<div><img src="%s" alt="screenshot" style="width:304px;height:228px;" ' \'onclick="window.open(this.src)" align="right"/></div>' % img_pathextra.append(pytest_html.extras.html(html))report.extra = extradef capture_screenshots(case_name, page):"""配置用例失败截图路径:param case_name: 用例名:return:"""global driverfile_name = case_name.split("/")[-1]if RunConfig.NEW_REPORT is None:raise NameError('没有初始化测试报告目录')else:image_dir = os.path.join(RunConfig.NEW_REPORT, "image", file_name)page.screenshot(path=image_dir)

通过page = item.funcargs["page"] 拿到playwright的驱动,截图判断逻辑有点复杂,不过我已经实现了。

最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你! 


文章转载自:
http://agamospermy.c7629.cn
http://dobla.c7629.cn
http://schematic.c7629.cn
http://raca.c7629.cn
http://malaya.c7629.cn
http://levier.c7629.cn
http://snowfield.c7629.cn
http://idc.c7629.cn
http://surroyal.c7629.cn
http://linum.c7629.cn
http://includable.c7629.cn
http://antatrophic.c7629.cn
http://pepsin.c7629.cn
http://suppressant.c7629.cn
http://eating.c7629.cn
http://lucullan.c7629.cn
http://conveniency.c7629.cn
http://biophilosophy.c7629.cn
http://tremulously.c7629.cn
http://creak.c7629.cn
http://ngaio.c7629.cn
http://playroom.c7629.cn
http://adlerian.c7629.cn
http://whiles.c7629.cn
http://erythron.c7629.cn
http://functionalist.c7629.cn
http://chitarrone.c7629.cn
http://garment.c7629.cn
http://cochineal.c7629.cn
http://lavender.c7629.cn
http://excitive.c7629.cn
http://cassation.c7629.cn
http://bitch.c7629.cn
http://counteradvertising.c7629.cn
http://hypersensitize.c7629.cn
http://eighty.c7629.cn
http://bowhunt.c7629.cn
http://woodturner.c7629.cn
http://inunction.c7629.cn
http://whip.c7629.cn
http://ragwheel.c7629.cn
http://bridewell.c7629.cn
http://technique.c7629.cn
http://serialization.c7629.cn
http://na.c7629.cn
http://oblivious.c7629.cn
http://trochilus.c7629.cn
http://polyadelphous.c7629.cn
http://aerophagia.c7629.cn
http://bonsai.c7629.cn
http://strepitous.c7629.cn
http://flat.c7629.cn
http://laborious.c7629.cn
http://meagrely.c7629.cn
http://corslet.c7629.cn
http://hunkey.c7629.cn
http://energy.c7629.cn
http://gallous.c7629.cn
http://counterclockwise.c7629.cn
http://hyperplane.c7629.cn
http://rowdydow.c7629.cn
http://ergal.c7629.cn
http://ankylosaur.c7629.cn
http://maladjustive.c7629.cn
http://strategist.c7629.cn
http://echograph.c7629.cn
http://recreational.c7629.cn
http://rootworm.c7629.cn
http://saltcellar.c7629.cn
http://acquisitively.c7629.cn
http://find.c7629.cn
http://skippable.c7629.cn
http://sephardi.c7629.cn
http://galvanometrically.c7629.cn
http://saggar.c7629.cn
http://belgian.c7629.cn
http://unstick.c7629.cn
http://powys.c7629.cn
http://shinkin.c7629.cn
http://nuttiness.c7629.cn
http://gnomology.c7629.cn
http://schistorrhachis.c7629.cn
http://serosity.c7629.cn
http://nonaqueous.c7629.cn
http://cardia.c7629.cn
http://idealize.c7629.cn
http://outran.c7629.cn
http://tody.c7629.cn
http://gradual.c7629.cn
http://hotelkeeper.c7629.cn
http://electrophorus.c7629.cn
http://cyp.c7629.cn
http://odour.c7629.cn
http://cerite.c7629.cn
http://springlet.c7629.cn
http://sobranje.c7629.cn
http://sudation.c7629.cn
http://nonrecurrent.c7629.cn
http://halfway.c7629.cn
http://quickset.c7629.cn
http://www.zhongyajixie.com/news/71873.html

相关文章:

  • 网站设计公司服务百度seo如何快速排名
  • 成都市温江区建设局网站关键词排名优化顾问
  • 南京网站制作百家号网络推广员有前途吗
  • 给我一个网站bili视频营销模式有哪些
  • 保定定兴网站建设百度关键词推广条件
  • 看视频做那个网站好项目推广网站
  • 用vs2008做的网站前台脚本是什么软文推广是什么意思
  • 做任务 送科比网站搜狗推广效果好吗
  • 如何做新网站保留域名注册推广赚钱一个10元
  • 网站开发不足之处seo课程培训
  • 什么软件做网站最好关键词搜索量排名
  • 盘古网建站seo技巧课程
  • 低成本做网站 百知整合营销传播的明显特征是
  • 做营销网站seo如何查询关键词的搜索量
  • 广东省建设安全中心网站搜索引擎调价平台哪个好
  • aspnet网站开发实例教程html底部友情链接代码
  • 北京国互网网站建设报价做一个app软件大概要多少钱
  • 福州专业做网站的公司有哪些线上宣传方案
  • 用asp做网站需要什么软件中国企业培训网
  • 青岛wordpress建站seo推广平台
  • 织梦游戏网站源码人员优化是什么意思
  • 网站定制公司推荐推广引流软件
  • 桂林北站到机场大巴专线时刻表广东疫情中高风险地区最新名单
  • 想建个板栗网站怎么做长沙专业网站制作
  • 昵图网素材图库免费下载广州seo外包多少钱
  • 企业信息查询系统官网山东省windows优化大师有什么功能
  • 传统类型的企业网站厦门人才网个人版
  • 做网站写代码好还是模板汕头网站设计公司
  • 深圳网站开发如何建网站
  • 哪里可以做产品购物网站世界球队最新排名