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

用ps做网站首页顶部图片宣传软文范例

用ps做网站首页顶部图片,宣传软文范例,软件开发流程八个步骤模板,青团智慧团建登录入口小白也能学会的模拟屏幕滑动与手势密码绘制 - 51Testing软件测试网小白也能学会的模拟屏幕滑动与手势密码绘制发表于#xff1a;2019-8-13 13:32 作者#xff1a;linux超 来源#xff1a;博客园前言  App自动化测试中有两个很重要的操作#xff0c;屏幕滑动与绘制手势…小白也能学会的模拟屏幕滑动与手势密码绘制 - 51Testing软件测试网小白也能学会的模拟屏幕滑动与手势密码绘制发表于2019-8-13 13:32  作者linux超   来源博客园前言  App自动化测试中有两个很重要的操作屏幕滑动与绘制手势密码。目前很多App在启动时都存在启动时的引导动画或者加载上下文内容时需要手动上滑或者下滑加载页面所以在自动化测试的过程中模拟手的滑动操作看起来就很重要了第二个比较重要的是模拟手动绘制九宫格完成手势密码的设置这种手势密码在我了解的范围内大多在金融类的app中最常见还有一些对用户信息保密性较好的app中所以模拟绘制手势密码也是app自动化测试中必须掌握的操作那么接下来我们就开始讲解两种操作该如何实现, 在进入正题之前你还应该知道手机中横纵坐标的原点是从屏幕的左上角顶点(0, 0)的位置开始的  滑动屏幕  swipe方法  模拟滑动屏幕的操作我们通过swipe方法实现先看一下这个方法的源代码def swipe(self, start_x, start_y, end_x, end_y, durationNone):  Swipe from one point to another point, for an optional duration.  Args:  start_x (int): x-coordinate at which to start  start_y (int): y-coordinate at which to start  end_x (int): x-coordinate at which to stop  end_y (int): y-coordinate at which to stop  duration (:obj:int, optional): time to take the swipe, in ms.  Usage:  driver.swipe(100, 100, 100, 400)  Returns:  WebElement    # swipe is something like press-wait-move_to-release, which the server  # will translate into the correct action  action TouchAction(self)  action \  .press(xstart_x, ystart_y) \  .wait(msduration) \  .move_to(xend_x, yend_y) \  .release()  action.perform()  return self参数  start_x, start_y : 表示开始滑动时的初始坐标也就是从哪里开始滑动  end_x,   end_y : 表示滑动后的坐标也就是滑动到哪里  duration:     : 表示滑动过程的时间间隔模拟操作时我们**设置个时间间隔避免由于代码运行太快而真机或者模拟器反应比较慢而操作失败单位以毫秒计算  通过源码我们发现swipe方法实际上是使用TouchAction实现的这个类在后面我们仍然会使用主要是模拟一些触屏动作  实现思路  大家可以想象一下平时我们滑动屏幕时是如何操作的例如向左滑动屏幕我们往往是把手放在屏幕的右侧然后按住屏幕向左滑动那么代码如何知道我们从屏幕的哪个位置开始讷那就是坐标了我们可以先获取屏幕的宽高然后按照它的比例计算鼠标的位置坐标我这里取的起始坐标点为屏幕宽度的0.9倍高度的0.5倍大概就是我们实际中滑屏时手指的操作位置。大家可以根据下面播放的动画观察鼠标开始的大概位置和结束位置  接下来我们开始模拟动画中鼠标的操作(人手的操作我用的模拟器所以有鼠标)  首先我们通过get_window_size()方法获取屏幕的宽和高(这个方法返回一个字典)然后计算鼠标的初始位置和结束为止def get_phone_size(self):  获取屏幕的大小  width self.driver.get_window_size()[width]  # 获取屏幕的宽  height self.driver.get_window_size()[height]  # 获取屏幕的高  return width, height通过模拟动画不难看出鼠标大概从起始点坐标(屏幕宽的3/4高的1/2)位置滑动到结束点坐标(屏幕宽1/4高1/2)ok接下来通过swipe()方法实现滑动操作def swipe_left(self, duration300):  左滑  width, height self.get_phone_size  start width * 0.9, height * 0.5  end width * 0.1, height * 0.5  return self.driver.swipe(*start, *end, duration)  def swipe_right(self, duration300):  右滑  width, height self.get_phone_size  start width * 0.9, height * 0.5  end width * 0.1, height * 0.5  return self.driver.swipe(*start, *end, duration)  def swipe_up(self, duration):  上滑  width, height self.get_phone_size  start width * 0.9, height * 0.5  end width * 0.1, height * 0.5  return self.driver.swipe(*start, *end, duration)  def swipe_down(self, duration):  下滑  width, height self.get_phone_size  start width * 0.9, height * 0.5  end width * 0.1, height * 0.5  return self.driver.swipe(*start, *end, duration)方法优化  以上每一个方法调用一次只能滑动一次而且不同的滑动方向需要调用不同的方法使用时比较麻烦。所以我们可以优化一下代码通过调用一个函数实现不同次数不同方向的滑动  使用for循环实现连续的滑动引入direction参数结合字典及反射机制实现根据不同的参数执行不同滑动方向的方法传递num参数控制滑动的次数具体代码如下def skip_welcome_page(self, direction, num3):    滑动页面跳过引导动画  :param direction:  str 滑动方向left, right, up, down  :param num: 滑动次数  :return:    direction_dic {  left: swipe_left,  right: swipe_right,  up: swipe_up,  down: swipe_down  }  time.sleep(3)  if hasattr(self, direction_dic[direction]):  for _ in range(num):  getattr(self, direction_dic[direction])()  # 使用反射执行不同的滑动方法  else:  raise ValueError(参数{}不存在, direction可以为{}任意一个字符串.  format(direction, direction_dic.keys()))以上就是所有滑动屏幕的操作了具体效果我们后面再看(你也可以先试试)  手势密码  TouchAction类  模拟手势密码的绘制我们使用TouchAction类这个类提供了短按压press()方法wait()方法move_to()方法release()方法perform()方法等常用方法下面我简单说明一下这几个方法的作用  press(element, x, y)  : 其中element参数是一个元素对象当element不为空时x和y必须位None如果element为None时x如果不为None那么y也不能位None也就是说在安卓操作系统中element和(x,y)必要传递一个苹果系统可以不传这里不做介绍  wait(duration) : duration是时间以毫秒为单位这个方法的作用是等待一段时间和sleep的作用类似**区别sleep不能被TouchAtion对象访问  release() : 这个方法的作用是结合press等按压动作使用的表示抬起动作  perform()这个方法的作用是使所有的按压及等待release等动作生效  实现思路  模拟大多app中的手势设置密码操作会遇见两种情况一种是9宫格中每一个点的元素都可以通过定位表达式定位到另一种是每个点无法通过定位表达式定位到的只能定位到整体9宫格元素每个点只能通过获取坐标的方式定位那么我们今天模拟绘制手势密码的情况就是第二种如果这种掌握了那么第一种更简单下面我们分析一下该如何获取每一个点的坐标先来看下面的图  上图中的x轴y轴是手机的坐标表示方式请区别数学中的二维坐标其中x轴方向表示手机屏幕的宽度widthy轴方向表示屏幕的高度height原点为(0, 0); 蓝色方框代表9宫格手势操作的整体元素(内部包含9个点)start_x, start_y 代表9宫格元素的起始坐标点start_x也是9宫格起始点距离y轴的距离start_y也是9宫格起始点距离x轴的距离请大家一定理解这几个值的关系下面我们可以通过WebElement对象的rect方法获取9宫格元素的宽高及起始点坐标def get_element_size_location(element):  width element.rect[width]  # 9宫格元素的宽度  height element.rect[height]  # 9宫格坐标的高度  # 9宫格元素的起始坐标点  start_x element.rect[x]  start_y element.rect[y]  return width, height, start_x, start_y除了使用rect方法外你还可以使用location和size方法分别获取元素的起始点坐标和宽高两个方法同样返回字典  element.location -{x: start_x, y: start_y}  element.size -{width: width, height: height}  接下来我们通过9宫格元素的widthheightstart_x, start_y分别计算每个点的坐标 我们按照上图把9宫格元素的width和height分别等分为6等分  前3个点(1, 2, 3)的坐标分别是width, height, start_x, start_y self.get_element_size_location(element)  point_1 {x: int(start_x width * (1 / 6) * 1), y: int(start_y height * (1 / 6) * 1)}  point_2 {x: int(start_x width * (1 / 6) * 3), y: int(start_y height * (1 / 6) * 1)}  point_3 {x: int(start_x width * (1 / 6) * 5), y: int(start_y height * (1 / 6) * 1)}中间3个点(4, 5, 6)的坐标分别为point_4 {x: int(start_x width * (1 / 6) * 1), y: int(start_y height * (1 / 6) * 3)}  point_5 {x: int(start_x width * (1 / 6) * 3), y: int(start_y height * (1 / 6) * 3)}  point_6 {x: int(start_x width * (1 / 6) * 5), y: int(start_y height * (1 / 6) * 3)}最后3个点(7 8 9)的坐标分别为point_7 {x: int(start_x width * (1 / 6) * 1), y: int(start_y height * (1 / 6) * 5)}  point_8 {x: int(start_x width * (1 / 6) * 3), y: int(start_y height * (1 / 6) * 5)}  point_9 {x: int(start_x width * (1 / 6) * 5), y: int(start_y height * (1 / 6) * 5)}下面我们使用TouchAction类中的move_to,wait,release,perform方法实现从一个点移动到另一个点进而实现模拟手势密码的连线操作(链接1-2-3-6-9)TouchAction(driver).press(xpoint_1[x], ypoint_1[y]).wait(300)\  .move_to(xpoint_2[x], ypoint_2[y]).wait(500)\  .move_to(xpoint_3[x], ypoint_3[y]).wait(500)\  .move_to(xpoint_6[x], ypoint_6[y]).wait(500)\  .move_to(xpoint_9[x], ypoint_9[y]).wait(500).release().perform()完整代码  不包含滑动屏幕的代码  base.py  ------------------------------------  Time : 2019/8/6 20:22  Auth : linux超  File : base.py  IDE  : PyCharm  Motto: Real warriors,dare to face the bleak warning,dare to face the incisive error!  QQ   : 28174043qq.com  GROUP: 878565760  ------------------------------------    from appium.webdriver import WebElement  from appium.webdriver.common.touch_action import TouchAction  from appium.webdriver.webdriver import WebDriver  from selenium.webdriver.support.wait import WebDriverWait  from selenium.common.exceptions import NoSuchElementException, TimeoutException  class Base(object):  def __init__(self, driver: WebDriver):  self.driver driver  staticmethod  def get_element_size_location(element):  width element.rect[width]  height element.rect[height]  start_x element.rect[x]  start_y element.rect[y]  return width, height, start_x, start_y  def gesture_password(self, element: WebElement):  width, height, start_x, start_y self.get_element_size_location(element)  point_1 {x: int(start_x width * (1 / 6) * 1), y: int(start_y height * (1 / 6) * 1)}  point_2 {x: int(start_x width * (1 / 6) * 3), y: int(start_y height * (1 / 6) * 1)}  point_3 {x: int(start_x width * (1 / 6) * 5), y: int(start_y height * (1 / 6) * 1)}  point_4 {x: int(start_x width * (1 / 6) * 1), y: int(start_y height * (1 / 6) * 3)}  point_5 {x: int(start_x width * (1 / 6) * 3), y: int(start_y height * (1 / 6) * 3)}  point_6 {x: int(start_x width * (1 / 6) * 5), y: int(start_y height * (1 / 6) * 3)}  point_7 {x: int(start_x width * (1 / 6) * 1), y: int(start_y height * (1 / 6) * 5)}  point_8 {x: int(start_x width * (1 / 6) * 3), y: int(start_y height * (1 / 6) * 5)}  point_9 {x: int(start_x width * (1 / 6) * 5), y: int(start_y height * (1 / 6) * 5)}  TouchAction(self.driver).press(xpoint_1[x], ypoint_1[y]).wait(300) \  .move_to(xpoint_2[x], ypoint_2[y]).wait(500) \  .move_to(xpoint_3[x], ypoint_3[y]).wait(500) \  .move_to(xpoint_6[x], ypoint_6[y]).wait(500) \  .move_to(xpoint_9[x], ypoint_9[y]).wait(500).release().perform()  def find_element(self, locator: tuple, timeout30) - WebElement:  wait WebDriverWait(self.driver, timeout)  try:  element wait.until(lambda driver: driver.find_element(*locator))  return element  except (NoSuchElementException, TimeoutException):  print(no found element {} by {}, format(locator[1], locator[0]))  if __name__ __main__:  pass【测试入门必备】细说Sqlserver与第三方工具相互间的关系
http://www.sadfv.cn/news/224373/

