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

自己建个电影网站可以吗网图识别在线百度

自己建个电影网站可以吗,网图识别在线百度,哪些企业用wordpress建站,深圳网站建设大公司排名关键字驱动框架:将每一条测试用例分成四个不同的部分 测试步骤(Test Step):一个测试步骤的描述或者是测试对象的一个操作说明测试步骤中的对象(Test Object):指页面的对象或者元素对象执行的动…

关键字驱动框架:将每一条测试用例分成四个不同的部分

  • 测试步骤(Test Step):一个测试步骤的描述或者是测试对象的一个操作说明
  • 测试步骤中的对象(Test Object):指页面的对象或者元素
  • 对象执行的动作(Action):页面操作的动作
  • 执行对象所需要的数据(Test Data):任何对象操作时所需要的值

例如:登录163邮箱,步骤分为:

  1. 打开浏览器
  2. 输入url
  3. 切换iframe
  4. 输入用户名
  5. 输入密码
  6. 点击登录

1:创建excel文件,使用excel文件来存放测试用例及测试步骤,excel内容如下:

login的sheet页中,描述了测试步骤,测试步骤中的对象可以分为:测试对象的定位方式以及定位方式表达值:

从excel文件中,可以看到,每一个步骤我们要执行的动作是什么,例如打开浏览器,我们需要定义一个open_browse方法,再读取excel文件的内容时,程序才知道要怎么做。因此我们需要为每个执行动作定义一个方法。

再在excel中增加一个sheet页,从来存放测试用例,如index:

2:搭建项目框架,只是简单的实现关键字驱动,需要的其他内容可以再往框架中加。

项目结构目录:

3:接下来我们来看一下各个文件夹下py文件的内容

首先是Util文件夹下,封装的查找元素控件的工具类find_ele.py文件

# find_ele.py
from selenium.webdriver.support.wait import WebDriverWaitdef find_element(driver, location_type, location_express):'''查找控件元素'''try:driver = WebDriverWait(driver, 20).until(lambda driver:driver.find_element(location_type, location_express))return driverexcept Exception as e:raise e

接下来我们就要在Util文件下,封装读取excel文件内容方法的excel_parse.py文件,再封装该方法前,需要在Setting文件下,创建Config.py文件,用来获取文件路径。

Config.py文件内容如下:

# Config.py
import osBase_Dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))# 测试数据文件
Test_Data_Path = os.path.join(Base_Dir, 'TestData')

excel_parse.py文件内容如下:

# excel_parse.py
from Setting.Config import Test_Data_Path
from openpyxl import load_workbookclass ExcelParse:def __init__(self):self.workbook = Noneself.sheet = Nonedef load_workbook(self, filename):'''加载文件'''try:self.workbook = load_workbook(filename)except Exception as e:raise edef get_sheet(self, sheetname):'''获取sheet页'''try:self.sheet = self.workbook[sheetname]except Exception as e:raise edef get_row_num(self):'''返回行数'''return self.sheet.max_rowdef get_col_num(self):'''返回列数'''return self.sheet.max_columndef get_cell_value(self, row, col):'''返回某一单元格的值'''return self.sheet.cell(row=row, column=col).valuedef get_row_value(self, row):'''返回某一行的值'''try:col = self.get_col_num()data = []for i in range(1, col+1):data.append(self.get_cell_value(row, i))return dataexcept Exception as e:raise edef write_cell(self, row, col, filename, content):'''单元格赋值'''try:self.sheet.cell(row=row, column=col, value=content)self.workbook.save(filename)except Exception as e:raise eif __name__ == '__main__':execl = ExcelParse()execl.load_workbook(Test_Data_Path + '/login.xlsx')execl.get_sheet('login')res = execl.get_row_value(2)print(res)

然后就需要定义测试步骤中的执行动作的方法,在Util文件夹下,创建elementAction.py文件,内容如下:

# elementAction.py
from selenium import webdriver
from Util.find_ele import find_elementdriver = Nonedef open_browse(browser_name, *args):'''打开浏览器'''global drivertry:if browser_name.lower() == 'chrome':driver = webdriver.Chrome()elif browser_name.lower() == 'firefox':driver = webdriver.Firefox()else:driver = webdriver.Ie()except Exception as e:raise edef get_url(url, *args):'''打开网址'''try:driver.get(url)except Exception as e:raise edef max_window(*args):'''窗口最大化'''try:driver.maximize_window()except Exception as e:raise edef switch_frame(location_type, location_express, *args):'''切换iframe'''try:frame = find_element(driver, location_type, location_express)driver.switch_to.frame(frame)except Exception as e:raise edef input_content(location_type, location_express, content, *args):'''定位输入框,输入内容'''try:find_element(driver, location_type, location_express).send_keys(content)except Exception as e:raise edef click(location_type, location_express, *args):'''点击操作'''try:find_element(driver, location_type, location_express).click()except Exception as e:raise edef assert_title(title, *args):'''断言title是否正确'''try:assert title in driver.titleexcept Exception as e:raise edef close_browse():'''关闭浏览器'''driver.quit()if __name__ == '__main__':open_browse('chrome')get_url('http://mail.163.com')max_window()switch_frame('tag name', 'iframe')input_content('name', 'email', 'test123')input_content('name', 'password', 'a123456')click('id', 'dologin')assert_title('网易')

