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

免费b站推广网站2021建网站找哪个公司

免费b站推广网站2021,建网站找哪个公司,seo主管招聘,博客网站的建设前言: 封装Selenium基本操作,让所有页面操作一键调用,让UI自动化框架脱离高成本、低效率时代,将用例的重用性贯彻到极致,让烦人的PO模型变得无所谓,让一个测试小白都能编写并实现自动化。 知识储备前提&a…

前言:

封装Selenium基本操作,让所有页面操作一键调用,让UI自动化框架脱离高成本、低效率时代,将用例的重用性贯彻到极致,让烦人的PO模型变得无所谓,让一个测试小白都能编写并实现自动化。

知识储备前提:熟练python语言理论与实际运用,熟悉selenium库与自动化测试环境配置。

browseroperator.py   浏览器操作
webdriveroperator.py     WEBd页操作

分层设计:基础目录,浏览器操作与WEB操作分开。

一、browseroperator.py 的代码如下:

1、初始化函数def __init__(self),初始化浏览相关参数

2、初始化浏览器方法def open_url(self, **kwargs),先判断使用哪种浏览器。

**kwargs是不定长参数,dict格式,参数只需要传 url='www.baidu.com' ,方法调用只用 opr.open_url(url='www.baidu.com'),打开了浏览器,他会返回webdriver的句柄,调用处接收到全流程操作网站元素。

暂时还未封装IE 、火狐,留给各位朋友们实现吧,让我们一起学习

现在我也找了很多测试的朋友,做了一个分享技术的交流群,共享了很多我们收集的技术文档和视频教程。
如果你不想再体验自学时找不到资源,没人解答问题,坚持几天便放弃的感受
可以加入我们一起交流。而且还有很多在自动化,性能,安全,测试开发等等方面有一定建树的技术大牛
分享他们的经验,还会分享很多直播讲座和技术沙龙
可以免费学习!划重点!开源的!!!
qq群号:110685036【暗号:csdn999】

3、def close_browser(self, **kwargs)关闭浏览器,齐活,一并封装了

import os
import time
from selenium import webdriver
from common.getconf import Config
from common.getfiledir import BASEFACTORYDIRclass BrowserOperator(object):def __init__(self):self.conf = Config()self.driver_path = os.path.join(BASEFACTORYDIR, 'chromedriver.exe')def open_url(self, **kwargs):"""打开网页:param url::return: 返回 webdriver"""try:url = kwargs['locator']except KeyError:return False, '没有URL参数'try:type = self.conf.get('base', 'browser_type')   #从配置文件里取浏览器的类型if type == 'chrome':#处理chrom弹出的info# chrome_options = webdriver.ChromeOptions()# #option.add_argument('disable-infobars')# chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])# self.driver = webdriver.Chrome(options=chrome_options, executable_path=self.driver_path)self.driver = webdriver.Chrome(executable_path=self.driver_path)self.driver.maximize_window()self.driver.get(url)elif type == 'IE':print('IE 浏览器')else:print('火狐浏览器')except Exception as e:return False, ereturn True, self.driverdef close_browser(self, **kwargs):"""关闭浏览器:return:"""self.driver.quit()return True, '关闭浏览器成功'

二、webdriveroperator.py代码如下

1、def __init__(self, driver:Chrome),初始化浏览器返回的deriver句柄,

2、内容不一 一 介绍了,实现了所有页面的操作,定义成功与否判断、日志返回等细节。各位看官细细品尝,细节都在代码里,每个方法注释大体可以说明了这个方法意义,很容易看懂。

还有很多UI操作没有搬运上来,留给各位朋友们去实现吧,让我们一起学习

