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

网站建设趣味解读网站视频要vip怎么看

网站建设趣味解读,网站视频要vip怎么看,望野眼,个人创建网站前言#xff1a; 封装Selenium基本操作#xff0c;让所有页面操作一键调用#xff0c;让UI自动化框架脱离高成本、低效率时代#xff0c;将用例的重用性贯彻到极致#xff0c;让烦人的PO模型变得无所谓#xff0c;让一个测试小白都能编写并实现自动化。 知识储备前提 封装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格式参数只需要传 urlwww.baidu.com ,方法调用只用 opr.open_url(urlwww.baidu.com)打开了浏览器他会返回webdriver的句柄调用处接收到全流程操作网站元素。 暂时还未封装IE 、火狐留给各位朋友们实现吧让我们一起学习 现在我也找了很多测试的朋友做了一个分享技术的交流群共享了很多我们收集的技术文档和视频教程。 如果你不想再体验自学时找不到资源没人解答问题坚持几天便放弃的感受 可以加入我们一起交流。而且还有很多在自动化性能安全测试开发等等方面有一定建树的技术大牛 分享他们的经验还会分享很多直播讲座和技术沙龙 可以免费学习划重点开源的 qq群号110685036【暗号csdn999】 3、def close_browserself, **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: 返回 webdrivertry: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(optionschrome_options, executable_pathself.driver_path)self.driver webdriver.Chrome(executable_pathself.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] .pngscreent_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://www.w-s-a.com/news/457207/

相关文章:

  • 专门教做甜品的网站郑州高新区建设环保局网站
  • 建站公司怎么获客网站建设全网营销
  • 黄石做网站的公司html免费网站模板
  • 做个商城网站怎么做便宜优酷视频网站源码
  • 网站侧边栏导航代码泰兴市住房和建设局网站
  • html网站登录界面模板确定建设电子商务网站目的
  • wordpress 多站点迁移三台网站seo
  • 工信部网站备案文件好网站建设公司地址
  • 怎么做app和网站购物网站单页面怎么做的
  • 西宁专业做网站教育网站建设策划书
  • 个人网站域名怎么起网站建设业务好跑吗
  • 网页设计的网网页设计的网站企业网站怎样做优化
  • 论文中小企业的网站建设域名网站空间
  • 宿迁网站建设联系电话现在出入邯郸最新规定
  • 男女做羞羞的事情网站30岁转行做网站编辑
  • 做企业网站的轻量级cmswordpress 越来越慢
  • 无锡中英文网站建设莱芜网络公司
  • ps软件下载官方网站相关搜索优化软件
  • 世界杯网站源码下载做网站推广代理
  • 用股票代码做网站的wordpress通过标签调用文章
  • iis添加网站ip地址树莓派运行wordpress
  • 网站空间域名多少钱宿迁做网站公司
  • 福州建设企业网站网站交互主要做什么的
  • 英文网站建设方法门户网站特点
  • 腾讯云备案 网站名称萧山城市建设网站
  • 漳浦网站建设网络营销推广策略
  • 龙岗商城网站建设教程百度关键词排名突然没了
  • 深圳网站建设服务哪家有织梦网站模板安装
  • 网站设计与网页制作代码大全网站开发还找到工作吗
  • 给设计网站做图会字体侵权吗站长工具seo综合查询张家界新娘