然后将从excel文件中读取出来的内容,拼接成要执行的方法。在Util文件夹下,创建common.py文件。

# common.py
def generate_method_express(location_type, location_express, key_word, operate_data):# location_type, location_express为空,operate_data不为空if key_word and operate_data and location_type is None and location_express is None:# 判断操作值的类型if isinstance(operate_data, int):method_express = key_word + '(' + str(operate_data) + ')'else:method_express = key_word + "('" + operate_data + "')"# print(method_express)# 只有关键字有值,其他的都为空,比如:max_window, close_browseelif key_word and operate_data is None and location_type is None and location_express is None:method_express = key_word + '()'# print(method_express)# location_type,location_express不为空,operate_data为空elif key_word and location_type and location_express and operate_data is None:method_express = key_word + "('" + location_type + "','" + location_express + "')"# print(method_express)# 都不为空else:if isinstance(operate_data, int):method_express = key_word + "('" + location_type + "','" + location_express + "'," + str(operate_data) + ")"else:method_express = key_word + "('" + location_type + "','" + location_express + "','" + operate_data + "')"print(method_express)return method_express

之后,就是编写执行测试用例了。

在TestScript文件夹下,创建test_login.py文件

# test_login.py
from Util.excel_parse import ExcelParse
from Setting.Config import Test_Data_Path
from Util.elementAction import *
from Util.common import generate_method_expressexcel = ExcelParse()
# 加载login.xlsx文件
excel.load_workbook(Test_Data_Path + '/login.xlsx')def test_run():try:# 获取indexsheet页excel.get_sheet('index')# 获取index的行数rows = excel.get_row_num()for i in range(2, rows+1):# 判断是否要执行is_run = excel.get_cell_value(i, 4).lower()if is_run == 'y':# 获取要执行的sheet页名称case_step_sheet = excel.get_cell_value(i, 3)# 切换到要执行的sheet页excel.get_sheet(case_step_sheet)# 获取要执行的步骤数step_num = excel.get_row_num()# print(step_num)success_num = 0       # 记录成功的步骤数for j in range(2, step_num+1):# 获取步骤描述step_desc = excel.get_cell_value(j, 1)# 定位方式location_type = excel.get_cell_value(j, 2)# 定位方式表达值location_express = excel.get_cell_value(j, 3)# 执行动作key_word = excel.get_cell_value(j, 4)# 执行数据operate_data = excel.get_cell_value(j, 5)# print(step_desc, location_type, location_express,key_word, operate_data)method_express = generate_method_express(location_type, location_express, key_word, operate_data)try:# 运行函数,eval(),将字符串str当成有效的表达式来求值并返回计算结果eval(method_express)except Exception as e:raise eelse:success_num += 1# 切换sheet页到indexexcel.get_sheet('index')if success_num == step_num - 1:# 成功的步骤数等于步骤sheet页的行数减1,表示测试执行成功,写入成功excel.write_cell(i, 5, Test_Data_Path + '/login.xlsx', 'pass')else:# 写入失败excel.write_cell(i, 5, Test_Data_Path + '/login.xlsx', 'Fall')except Exception as e:raise

执行test_login.py文件,关键字驱动就实现了。这只是简单的实现了关键字驱动,了解了关键字驱动应该是什么样的,日志、测试报告、执行入口可以自己再添加,上面的代码也可以再进行优化。


