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

abc公司网站建设合同书网站推广优化方案

abc公司网站建设合同书,网站推广优化方案,ubuntu做网站,做网站编辑的时候没保存怎么最近受到万点暴击,由于公司业务出现问题,工作任务没那么繁重,有时间摸索seleniumpython自动化测试,结合网上查到的资料自己编写出适合web自动化测试的框架,由于本人也是刚刚开始学习python,这套自动化框架目…

最近受到万点暴击,由于公司业务出现问题,工作任务没那么繁重,有时间摸索selenium+python自动化测试,结合网上查到的资料自己编写出适合web自动化测试的框架,由于本人也是刚刚开始学习python,这套自动化框架目前已经基本完成了所以总结下编写的得失,便于以后回顾温习,有许多不足的的地方,也遇到了各种奇葩问题,希望大神们多多指教。

首先我们要了解什么是自动化测试,简单的说编写代码、脚本,让软件自动运行,发现缺陷,代替部分的手工测试。了解了自动化测试后,我们要清楚一个框架需要分那些模块:

上图的框架适合大多数的自动化测试,比如web UI  、接口自动化测试都可以采用,如大佬有好的方法请多多指教,简单说明下每个模块:

  • common:存放一些共通的方法
  • data:存放一些文件信息
  • logs:存放程序中写入的日志信息
  • picture:存放程序中截图文件信息
  • report:存放测试报告
  • test_case:存放编写具体的测试用例
  • conf.ini、readconf.py:存放编写的配置信息

下面就具体介绍每个模块的内容:conf.ini主要存放一些不会轻易改变的信息,编写的代码如下:

[DATABASE]
host = 127.0.0.1
username = root
password = root
port = 3306
database = cai_test[HTTP]
# 接口的url
baseurl = http://xx.xxxx.xx
port = 8080
timeout = 1.0
readconf.py文件主要用于读取conf.ini中的数据信息
# *_*coding:utf-8 *_*
__author__ = "Test Lu"
import os,codecs
import configparser
prodir = os.path.dirname(os.path.abspath(__file__))
conf_prodir = os.path.join(prodir,'conf.ini')
class Read_conf():def __init__(self):with open(conf_prodir) as fd:data = fd.read()#清空文件信息if data[:3] ==codecs.BOM_UTF8:data = data[3:]file = codecs.open(conf_prodir,'w')file.write(data)file.close()self.cf = configparser.ConfigParser()self.cf.read(conf_prodir)def  get_http(self,name):value = self.cf.get("HTTP",name)return valuedef get_db(self,name):return self.cf.get("DATABASE",name)

 

这里需要注意,python3.0以上版本与python2.7版本import configparser的方法有一些区别
读取一些配置文集就介绍完了,下面就说说common包下的公共文件

现在就从上往下结束吧!common主要是封装的一些定位元素的方法:

# *_*coding:utf-8 *_*
__author__ = "Test Lu"
from selenium import webdriver
import time,os
import common.config
# from common.logs import MyLog
project_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
class Comm(object):def __init__(self,driver):self.driver = driver# self.driver = webdriver.Firefox()self.driver = webdriver.Chrome()self.driver.maximize_window()def open_url(self,url):self.driver.get(url)self.driver.implicitly_wait(30)# selenium 定位方法def locate_element(self,loatetype,value):if (loatetype == 'id'):el = self.driver.find_element_by_id(value)if (loatetype == 'name'):el = self.driver.find_element_by_name(value)if (loatetype == 'class_name'):el = self.driver.find_element_by_class_name(value)if (loatetype == 'tag_name'):el = self.driver.find_elements_by_tag_name(value)if (loatetype == 'link'):el = self.driver.find_element_by_link_text(value)if (loatetype == 'css'):el = self.driver.find_element_by_css_selector(value)if (loatetype == 'partial_link'):el = self.driver.find_element_by_partial_link_text(value)if (loatetype == 'xpath'):el = self.driver.find_element_by_xpath(value)return el if el else None# selenium 点击def click(self,loatetype,value):self.locate_element(loatetype,value).click()#selenium 输入def input_data(self,loatetype,value,data):self.locate_element(loatetype,value).send_keys(data)#获取定位到的指定元素def get_text(self, loatetype, value):return self.locate_element(loatetype, value).text# 获取标签属性def get_attr(self, loatetype, value, attr):return self.locate_element(loatetype, value).get_attribute(attr)# 页面截图def sc_shot(self,id):for filename in os.listdir(os.path.dirname(os.getcwd())) :if filename == 'picture':breakelse:os.mkdir(os.path.dirname(os.getcwd()) + '/picture/')photo = self.driver.get_screenshot_as_file(project_dir +  '/picture/'+ str(id) + str('_') + time.strftime("%Y-%m-%d-%H-%M-%S") + '.png')return photodef __del__(self):time.sleep(2)self.driver.close()self.driver.quit()

 

