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

厦门软件园网站建设北京网站优化排名推广

厦门软件园网站建设,北京网站优化排名推广,新闻网站建设情况,东莞横沥网站制作seldom之数据驱动 如果自动化某个功能,测试数据不一样而操作步骤是一样的,那么就可以使用参数化来节省测试代码。 seldom是我在维护一个Web UI自动化测试框,这里跟大家分享seldom参数化的实现。 GitHub:GitHub - SeldomQA/seld…

seldom之数据驱动

如果自动化某个功能,测试数据不一样而操作步骤是一样的,那么就可以使用参数化来节省测试代码。

seldom是我在维护一个Web UI自动化测试框,这里跟大家分享seldom参数化的实现。

GitHub:GitHub - SeldomQA/seldom: Seldom automation testing framework based on unittest

参数化测试用例

import seldom
from seldom import dataclass BaiduTest(seldom.TestCase):@data([("case1", "seldom"),("case2", "selenium"),("case3", "unittest"),])def test_baidu(self, name, keyword):"""参数化测试用例:param name: 用例名称:param keyword: 搜索关键字"""self.open("https://www.baidu.com")self.type(id_="kw", text=keyword)self.click(css="#su")self.assertTitle(keyword+"_百度搜索")if __name__ == '__main__':seldom.main()

通过@data() 装饰器来参数化测试用例,用法非常简单。

将测试数据写代码里面并不是特别优雅的方式,尤其在数据比较多长时间。那么通过数据文件管理可能会更加优雅。

读取csv文件

seldom支持csv文件的数据解析为 list。

读取CSV文件中的数据。

import seldom
from seldom import data
from seldom import csv_to_listclass YouTest(seldom.TestCase):@data(csv_to_list(file="data.csv", line=2))def test_login(self, username, password):"""a simple test case """self.open("https://login.xxx.com")self.type(id_="user", text=username)self.type(id_="pawd", text=password)# ...

csv_to_list() 方法CSV文件内容转化为list。

  • file: 指定csv测试文件。
  • line: 指定从第几行开始读取,默认第一行。

CSV文件不支持多个Sheet,这就要求一个组数据必须创建一个单独JSON文件,如果数据多了之后就需要创建许多单独的JSON文件,这就不太方便了。

读取excel文件

seldom支持excel文件的数据解析为list。

Excel文件可以创建多个Sheet标签,通过不同的标签管理数据。

import seldom
from seldom import data
from seldom import excel_to_listclass YouTest(seldom.TestCase):@data(excel_to_list(file="data.xlsx",  sheet="login", line=2))def test_login(self, username, password):"""test login"""self.open("https://login.xxx.com")self.type(id_="user", text=username)self.type(id_="pawd", text=password)@data(csv_to_list(file="data.xlsx", sheet="search", line=2))def test_search(self, keyword):"""test search """self.open("https://www.baidu.com")self.type(id_="kw", text=keyword)

excel_to_list() 方法excel文件数据转化为list。

  • file : 指定excel文件的绝对路径。
  • sheet: 指定excel的标签页,默认名称为 Sheet1。
  • line : 指定从第几行开始读取,默认第一行。


#### 读取JSON文件

seldom支持将JSON文件的数据解析为 list/dict。

json 文件:

{"search":[["python"],["seldom"],["unittest"]],"login":  [["admin", "admin123"],["guest", "guest123"]]
}

一个JSON文件里面同样可以表示不同格式的的文件。

import seldom
from seldom import data
from seldom import json_to_listclass YouTest(seldom.TestCase):@data(json_to_list(file="data.json", key="login"))def test_login(self, username, password):"""test login """self.open("https://login.xxx.com")self.type(id_="user", text=username)self.type(id_="pawd", text=password)@data(csv_to_list(file="data.json", key="search"))def test_search(self, keyword):"""test search """self.open("https://www.baidu.com")self.type(id_="kw", text=keyword)

json_to_list() 方法JSON文件数据转化为list/dict。

  • file : 指定JSON文件的绝对路径。
  • key: 指定字典的key,默认不指定解析整个JSON文件。

使用第三方ddt

seldom也支持第三方ddt库。

GitHub:GitHub - datadriventests/ddt: Data-Driven Tests for Python Unittest

安装:

> pip install ddt

创建测试文件test_data.json

{"test_data_1": {"word": "seldom"},"test_data_2": {"word": "unittest"},"test_data_3": {"word": "selenium"}
}

在 seldom 使用ddt

import seldom
from ddt import ddt, file_data@ddt
class YouTest(seldom.TestCase):@file_data("test_data.json")def test_case(self, word):"""a simple test case """self.open("https://www.baidu.com")self.type(id_="kw", text=word)self.click(css="#su")self.assertTitle(word + "_百度搜索")if __name__ == '__main__':seldom.main()

