码迷,mamicode.com
首页 > 移动开发 > 详细

Python+Appium 查找 toast 方法的封装

时间:2018-01-13 20:43:10      阅读:1412      评论:0      收藏:0      [点我收藏+]

标签:timeout   ber   style   except   until   common   pat   png   写法   

使用场景:在操作应用时常见toast弹框,通过toast弹框信息的获取判断当前的某个操作是否成功

引用的包:from selenium.webdriver.support import expected_conditions as EC,\expected_conditions

      from selenium.webdriver.common.by import By
      from selenium.webdriver.support.ui import WebDriverWait

截图如下,查找如下截图中的toast内容,判断给出的值是否与实际toast的值是否相等,相等则正常执行,不相等直接走except异常内容,如下:

  技术分享图片

 

第一种封装方法:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC,\
    expected_conditions

def find_Toast2(self,message): #查找toast值
‘‘‘ method explain:查找toast的值,与find_Toast实现方法一样,只是不同的2种写法 parameter explain:【text】查找的toast值 Usage: device.find_Toast2(‘再按一次退出iBer‘) ‘‘‘ logging.info("查找toast值---‘%s‘" %(message)) try: message = //*[@text=\‘{}\‘].format(message) WebDriverWait(self.driver,5,0.5).until(expected_conditions.presence_of_element_located((By.XPATH,message))) logging.info("查找到toast----%s"%message) return True except: logging.info("未查找到toast----%s"%message) return False

 

第二种封装方法如下:

def find_Toast(self,message,timeout=5,poll_frequency = 0.5):  #查找toast值
        ‘‘‘
        method explain:查找toast的值
        parameter explain:【text】给定的toast值
        Usage:
            device.find_Toast(‘再按一次退出iBer‘)
        ‘‘‘
        logging.info("获取toast值---‘%s‘" %message)
        try:
            toast_loc = ("xpath",".//*[contains(@text,‘%s‘)]" %message)
            WebDriverWait(self.driver,timeout,poll_frequency).until(EC.presence_of_element_located(toast_loc))
            logging.info("查找到toast--‘%s‘"%message)
            return True
        except:
            logging.info("未查找到toast--‘%s‘"%message)
            return False

 说明:

  获取toast的方法封装点击链接:http://www.cnblogs.com/syw20170419/p/8280115.html

Python+Appium 查找 toast 方法的封装

标签:timeout   ber   style   except   until   common   pat   png   写法   

原文地址:https://www.cnblogs.com/syw20170419/p/8280100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!