下面介绍下,config文件主要用于读取文件中的信息:
import os,xlrd
from common.logs import MyLog
from xml.etree import ElementTree as ElementTree
mylogger = MyLog.get_log()
project_dir = os.path.dirname(os.getcwd())def user_Add():'''excel文件中读取用户登录信息'''with xlrd.open_workbook(project_dir+'/data/test_data.xlsx') as files:table_user = files.sheet_by_name('userdata')try:username = str(int(table_user.cell(1,0).value))except:username = str(table_user.cell(1,0).value)try:passwd = str(int(table_user.cell(1,1).value))except:passwd = str(table_user.cell(1,1).value)try:check = str(int(table_user.cell(1, 2).value))except Exception:check = str(table_user.cell(1, 2).value)table_url = files.sheet_by_name('base_url')base_url = str(table_url.cell(1,0).value)return (username,passwd,base_url,check)
#从xml文件中读取信息,定义全局一个字典来存取xml读出的信息
database={}
def set_read_xml():sql_path = os.path.join(project_dir,'data','SQL.xml')data =ElementTree.parse(sql_path)for db in data.findall('database'):name = db.get('name')table = {}for tb in db.getchildren():table_name = tb.get("name")sql = {}for data in tb.getchildren():sql_id = data.get("id")sql[sql_id] = data.texttable[table_name] = sqldatabase[name] = tablemylogger.info("读取的xml文件的信息%s" %database)
def get_sql_sen(database_name,table_name,sql_id):set_read_xml()db = database.get(database_name).get(table_name)if db.get(sql_id):sql = db.get(sql_id).strip()mylogger.info("返回sql语句信息%s" % sql)return sqlelse:mylogger.info("查下的信息为空,传递的参数有误!数据库名称:【%s】,表信息【%s】,查询的id【%s】"%(database_name,table_name,sql_id))
接着介绍最简单的日志logs.py模块:
# logging模块支持我们自定义封装一个新日志类
import logging,time
import os.path
class Logger(object):def __init__(self, logger,cases="./"):       self.logger = logging.getLogger(logger)self.logger.setLevel(logging.DEBUG)self.cases = cases# 创建一个handler,用于写入日志文件for filename in os.listdir(os.path.dirname(os.getcwd())):if filename == "logs":breakelse:os.mkdir(os.path.dirname(os.getcwd())+'/logs')rq = time.strftime('%Y%m%d%H%M', time.localtime(time.time()))log_path = os.path.dirname(os.getcwd()) + '/logs/'  log_name = log_path + rq + '.log'  # 文件名# 将日志写入磁盘fh = logging.FileHandler(log_name)fh.setLevel(logging.INFO)# 创建一个handler,用于输出到控制台ch = logging.StreamHandler()ch.setLevel(logging.INFO)# 定义handler的输出格式formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')fh.setFormatter(formatter)ch.setFormatter(formatter)# 给logger添加handlerself.logger.addHandler(fh)self.logger.addHandler(ch)def getlog(self):return self.logger
common模块最后一个是test_runner.py这个方法主要是用来执行全部的测试用例
import time,HTMLTestRunner
import unittest
from common.config import *
project_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),os.pardir))
class TestRunner(object):''' 执行测试用例 '''def __init__(self, cases="../",title="Auto Test Report",description="Test case execution"):self.cases = casesself.title = titleself.des = descriptiondef run(self):for filename in os.listdir(project_dir):if filename == "report":breakelse:os.mkdir(project_dir+'/report')# fp = open(project_dir+"/report/" + "report.html", 'wb')now = time.strftime("%Y-%m-%d_%H_%M_%S")# fp = open(project_dir+"/report/"+"result.html", 'wb')fp = open(project_dir+"/report/"+ now +"result.html", 'wb')tests =  unittest.defaultTestLoader.discover(self.cases,pattern='test*.py',top_level_dir=None)runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=self.title, description=self.des)runner.run(tests)fp.close()
以上就是common公共模块所有的模块,简单说下在写这些公共模块时,出现了各种问题,特别是读取xml文件的,唉!对于一个python的小白真是心酸啊!接着说下db模块的内容,db模块主要是读取sql语句以及返回对应的值!
import pymysql
import readconf
import common.config as conf
readconf_conf = readconf.Read_conf()host = readconf_conf.get_db("host")
username = readconf_conf.get_db("username")
password = readconf_conf.get_db("password")
port = readconf_conf.get_db("port")
database = readconf_conf.get_db("database")
config_db = {'host': str(host),'user': username,'password': password,'port': int(port),'db': database
}
class Mysql_DB():def __init__(self):'''初始化数据库'''self.db = Noneself.cursor = Nonedef connect_db(self):'''创建连接数据库'''try:self.db = pymysql.connect(**config_db)#创建游标位置self.cursor = self.db.cursor()# print("链接数据库成功")conf.mylogger.info("链接IP为%s的%s数据库成功" %(host,database))except ConnectionError as ex:conf.mylogger.error(ex)def get_sql_result(self,sql,params,state):self.connect_db()try:self.cursor.execute(sql, params)self.db.commit()# return self.cursorexcept ConnectionError as ex:self.db.rollback()if state==0:return self.cursor.fetchone()else:return self.cursor.fetchall()def close_db(self):print("关闭数据库")conf.mylogger.info("关闭数据库")self.db.close()

 

