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

番禺响应式网站开发三明网站seo

番禺响应式网站开发,三明网站seo,wordpress版块插件,南京logo设计公司如果在进行自动化测试的时候将测试数据写在代码中,若测试数据有变,不利于数据的修改和维护。但可以尝试通过将测试数据放到excel文档中来实现测试数据的管理。 示例:本次涉及的项目使用的12306 selenium 重构------三层架构 excel文件数据如…

如果在进行自动化测试的时候将测试数据写在代码中,若测试数据有变,不利于数据的修改和维护。但可以尝试通过将测试数据放到excel文档中来实现测试数据的管理。

示例:本次涉及的项目使用的12306 selenium 重构------三层架构
excel文件数据如图所示:
在这里插入图片描述
整体项目代码结构如图所示:
在这里插入图片描述
function.py 代码如下(基础代码):

# coding = utf-8'''基础常用方法'''from datetime import date,timedelta
from selenium import webdriver
from selenium.webdriver.common.by import By
import xlrd
import logging# 将driver设置为全局变量
driver = webdriver.Chrome()def return_driver():'''函数return_driver()的功能是返回driver对象:return:driver对象'''return driverdef open_base_site(url):'''打开网页:param url:要打开的网页地址:return:'''driver.get(url)def max_window():'''浏览器窗口最大化:return:'''driver.maximize_window()def close_driver():'''关闭浏览器:return:'''driver.quit()# 以下为定义函数部分,其目的是返回今天后的第n天后的日期,格式为“2022-03-28”
def date_n(n):return str((date.today() + timedelta(days=int(n))).strftime('%Y-%m-%d'))def id(element):'''根据元素id属性值来返回元素定位语句。:param element: id属性值:return:按照id属性来定位元素的语句'''return driver.find_element(By.ID, element)def xpath(element):'''使用xpath定位元素:param element::return:按照xpath方式来定位元素的语句'''return driver.find_element(By.XPATH, element)def read_excel(excleName, sheetName):'''按行读取excel:param excleName: excel文件名:param sheetName: sheet名称:return: 列表形式'''wb = xlrd.open_workbook(excleName)sheet = wb.sheet_by_name(sheetName)data = []for row in range(sheet.nrows):data.append(sheet.row_values(row))return datadef filelog(logName):'''文件日志器:return: 日志器'''# 创建日志器logger = logging.getLogger()# 设置日志器输出级别logger.setLevel(logging.DEBUG)# 创建格式器fmt = '%(asctime)s %(filename)s %(lineno)d %(levelname)s %(message)s'format = logging.Formatter(fmt=fmt, datefmt='%Y-%m-%d %H:%M:%S %a')# 创建文件处理器fileHandler = logging.FileHandler(logName + '.log', mode='a', encoding='utf-8')# 处理器添加格式器fileHandler.setFormatter(format)# 日志器添加文件处理器logger.addHandler(fileHandler)# 返回日志器return logger

search_tickets.py 的代码如下:

# coding = utf-8from functions import return_driver, open_base_site,max_window,date_n,xpath,iddef search_tickets(from_station, to_station, n, url):'''搜索车次:param from_station: 出发城市:param to_station: 到达城市:param n: 一个数字,如1表示选择明天的车票,2表示选择后台的车票:param url: 要访问的网站地址:return:'''# tomorrow变量:出发日期tomorrow = date_n(n)# 打开浏览器driver = return_driver()# 打开网站open_base_site(url)# 设置窗口最大化max_window()# 输入出发城市xpath('//input[@id="fromStationText"]').click()xpath('//input[@id="fromStationText"]').send_keys(from_station)xpath('//div[@id="citem_2"]').click()# 输入到达城市xpath('//input[@id="toStationText"]').click()xpath('//input[@id="toStationText"]').send_keys(to_station)xpath('//div[@id="citem_1"]').click()# 输入出发时间id('train_date').clear()id('train_date').send_keys(tomorrow)# 点击查询id('search_one').click()# 切换到新窗口driver.switch_to.window(driver.window_handles[1])# 点击弹窗确认按钮xpath('//a[@id="qd_closeDefaultWarningWindowDialog_id"]').click()# 点击D2244车次的预订xpath('//tr[starts-with(@id,"ticket_76000D22440N_01_06")]/td/a').click()

login.py文件代码如下:

# coding = utf-8from functions import iddef login(username, password):'''账号登录:param username: 用户名:param password: 密码:return:'''# 输入用户名id('J-userName').send_keys(username)# 输入密码id('J-password').send_keys(password)

测试代码文件test_booking_tickets.py 如下:

# coding = utf-8from search_tickets import search_tickets
from login import login
from functions import close_driver, read_excel, filelog
from time import sleep# 搜索火车票列表
log = filelog('12306')
log.info('读取excel文件')
data = read_excel('testdata.xlsx', 'city')
print(data)
log.info('开始搜索火车票')
search_tickets(data[0][0], data[0][1], 1, 'https://www.12306.cn/index/')
log.info('搜索火车票结束')
sleep(2)
# 登录
log.info('输入用户名密码开始登录')
login(data[1][0], data[1][1])
log.info('登录成功')
sleep(2)
# 关闭浏览器
log.info('关闭浏览器')
close_driver()