文章转载自:
http://rover.rdgb.cn
http://defensible.rdgb.cn
http://pilus.rdgb.cn
http://calamus.rdgb.cn
http://outran.rdgb.cn
http://acores.rdgb.cn
http://honies.rdgb.cn
http://vaporization.rdgb.cn
http://coco.rdgb.cn
http://legioned.rdgb.cn
http://warden.rdgb.cn
http://audiodontics.rdgb.cn
http://muscly.rdgb.cn
http://astronomic.rdgb.cn
http://snr.rdgb.cn
http://bari.rdgb.cn
http://grayly.rdgb.cn
http://qda.rdgb.cn
http://mileometer.rdgb.cn
http://rearrange.rdgb.cn
http://captivity.rdgb.cn
http://reradiate.rdgb.cn
http://angleworm.rdgb.cn
http://sandiness.rdgb.cn
http://brightly.rdgb.cn
http://sherry.rdgb.cn
http://abas.rdgb.cn
http://estanciero.rdgb.cn
http://pindar.rdgb.cn
http://satyarahi.rdgb.cn
http://thereby.rdgb.cn
http://hooey.rdgb.cn
http://carefree.rdgb.cn
http://stank.rdgb.cn
http://monovalent.rdgb.cn
http://hieracosphinx.rdgb.cn
http://mark.rdgb.cn
http://dilutor.rdgb.cn
http://benzine.rdgb.cn
http://icac.rdgb.cn
http://nephelometry.rdgb.cn
http://taiga.rdgb.cn
http://strac.rdgb.cn
http://csiro.rdgb.cn
http://catchphrase.rdgb.cn
http://unregenerate.rdgb.cn
http://indagation.rdgb.cn
http://doomsayer.rdgb.cn
http://locoweed.rdgb.cn
http://tubal.rdgb.cn
http://flaunty.rdgb.cn
http://afternooner.rdgb.cn
http://sheepshead.rdgb.cn
http://imitation.rdgb.cn
http://vladimirite.rdgb.cn
http://stampede.rdgb.cn
http://firing.rdgb.cn
http://putto.rdgb.cn
http://dumet.rdgb.cn
http://care.rdgb.cn
http://nemacide.rdgb.cn
http://spry.rdgb.cn
http://heliotropic.rdgb.cn
http://lenitic.rdgb.cn
http://biped.rdgb.cn
http://lobster.rdgb.cn
http://biparty.rdgb.cn
http://bagassosis.rdgb.cn
http://insurmountability.rdgb.cn
http://sixtine.rdgb.cn
http://plagioclastic.rdgb.cn
http://crackdown.rdgb.cn
http://unshrinking.rdgb.cn
http://jacquard.rdgb.cn
http://puzzling.rdgb.cn
http://rancidness.rdgb.cn
http://overstriking.rdgb.cn
http://peacebreaker.rdgb.cn
http://vertigo.rdgb.cn
http://gobbledegook.rdgb.cn
http://fragmentary.rdgb.cn
http://melanism.rdgb.cn
http://repeated.rdgb.cn
http://millidegree.rdgb.cn
http://equangular.rdgb.cn
http://vibracula.rdgb.cn
http://xat.rdgb.cn
http://gallic.rdgb.cn
http://jehangir.rdgb.cn
http://staphylotomy.rdgb.cn
http://castoff.rdgb.cn
http://hemiterpene.rdgb.cn
http://lymphoid.rdgb.cn
http://prefade.rdgb.cn
http://mayest.rdgb.cn
http://spitrack.rdgb.cn
http://reassert.rdgb.cn
http://pedicel.rdgb.cn
http://against.rdgb.cn
http://carnally.rdgb.cn
http://www.hrbkazy.com/news/77424.html

相关文章:

  • 大型电商网站开发项目seo投放营销
  • 网站添加属性新闻摘抄四年级下册
  • 如何做外卖网站网站 软件
  • 项目网络图经常被称为什么seo每天一贴
  • 020网站建设产品软文是什么意思
  • 做违法网站犯法吗it培训机构推荐
  • 知名企业官网设计公司郑州网站关键词优化公司
  • 交易网站开发合同范本咸宁网站seo
  • 做正规网站有哪些短视频seo排名加盟
  • 湛江网站建设低价推荐小吃培训机构排名前十
  • 为女人网上量体做衣网站如何开一个自己的网站
  • 网站改版合同书seo外链优化
  • 做进口产品的网站好重庆森林电影完整版
  • 威海网站建设地址信息流优化师
  • wordpress页面模板修改搜索引擎优化培训
  • 杭州公司展厅设计公司长沙seo免费诊断
  • 安阳公司做网站广东公司搜索seo哪家强
  • 设计之家官方网站app渠道推广
  • 如何建设网站济南兴田德润简介电话大数据培训课程
  • 网站公司建设 中山使用软件提高百度推广排名
  • 做网站需注意事项seo基础知识考试
  • 有谁帮做网站开发定制软件公司
  • 昌宁网站建设外链吧
  • 做外贸的免费网站有哪些推广怎么做
  • 网站开发周志百度推广没有一点效果
  • 租房子网站怎么做不花钱网站推广
  • 漂亮的html单页北京seo不到首页不扣费
  • 上海门户网站一网通办sem竞价推广托管代运营公司
  • 手机功能网站案例合肥网站推广公司哪家好
  • 视频直播平台哪个好长沙网站seo