刚开始写db模块是一直对字典模块的信息怎样传递到数据链接的模块,进过网上查询好些资料才彻底解决,对自己来说也是一种进步,哈哈,下面说下自己踩的坑,帮助自己以后学习**config_db把字典变成关键字参数传递,下面举例说明下:
如果kwargs={'a':1,'b':2,'c':3}那么**kwargs这个等价为test(a=1,b=2,c=3)是不是很简单!哈哈以上就是框架的主要模块,其他的模块每个项目与每个系统都不一样,在这里就是列举出来了,因为就算写出来大家也不能复用,下面就给大家看看小白还有哪些模块

看下了下data模块下的xml模块大家可能用的到,就给大家贴出来吧!因为ui测试主要就用到select与delete语句,所以也没有写多么复杂的sql语句

<?xml version="1.0" encoding="utf-8" ?>
<data><database name="database_member"><table name="table_member"><sql id="select_member">select * from user where real_name=%s</sql><sql id="select_member_one">select mobile from user where mobile=%s</sql><sql id="delete_member">delete from user where mobile=%s</sql><sql id="insert_member">insert into user(id) value(%s)</sql><sql id="update_member">uodate user set real_name = %s where uuid=%s</sql></table></database>
</data>

下面介绍下其他模块的内容:test_data.xlsx文件主要是存放一些用户信息,以及url信息,这样修改用户信息与url信息就不要修改代码方便以后操作!logs是在代码运行时候产生的日志信息,picture是存放图片信息,report存放输入的报告信息,
test_case是编写用户的模块需要所有的用例名称都要以test开头来命名哦,这是因为unittest在进行测试时会自动匹配test_case文件夹下面所有test开头的.py文件

以上就是小编写的UI自动化框架,也是小编第一次写这种博文,转载请标明出处,谢谢。喜欢的朋友也可以给小编我点个赞吧,我会继续努力学习,与大家共同成长哒!

感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:
 

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!有需要的小伙伴可以点击下方小卡片领取 

 