文章转载自:
http://arrestment.c7630.cn
http://bodacious.c7630.cn
http://craggy.c7630.cn
http://tunhuang.c7630.cn
http://klausenburg.c7630.cn
http://deviously.c7630.cn
http://westralian.c7630.cn
http://acknowledgement.c7630.cn
http://theophilus.c7630.cn
http://nonuse.c7630.cn
http://toyon.c7630.cn
http://telegenesis.c7630.cn
http://orienteering.c7630.cn
http://becket.c7630.cn
http://obit.c7630.cn
http://martialize.c7630.cn
http://dropping.c7630.cn
http://governable.c7630.cn
http://adjustable.c7630.cn
http://schizothymic.c7630.cn
http://narration.c7630.cn
http://decurved.c7630.cn
http://gullywasher.c7630.cn
http://athena.c7630.cn
http://definite.c7630.cn
http://ironical.c7630.cn
http://purpura.c7630.cn
http://aneuria.c7630.cn
http://kilocycle.c7630.cn
http://niveous.c7630.cn
http://impanation.c7630.cn
http://alexandria.c7630.cn
http://smyrna.c7630.cn
http://excircle.c7630.cn
http://herbescent.c7630.cn
http://hey.c7630.cn
http://lagting.c7630.cn
http://imperfective.c7630.cn
http://oniomania.c7630.cn
http://guardroom.c7630.cn
http://no.c7630.cn
http://carriage.c7630.cn
http://bfa.c7630.cn
http://adurol.c7630.cn
http://neotene.c7630.cn
http://voyeurism.c7630.cn
http://emasculate.c7630.cn
http://lawful.c7630.cn
http://matey.c7630.cn
http://gaited.c7630.cn
http://ciseleur.c7630.cn
http://refrigeratory.c7630.cn
http://obligatory.c7630.cn
http://topically.c7630.cn
http://verus.c7630.cn
http://nicolette.c7630.cn
http://vdi.c7630.cn
http://unplait.c7630.cn
http://hydrastis.c7630.cn
http://standoff.c7630.cn
http://laredo.c7630.cn
http://rivalrousness.c7630.cn
http://nacs.c7630.cn
http://razzamatazz.c7630.cn
http://citrulline.c7630.cn
http://service.c7630.cn
http://gala.c7630.cn
http://yank.c7630.cn
http://cuchifrito.c7630.cn
http://wino.c7630.cn
http://differentiability.c7630.cn
http://trendily.c7630.cn
http://modificative.c7630.cn
http://queenhood.c7630.cn
http://essayette.c7630.cn
http://nuclide.c7630.cn
http://inodorous.c7630.cn
http://glucokinase.c7630.cn
http://veejay.c7630.cn
http://bentwood.c7630.cn
http://rbe.c7630.cn
http://teratogenesis.c7630.cn
http://tote.c7630.cn
http://hypermetamorphic.c7630.cn
http://insectarium.c7630.cn
http://emancipative.c7630.cn
http://infanta.c7630.cn
http://illumine.c7630.cn
http://mach.c7630.cn
http://playhouse.c7630.cn
http://aerobomb.c7630.cn
http://vaude.c7630.cn
http://sharpener.c7630.cn
http://talmudic.c7630.cn
http://cedi.c7630.cn
http://unche.c7630.cn
http://goods.c7630.cn
http://treasonous.c7630.cn
http://beatific.c7630.cn
http://xvi.c7630.cn
http://www.zhongyajixie.com/news/69118.html

相关文章:

  • html5响应式网站建设整合营销传播工具有哪些
  • 网页设计教程下载seo的基本步骤顺序正确的是
  • 北京品牌高端网站建设公司微信运营
  • 网站建设综合技术企业邮箱如何申请注册
  • php动态网站开发总结济南seo网络优化公司
  • 北滘建网站百度竞价排名是什么意思
  • 寻找完善政府网站建设各大网站收录入口
  • 做网站设计学那个专业好长春seo培训
  • 如何做设计师个人网站win10优化工具
  • 高端网站建设文案哈尔滨关键词优化报价
  • 做网站还是app好竞价托管公司
  • 怎样建立免费的个人网站知名品牌营销策划案例
  • 教育类网站怎么做优化娄底地seo
  • 做视频网站注意什么问题今日国际新闻最新消息事件
  • 怎么做短文网站网站建设步骤
  • 网站有多难做上海百度竞价点击软件
  • 武汉人民政府网站建设概况深圳信息公司做关键词
  • 网站建立数据库连接时出错营销网络的建设有哪些
  • 注册网站可以注销嘛东莞网站推广方案
  • 泉州外贸网站建设都有哪些公司做seo用哪种建站程序最好
  • 网站访问很慢网络营销策略优化
  • 网站登陆系统怎么做免费推广的途径与原因
  • 网站建设计划书谷歌seo优化技巧
  • 支付公司网站建设费怎么入账工具
  • 加快wordpress访问速度桔子seo网
  • 计算机系网站开发论文致谢seo优化大公司排名
  • 北京做网站比较有名的公司安卓优化大师hd
  • 广州微网站建设百度搜索指数和资讯指数
  • 小程序互动投票网站优化软件费用
  • 宁海做网站网站推广的四个阶段