相关文章:

  • 做百度移动端网站排名网站关闭与域名备案
  • 旅游门户网站建设项目招标做公司网站客户群体怎么找
  • 湖南建设厅官方网站房产备案查询系统
  • 网站主色调有几种著名的办公室设计案例
  • lamp网站架构wordpress什么环境速度
  • 建立网站容量上海高品质网站建设公司
  • 小企业网站维护一年多少钱Light模板WordPress
  • 网站建设需要上传数据库吗个人能否做网站
  • 网站开发分析报告新华舆情监测平台
  • 哪个网站查企业信息免费设立
  • 广告公司做网站为何网站不被百度收录
  • 会计题库网站怎么做除了小红书还有什么推广平台
  • 重庆医疗网站建设网站地图的好处
  • 网站关键词多少个好wordpress添加html页面
  • wordpress网站换主题重庆公司社保缴费比例
  • 做外贸网站报价单电子商务网站建设的开发背景
  • 网站首页素材企业还做网站吗
  • 建设一个聊天类的网站wordpress 个人信息编辑
  • 学做标书的网站免费建设旅游网站
  • 网站建设如何推广业务网络设计师证怎么考
  • 找哪里做网站wordpress加入移动端导航
  • 合肥企业网站模板建站做网站服务器要用多大
  • 网站系统管理员网站建设的进度计划
  • dw网站首页制作网站开发项目成本分析之合理性
  • 比较好的h5网站购物网站 开发
  • 成都网站设计公司电话网站设计免费字体
  • 翻译建设企业网站wordpress 分类下怎么调用带有缩略图的文章?
  • 360网站图标怎么做他达那非片能延时多久
  • 青春网站建设工作室网站收录最好的方法
  • 做电路方案设计的网站网站建设08keji