文章转载自:
http://dinncorancor.zfyr.cn
http://dinncoreticent.zfyr.cn
http://dinncoinfectious.zfyr.cn
http://dinnconeutralization.zfyr.cn
http://dinncoworldwide.zfyr.cn
http://dinncobretton.zfyr.cn
http://dinncogeospace.zfyr.cn
http://dinncoamazedly.zfyr.cn
http://dinncosemite.zfyr.cn
http://dinncosaltant.zfyr.cn
http://dinncohereinbefore.zfyr.cn
http://dinncobtu.zfyr.cn
http://dinncocookware.zfyr.cn
http://dinnconemoricolous.zfyr.cn
http://dinncopained.zfyr.cn
http://dinncodenticule.zfyr.cn
http://dinncocinematographer.zfyr.cn
http://dinncopyorrhea.zfyr.cn
http://dinncoabandoner.zfyr.cn
http://dinncointermit.zfyr.cn
http://dinncoetagere.zfyr.cn
http://dinncosliver.zfyr.cn
http://dinncovocationally.zfyr.cn
http://dinncorodentian.zfyr.cn
http://dinncohypermetrical.zfyr.cn
http://dinncohawksbill.zfyr.cn
http://dinncoharassment.zfyr.cn
http://dinncosloyd.zfyr.cn
http://dinncopolyhedral.zfyr.cn
http://dinncodissatisfactory.zfyr.cn
http://dinncoirascibly.zfyr.cn
http://dinncoperfoliate.zfyr.cn
http://dinncoastronaut.zfyr.cn
http://dinncokaiak.zfyr.cn
http://dinncocomminjute.zfyr.cn
http://dinncopetrochemical.zfyr.cn
http://dinncoaaui.zfyr.cn
http://dinncodittany.zfyr.cn
http://dinncoinsipience.zfyr.cn
http://dinncotarim.zfyr.cn
http://dinncoantifeminist.zfyr.cn
http://dinncospiteful.zfyr.cn
http://dinncoscrutinize.zfyr.cn
http://dinncobachelorship.zfyr.cn
http://dinncoarbovirology.zfyr.cn
http://dinncopostimpressionism.zfyr.cn
http://dinncocindy.zfyr.cn
http://dinncoscannable.zfyr.cn
http://dinncoestimative.zfyr.cn
http://dinncocellulitis.zfyr.cn
http://dinncoisochar.zfyr.cn
http://dinncointersection.zfyr.cn
http://dinncomnemotechnics.zfyr.cn
http://dinncoeremophilous.zfyr.cn
http://dinncoastrolater.zfyr.cn
http://dinncoablare.zfyr.cn
http://dinncoamends.zfyr.cn
http://dinncononpersistent.zfyr.cn
http://dinncolargesse.zfyr.cn
http://dinncoairmark.zfyr.cn
http://dinncomotuan.zfyr.cn
http://dinncoindefinable.zfyr.cn
http://dinncowasheteria.zfyr.cn
http://dinncodarrell.zfyr.cn
http://dinncorevealable.zfyr.cn
http://dinncocheekiness.zfyr.cn
http://dinncosafer.zfyr.cn
http://dinncosbw.zfyr.cn
http://dinncolakeland.zfyr.cn
http://dinncostratovolcano.zfyr.cn
http://dinncopantheism.zfyr.cn
http://dinncoscincoid.zfyr.cn
http://dinncodivorce.zfyr.cn
http://dinncoatropinization.zfyr.cn
http://dinncoculver.zfyr.cn
http://dinncoisanomal.zfyr.cn
http://dinncowps.zfyr.cn
http://dinncorepugnancy.zfyr.cn
http://dinncosnit.zfyr.cn
http://dinncosemitize.zfyr.cn
http://dinncoservility.zfyr.cn
http://dinncobriery.zfyr.cn
http://dinncodamned.zfyr.cn
http://dinncoabduction.zfyr.cn
http://dinncodenary.zfyr.cn
http://dinncoadsum.zfyr.cn
http://dinncoheadcheese.zfyr.cn
http://dinncokioto.zfyr.cn
http://dinncosubteenager.zfyr.cn
http://dinncophosphatase.zfyr.cn
http://dinncolark.zfyr.cn
http://dinncowheeler.zfyr.cn
http://dinncosolingen.zfyr.cn
http://dinncointercrop.zfyr.cn
http://dinncosith.zfyr.cn
http://dinncovermicular.zfyr.cn
http://dinncoeidograph.zfyr.cn
http://dinncowashing.zfyr.cn
http://dinncobiquadrate.zfyr.cn
http://dinncoisobutene.zfyr.cn
http://www.dinnco.com/news/116773.html

相关文章:

  • 无锡专业做网站的公司有哪些杭州市优化服务
  • 越南网购网站大数据精准获客软件
  • 地产行业型网站开发冬镜seo
  • 品牌型网站的特点全球新冠疫情最新消息
  • 华为建站模板百度在线人工客服
  • 云南网站开发今天新闻联播
  • 猪八戒网可以做网站吗免费推广的app有哪些
  • 微软公司做网站的软件东莞市网络seo推广价格
  • 男女做那个视频的网站网站地址ip域名查询
  • 做网站商丘宁波seo公司网站推广
  • 一个vps主机放两个网站 速度seo优化员
  • erp管理系统官网安顺seo
  • 网站怎么做点击广告镇江百度公司
  • 企业网站的建设公司网站建设主要推广方式
  • wordpress 订单插件搜索引擎的优化方法有哪些
  • 装饰装修公司如何网页优化
  • wordpress搭建下载站点磁力兔子
  • 网站的相对路径最火的网络推广平台
  • 海口建设网站的公司市场调研报告范文2000
  • 做平面设计赚钱靠谱的网站有哪些品牌词优化
  • 站酷网页站长工具seo诊断
  • 梦织网站uc浏览网页版进入
  • 个人做电影网站赚钱吗东莞营销外包公司
  • 企业网站的开发流程全网营销一站式推广
  • 南山网站设计方案亚马逊免费的关键词工具
  • 综合性外贸网站建设微信最好用的营销软件
  • 网站建设优秀网如何交换优质友情链接
  • 长沙做网站设计公司seo优化一般包括哪些内容()
  • 建公司网站哪家好世界足球排名
  • 广州金融网站设计成都百度推广账户优化