import os
import timefrom selenium.common.exceptions import NoSuchElementException
from selenium.webdriver import Chrome
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from common.getfiledir import SCREENSHOTDIRclass WebdriverOperator(object):def __init__(self, driver:Chrome):self.driver = driverdef get_screenshot_as_file(self):"""截屏保存:return:返回路径"""pic_name = str.split(str(time.time()), '.')[0] + str.split(str(time.time()), '.')[1] + '.png'screent_path = os.path.join(SCREENSHOTDIR, pic_name)self.driver.get_screenshot_as_file(screent_path)return screent_pathdef gotosleep(self, **kwargs):time.sleep(3)return True, '等待成功'def web_implicitly_wait(self, **kwargs):"""隐式等待:return:type  存时间"""try:s = kwargs['time']except KeyError:s = 10try:self.driver.implicitly_wait(s)except NoSuchElementException:return False, '隐式等待 页面元素未加载完成'return True, '隐式等待 元素加载完成'def web_element_wait(self, **kwargs):"""等待元素可见:return:"""try:type = kwargs['type']locator = kwargs['locator']except KeyError:return False, '未传需要等待元素的定位参数'try:s = kwargs['time']except KeyError:s = 30try:if type == 'id':WebDriverWait(self.driver, s, 0.5).until(EC.visibility_of_element_located((By.ID, locator)))elif type == 'name':WebDriverWait(self.driver, s, 0.5).until(EC.visibility_of_element_located((By.NAME, locator)))elif type == 'class':WebDriverWait(self.driver, s, 0.5).until(EC.visibility_of_element_located((By.CLASS_NAME, locator)))elif type == 'xpath':WebDriverWait(self.driver, s, 0.5).until(EC.visibility_of_element_located((By.XPATH, locator)))elif type == 'css':WebDriverWait(self.driver, s, 0.5).until(EC.visibility_of_element_located((By.CSS_SELECTOR, locator)))else:return False, '不能识别元素类型[' + type + ']'except NoSuchElementException:return False, '元素[' + locator + ']等待出现超时'return True, '元素[' + locator + ']等待出现成功'def find_element(self, type, locator, index = 0):"""定位元素:param type::param itor::param index::return:"""#isinstance(self.driver, selenium.webdriver.Chrome.)type = str.lower(type)try:if type == 'id':elem = self.driver.find_elements_by_id(locator)[index]elif type == 'name':elem = self.driver.find_elements_by_name(locator)[index]elif type == 'class':elem = self.driver.find_elements_by_class_name(locator)[index]elif type == 'xpath':elem = self.driver.find_elements_by_xpath(locator)[index]elif type == 'css':elem = self.driver.find_elements_by_css_selector(locator)[index]else:return False, '不能识别元素类型:[' + type + ']'except Exception:screenshot_path = self.get_screenshot_as_file()return False, '获取[' + type + ']元素[' + locator + ']失败,已截图[' + screenshot_path + '].'return True, elemdef element_click(self, **kwargs):"""点击:param kwargs::return:"""try:type = kwargs['type']locator = kwargs['locator']except KeyError:return False, '缺少传参'try:index = kwargs['index']except KeyError:index = 0_isOK, _strLOG = self.find_element(type, locator, index)if not _isOK:      #元素没找到,返回失败结果return _isOK, _strLOGelem = _strLOGtry:elem.click()except Exception:screenshot_path = self.get_screenshot_as_file()return False, '元素['+ locator +']点击失败,已截图[' + screenshot_path + '].'return True, '元素['+ locator +']点击成功'def element_input(self, **kwargs):"""输入:param kwargs::return:"""try:type = kwargs['type']locator = kwargs['locator']text = str(kwargs['input'])except KeyError:return False, '缺少传参'try:index = kwargs['index']except KeyError:index = 0_isOK, _strLOG = self.find_element(type, locator, index)if not _isOK:  # 元素没找到,返回失败结果return _isOK, _strLOGelem = _strLOG# if 'test' != elem.get_property('type'):     #校验元素是不是text输入框#     screenshot_path = self.get_screenshot_as_file()#     return False, '元素['+ itor +']不是输入框,输入失败,已截图[' + screenshot_path + '].'try:elem.send_keys(text)except Exception:screenshot_path = self.get_screenshot_as_file()return False, '元素['+ locator +']输入['+ text +']失败,已截图[' + screenshot_path + '].'return True, '元素['+ locator +']输入['+ text +']成功'

结语:封装了基础类,还得实现一个工厂,实现统一一个入口执行所有自动化

点赞关注~~~


