美文网首页UI自动化
2017/06/14Python自动化小工具

2017/06/14Python自动化小工具

作者: 子不语的花未眠 | 来源:发表于2017-06-14 15:08 被阅读35次

    最近在做UI自动化,写了几个小工具,需要自取

    __author__ = 'xiaoj'

    import time

    import shutil#强制删除

    import os

    class Tools:

    #初始化传参,传入driver

    def __init__(self,driver):

    self.driver = driver

    #-----------------------------------上下左右滑动功能-------------------------------

    #获取屏幕大小

    def getSize(self):

    x = self.driver.get_window_size()['width']

    y = self.driver.get_window_size()['height']

    return (x,y)

    #向左滑动

    def swipeLeft(self,t):

    l = self.getSize()

    x1 = int(l[0]*0.9)

    y1 = int(l[1]*0.5)

    x2 = int(l[0]*0.1)

    self.driver.swipe(x1,y1,x2,y1,t)

    #向右滑动

    def swipeRight(self,t):

    l = self.getSize()

    x1 = int(l[0]*0.25)

    y1 = int(l[1]*0.5)

    x2 = int(l[0]*0.75)

    self.driver.swipe(x1,y1,x2,y1,t)

    #向上滑动

    def swipeUp(self,t):

    l = self.getSize()

    x1 = int(l[0]*0.5)

    y1 = int(l[1]*0.8)

    y2 = int(l[1]*0.4)

    self.driver.swipe(x1,y1,x1,y2,t)

    time.sleep(5)

    #向下滑动

    def swipeDown(self,t):

    l = self.getSize()

    x1 = int(l[0]*0.5)

    y1 = int(l[1]*0.25)

    y2 = int(l[1]*0.75)

    self.driver.swipe(x1,y1,x1,y2,t)

    #------------------------------带时间戳的截图功能-------------------------------

    def getTime(self):

    tamp = time.strftime('%H%M%S',time.localtime())#时分秒

    return tamp

    #截图功能

    def getScreenShot(self,path,filename):

    timeA = self.getTime()

    filename = path + filename

    filename = filename + '%s.png'%timeA

    self.driver.get_screenshot_as_file(filename)

    #-----------------------------强制删除文件夹再覆盖截图-------------------------

    def coverUpdate(self,path):

    #强制删除文件夹

    shutil.rmtree(path)

    #重新创建文件夹

    os.mkdir(path)

    #-----------------------------------------查找元素,没找到滑动---------------------------------------

    def findLocal(self):

    x = 1

    while x ==1:

    if self.fact() ==1:

    self.swipeUp(2000)

    time.sleep(3)

    self.fact()

    else:

    print("找到了")

    x = 2

    #递归

    def fact(self):

    n = 1

    try:

    self.driver.find_element_by_id('').click()

    except Exception as e:

    return n

    相关文章

      网友评论

        本文标题:2017/06/14Python自动化小工具

        本文链接:https://www.haomeiwen.com/subject/fdosqxtx.html