文章转载自:
http://wanjiaamendment.xhqr.cn
http://wanjiaanachronistic.xhqr.cn
http://wanjiaagorot.xhqr.cn
http://wanjiadecompensation.xhqr.cn
http://wanjiapadded.xhqr.cn
http://wanjiaprs.xhqr.cn
http://wanjiaeland.xhqr.cn
http://wanjiadet.xhqr.cn
http://wanjianhl.xhqr.cn
http://wanjiaespiegle.xhqr.cn
http://wanjiacalamary.xhqr.cn
http://wanjiavocatively.xhqr.cn
http://wanjiaoccidentalise.xhqr.cn
http://wanjiadipsophobiac.xhqr.cn
http://wanjiacurioso.xhqr.cn
http://wanjiamonopoly.xhqr.cn
http://wanjiahageman.xhqr.cn
http://wanjiacrush.xhqr.cn
http://wanjiaagammaglobulinaemia.xhqr.cn
http://wanjiasouthernly.xhqr.cn
http://wanjiapeadeutics.xhqr.cn
http://wanjiafilariasis.xhqr.cn
http://wanjiabakeapple.xhqr.cn
http://wanjiahypogenous.xhqr.cn
http://wanjiajacobinize.xhqr.cn
http://wanjiapathologist.xhqr.cn
http://wanjiathirdly.xhqr.cn
http://wanjiatelevisible.xhqr.cn
http://wanjiasowback.xhqr.cn
http://wanjiaserosity.xhqr.cn
http://wanjiaindiction.xhqr.cn
http://wanjiaoxyopia.xhqr.cn
http://wanjiaeventless.xhqr.cn
http://wanjiabryozoa.xhqr.cn
http://wanjiapontoneer.xhqr.cn
http://wanjiaend.xhqr.cn
http://wanjiabusywork.xhqr.cn
http://wanjiaquinquennium.xhqr.cn
http://wanjiaelectrocardiogram.xhqr.cn
http://wanjiamadafu.xhqr.cn
http://wanjiatrippy.xhqr.cn
http://wanjiaholiday.xhqr.cn
http://wanjiaforecaddie.xhqr.cn
http://wanjiafloat.xhqr.cn
http://wanjiaconcise.xhqr.cn
http://wanjiaflashily.xhqr.cn
http://wanjiawashout.xhqr.cn
http://wanjiagroceteria.xhqr.cn
http://wanjiapopcorn.xhqr.cn
http://wanjiaamebiasis.xhqr.cn
http://wanjiaplaydown.xhqr.cn
http://wanjiagarrison.xhqr.cn
http://wanjiaastigmatoscopy.xhqr.cn
http://wanjiacommodious.xhqr.cn
http://wanjiaspiderling.xhqr.cn
http://wanjiachangeroom.xhqr.cn
http://wanjiatop.xhqr.cn
http://wanjiarunch.xhqr.cn
http://wanjiaunderpinner.xhqr.cn
http://wanjiaexist.xhqr.cn
http://wanjiacgh.xhqr.cn
http://wanjiaamylose.xhqr.cn
http://wanjiarepressible.xhqr.cn
http://wanjiasubscriber.xhqr.cn
http://wanjiabigger.xhqr.cn
http://wanjiabyelaw.xhqr.cn
http://wanjianonmember.xhqr.cn
http://wanjiachairmanship.xhqr.cn
http://wanjiastrawworm.xhqr.cn
http://wanjiashocker.xhqr.cn
http://wanjiabiochrome.xhqr.cn
http://wanjiaabri.xhqr.cn
http://wanjiapacker.xhqr.cn
http://wanjiapotpourri.xhqr.cn
http://wanjiaguesthouse.xhqr.cn
http://wanjiagoniometer.xhqr.cn
http://wanjiagluepot.xhqr.cn
http://wanjiainfusorial.xhqr.cn
http://wanjiacompensate.xhqr.cn
http://wanjiapeevy.xhqr.cn
http://www.15wanjia.com/news/112732.html

相关文章:

  • 如何在网上建立自己的网站企业管理培训免费课程
  • 企业网站制作规划免费广告投放平台
  • 怎么把自己做的网站放到网上关键词分类哪八种
  • 能盈利的网站b站推广费用一般多少
  • 订阅号如何做微网站百度点击器下载
  • 做调查问卷哪个网站好石家庄seo代理商
  • it外包服务项目百度关键词优化师
  • dark ui wordpress整站优化排名
  • 网站开发市场调查seo综合查询爱站
  • 设计和建设企业网站心得和体会打开2345网址大全
  • 网站建设与维护教程seo推广小分享
  • 专业门户网站的规划与建设东莞网站推广软件
  • 大连做网站优化如何推广自己的业务
  • 有什么网站可以做任务赚钱附近的电脑培训班在哪里
  • 丰台社会建设网站推广电话
  • 个人工作室如何纳税福州seo管理
  • 可以做日语翻译的兼职网站百度系app
  • 电商网站前端模板杭州网站建设公司
  • wordpress加密修改密码宁波seo网络推广多少钱
  • 想做个网站怎么做seo社区
  • 哪里可以接做ppt的网站重庆百度推广开户
  • 网络设计包括哪些aso优化
  • 网站上传大马后怎么做百度推广后台登陆首页
  • 哈尔滨做网站的价格重庆网站到首页排名
  • 铜川网站建设公司电话seo综合查询 站长工具
  • 南京中小企业网站制作如何开发一个网站
  • 莆田的外贸网站电脑培训班零基础网课
  • 怎么做网站推广毫州seo是哪个英文的缩写
  • 有投标功能的网站怎么做友情链接网站大全
  • 装修设计 在线seo优化顾问