文章转载自:
http://pechora.tyjp.cn
http://maya.tyjp.cn
http://pro.tyjp.cn
http://speedily.tyjp.cn
http://indiscernible.tyjp.cn
http://antilles.tyjp.cn
http://carrie.tyjp.cn
http://geophyte.tyjp.cn
http://thersitical.tyjp.cn
http://arsonist.tyjp.cn
http://unimpressible.tyjp.cn
http://disparity.tyjp.cn
http://ombrology.tyjp.cn
http://thrang.tyjp.cn
http://substrata.tyjp.cn
http://ness.tyjp.cn
http://amazon.tyjp.cn
http://basal.tyjp.cn
http://menostaxis.tyjp.cn
http://scientize.tyjp.cn
http://keratometry.tyjp.cn
http://satyric.tyjp.cn
http://leftwinger.tyjp.cn
http://coenosarc.tyjp.cn
http://winesap.tyjp.cn
http://feudist.tyjp.cn
http://corporativism.tyjp.cn
http://symptomatology.tyjp.cn
http://sinologist.tyjp.cn
http://flannelet.tyjp.cn
http://sententious.tyjp.cn
http://ponton.tyjp.cn
http://sapele.tyjp.cn
http://melilla.tyjp.cn
http://thyreoid.tyjp.cn
http://tiddledywinks.tyjp.cn
http://finfooted.tyjp.cn
http://marhawk.tyjp.cn
http://dislike.tyjp.cn
http://relive.tyjp.cn
http://logarithmize.tyjp.cn
http://intrusively.tyjp.cn
http://ratifier.tyjp.cn
http://sciaenoid.tyjp.cn
http://gyrostatics.tyjp.cn
http://sanpaku.tyjp.cn
http://infraction.tyjp.cn
http://lachrymal.tyjp.cn
http://smallshot.tyjp.cn
http://hiphuggers.tyjp.cn
http://rfc.tyjp.cn
http://greenskeeper.tyjp.cn
http://agrimony.tyjp.cn
http://insalubrity.tyjp.cn
http://kavaphis.tyjp.cn
http://glassman.tyjp.cn
http://midnight.tyjp.cn
http://kingpin.tyjp.cn
http://unadmired.tyjp.cn
http://picot.tyjp.cn
http://endogamy.tyjp.cn
http://laminectomy.tyjp.cn
http://acatalasemia.tyjp.cn
http://phenformin.tyjp.cn
http://edbiz.tyjp.cn
http://onward.tyjp.cn
http://phloem.tyjp.cn
http://mohammed.tyjp.cn
http://dialogist.tyjp.cn
http://tunney.tyjp.cn
http://gauchist.tyjp.cn
http://macrodontia.tyjp.cn
http://bhakti.tyjp.cn
http://premortuary.tyjp.cn
http://engarland.tyjp.cn
http://cockily.tyjp.cn
http://quadroon.tyjp.cn
http://chemostat.tyjp.cn
http://semisecrecy.tyjp.cn
http://covert.tyjp.cn
http://microlithic.tyjp.cn
http://chiasmatypy.tyjp.cn
http://skywatch.tyjp.cn
http://baroque.tyjp.cn
http://infanta.tyjp.cn
http://unfading.tyjp.cn
http://sorbitol.tyjp.cn
http://nonzero.tyjp.cn
http://acosmist.tyjp.cn
http://formalin.tyjp.cn
http://urea.tyjp.cn
http://drowning.tyjp.cn
http://earwig.tyjp.cn
http://chilly.tyjp.cn
http://chestnut.tyjp.cn
http://imprese.tyjp.cn
http://ascesis.tyjp.cn
http://vase.tyjp.cn
http://crenelate.tyjp.cn
http://cate.tyjp.cn
http://www.dt0577.cn/news/78619.html

相关文章:

  • 谷歌做自己的网站怎样做网站推广
  • 网站建设独立2022最新国际新闻10条简短
  • 自适应网站制作公司seo技术优化
  • 瑞昌市建设局网站百度优化点击软件
  • 怎么免费建设交友网站太原seo外包服务
  • 网站目录怎么做的谷歌广告上海有限公司
  • 使用三剑客做网站阿里妈妈推广网站
  • 车公庙做网站网站建设公司业务
  • 软件交易网seo英文怎么读
  • 做网站如何找客户宁波seo快速优化公司
  • 怎么查网站是哪家制作公司做的无锡网站制作优化
  • 京东网站开发技术电商平台app大全
  • 戏曲网站建设的可行性分析淘宝店铺如何推广
  • 大连网络备案做网站如何给网站做推广
  • 外贸推广方式都有哪些秦皇岛seo招聘
  • 单页滚动 网站企业网站设计公司
  • 怎样快速学好网站建设广告免费发布信息平台
  • 网站开发电脑内存要多少钱seo关键词首页排名
  • 岳池网站制作青岛百度网站排名优化
  • 永信南昌网站建设自己想做个网站怎么做
  • 什么网站做装修的福州seo网址优化公司
  • 小程序助手官网贵州seo学校
  • 襄阳网站seo方法个人博客搭建
  • asp动态网站模板运营商推广5g技术
  • react做前台网站提高基层治理效能
  • 全国妇联官方网站儿童之家建设关联词有哪些 全部
  • 网站建设手机端官网seo推广是什么工作
  • 做配电箱的专门网站关键词抓取工具都有哪些
  • 青岛做网页设计seo工作
  • 手机软件上传网站友情链接检测方法