zoukankan      html  css  js  c++  java
  • Appium-Python3--UI自动化-[-8-]-记一次使用隐式等待:implicitly_wait()的坑

    情景描述:

      APP首次登录时通常会有位置授权操作,APP-UI自动化时需要检测该授权弹框是否存在,如果存在则需要授权,如果不存在则进行下一步

    逻辑代码如下:

            MyLog.logger().info("检查位置授权弹框之前时间为:" + str(datetime.datetime.now()))
            
            # 检查位置授权是否弹出
            is_show = self.login_page_auth_location_check_is_or_not_show()
    
            MyLog.logger().info("检查位置授权弹框之后时间为::" + str(datetime.datetime.now()))
    
            MyLog.logger().info("位置授权是否存在:"+str(is_show))
    
            # app正常启动,截图保存
            common.take_screenShot(self.driver,u"启动页面")
            # MyLog.logger().info("现在时间为3:" + str(datetime.datetime.now()))
    
            if is_show is True:
    
                # 获取位置授权
                self.login_page_auth_location()

    全局的implicitly_wait()时间我设置成30秒

    self.driver.implicitly_wait(30)

    检测授权弹框是否存在的方法:

    # 获取toast元素
    def is_toast_exist(driver, text=None, timeout=5, poll_frequency=0.01):
        try:
    
            toast_loc = ("xpath", ".//*[contains(@text,'%s')]" % text)
            WebDriverWait(driver, timeout, poll_frequency).until(EC.presence_of_element_located(toast_loc))
            return True
    
        except Exception as e:
    
            return False

    无需授权----结果日志显示:

    '''
    2020-02-17 18:43:33,443 INFO test_sales_login_module.test_sales_Login_module Line:38 检查位置授权弹框之前时间为:2020-02-17 18:43:33.443920
    2020-02-17 18:44:05,150 INFO test_sales_login_module.test_sales_Login_module Line:42 检查位置授权弹框之后时间为::2020-02-17 18:44:05.150074
    2020-02-17 18:44:05,150 INFO test_sales_login_module.test_sales_Login_module Line:44 位置授权是否存在:False
    2020-02-17 18:44:05,765 INFO test_sales_login_module.login_username Line:95 ============定位登录员工号输入框。。。。
    2020-02-17 18:44:06,461 INFO test_sales_login_module.login_password Line:105 ============定位登录密码输入框。。。。
    '''

    需进行授权----结果日志显示:

    '''
    2020-02-17 18:55:00,960 INFO test_sales_login_module.test_sales_Login_module Line:38 检查位置授权弹框之前时间为:2020-02-17 18:55:00.960350
    2020-02-17 18:55:04,057 INFO test_sales_login_module.test_sales_Login_module Line:43 检查位置授权弹框之后时间为::2020-02-17 18:55:04.057558
    2020-02-17 18:55:04,057 INFO test_sales_login_module.test_sales_Login_module Line:45 位置授权是否存在:True
    2020-02-17 18:55:04,502 INFO test_sales_login_module.login_page_auth_location Line:126 ============接受授权位置按钮。。。。
    2020-02-17 18:55:04,586 INFO test_sales_login_module.login_username Line:96 ============定位登录员工号输入框。。。。
    2020-02-17 18:55:06,335 INFO test_sales_login_module.login_password Line:106 ============定位登录密码输入框。。。。
    '''

    分析:

    1.如果【需进行授权】,检查弹框花费了不到4s的时间

    2.如果 【无需授权】,检查弹框花费了大约30s多的时间

    因此得出,无需授权时,等待时间太长,全局的implicitly_wait()时间设置为30秒

    改进:

    全局的implicitly_wait()时间尽量缩短,否则会影响性能

    1.我们可以将全局时间等待设置3-5s

    2.检测授权弹框是否存在的方法中可以单独设置timeout针对局部操作设置超时时间

    完美解决!!!

  • 相关阅读:
    CDN缓存
    nginx作用
    Linux下4个查找命令which、whereis、locate、find
    @ModelAttribute的用法,与@RequestBody的区别
    将kafka消息解析拷贝
    永久代溢出(java.lang.OutOfMemoryError: PermGen space )
    失败重试机制-递归应用1
    kafka-重复消费-2
    读写分离-延时问题-1
    UILabel处理html标签
  • 原文地址:https://www.cnblogs.com/chushujin/p/12323104.html
Copyright © 2011-2022 走看看