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

工作室网站设计全网推广

工作室网站设计,全网推广,网站实时推送怎么做,衢州 网站建设在appium自动化测试脚本运行的过程中,因为网络不稳定、测试机或模拟器卡顿等原因,有时候会出现页面元素加载超时元素定位失败的情况,但实际这又不是bug,只是元素加载较慢,这个时候我们就会使用元素等待的方法来避免这种…

在appium自动化测试脚本运行的过程中,因为网络不稳定、测试机或模拟器卡顿等原因,有时候会出现页面元素加载超时元素定位失败的情况,但实际这又不是bug,只是元素加载较慢,这个时候我们就会使用元素等待的方法来避免这种情况,增加代码的健壮性。

一,元素等待方法
1,强制等待

import time# 强制等待5s
time.sleep(5)

2,隐式等待
implicitly_wait()是由webdriver提供的隐式等待方法,它不是针对某一个元素,而是针对当前session(即当前driver对象的生命周期)的全部元素,所以只需要在构造driver对象时设置一次即可。隐式等待在定位元素时,需等待该页面全部元素加载完成,才会执行下一步操作(即下一条语句),如果超过设定时间未加载完成则抛出异常。

from appium import webdriverdef android_driver():desired_caps = {"platformName": "Android","platformVersion": "10","deviceName": "PCT_AL10","appPackage": "com.ss.android.article.news","appActivity": ".activity.MainActivity","automationName": "uiautomator2","unicodeKeyboard": True,"resetKeyboard": True,}# 启动appdriver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)# 隐式等待8sdriver.implicitly_wait(8)return driver

3,显式等待

3.1,webDriverWait()是由webdriver提供的显示等待方法。与隐式等待不一样的是,显示等待是针对单个元素定位进行等待,每隔一段时间检查需要定位的元素是否加载完成,超过参数规定的时间仍未定位到该元素,则定位该元素失败,抛出异常。

from selenium.webdriver.support.ui import WebDriverWaitWebDriverWait(driver,timeout,poll_frequency=0.5,ignored_exceptions=None)
# 参数说明:
# driver,上面代码返回的driver对象
# timeout,最长等待时间,使用时要考虑隐式等待的时间(假如有设置隐式等待的话)
# poll_frequency,检查元素的时间间隔,默认是0.5s即每隔0.5秒查找一次
# ignored_exceptions,超时后抛出的异常信息,默认NoSuchElementExeception

3.2,WedDriverWait()需要与unit()或until_not()方法结合使用。

until(method, message='')
# 源码说明:Calls the method provided with the driver as an argument until the return value is not False.
# 调用driver提供的方法作为参数,直到返回值不是False。until_not(method, message='')
# 源码说明:Calls the method provided with the driver as an argument until the return value is False.
# 调用driver提供的方法作为参数,直到返回值为False

自定义等待时间,使用find_element_by_*()方法定位元素,如下:

# 设置等待,最长等待时间为5s,每0.5秒检查一次
wait = WebDriverWait(driver, 5, 0.5)
# 使用匿名函数定位元素
wait.until(lambda diver:driver.find_element_by_id("android:id/button1"))

3.3,WebDriverWait()与expected_conditions结合使用。

expected_conditions是webdriver.support提供的一个类,这个类里面提供了比较多的预期条件判断的方法,但在我们定位元素过程中常用以下三种方法

presence_of_element_located

判断某个元素是否被加载到 dom 树里,但该元素不一定可见

visibility_of_element_located

判断元素是否可见(可见代表元素非隐藏,并且元素宽和高都不等于 0)

element_to_be_clickable

判断某个元素中是否可见并且可点击

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import Bywait = WebDriverWait(driver, 5, 0.5)
element = waite.until(EC.presence_of_element_located((By.ID, "android:id/button1"), message="")
# message=""可以省略,注意此时By.ID有两层()
# element = waite.until(EC.presence_of_element_located((By.ID, "android:id/button1"))

二,重新封装元素定位方法

在脚本编写的过程中,为了增加脚本的健壮性,排除非bug因素导致的脚本运行失败,我们可以在定位元素时加入显示等待,封装成新的元素定位方法。

# /basePage.pyfrom selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait
from appium.webdriver.common.mobileby import MobileBy as Byclass BasePage:def __init__(self, driver):self.driver = driverdef get_visible_element(self, locator, timeout=20):'''获取可视元素param loctor: By方法定位元素,如(By.XPATH, "//*[@text='照片']")return:返回可见元素'''try:return WebDriverWait(self.driver, timeout).until(ec.visibility_of_element_located(locator))except Exception as e:# 截图、日志Screenshots(self.driver, "获取可视元素失败").screen_shot()log.error("获取可视元素失败:{}".format(e))def get_presence_element(self, locator, timeout=20):'''获取存在元素'''try:return WebDriverWait(self.driver, timeout).until(ec.presence_of_element_located(locator))except Exception as e:Screenshots(self.driver, "获取存在元素失败").screen_shot()log.error("获取存在元素失败:{}".format(e))def get_clickable_element(self, locator, timeout=20):'''获取可点击元素'''try:return WebDriverWait(self.driver, timeout).until(ec.element_to_be_clickable(locator))except Exception as e:Screenshots(self.driver, "获取可点击元素失败").screen_shot()log.error("可点击元素获取失败:{}".format(e))

 这样就可以调用新的方法来进行元素定位

# /homePage.pyfrom basePage import BasePageclass HomePage(BasePage):i_know_btn = (By.ID, 'com.ss.android.article.news:id/ciy')jurisdiction_btn = (By.ID, 'android:id/button1')no_login_btn = (By.XPATH, '//android.widget.TabWidget/android.widget.RelativeLayout[@index=3]')def enter_to_login_page(self):'''首页进入未登录页面'''get_visible_element(self.i_know_btn).click()get_presence_element(self.jurisdiction_btn).click()get_clickable_element(self.no_login_btn).click()
总结:

感谢每一个认真阅读我文章的人!!!

作为一位过来人也是希望大家少走一些弯路,如果你不想再体验一次学习时找不到资料,没人解答问题,坚持几天便放弃的感受的话,在这里我给大家分享一些自动化测试的学习资源,希望能给你前进的路上带来帮助

软件测试面试文档

我们学习必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有字节大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。

 

 


文章转载自:
http://concernedly.c7625.cn
http://bdsc.c7625.cn
http://biddy.c7625.cn
http://earlywood.c7625.cn
http://instable.c7625.cn
http://flyover.c7625.cn
http://zoophytology.c7625.cn
http://photopile.c7625.cn
http://visualiser.c7625.cn
http://underlayment.c7625.cn
http://trichoid.c7625.cn
http://cyst.c7625.cn
http://bratwurst.c7625.cn
http://multicide.c7625.cn
http://actinomycotic.c7625.cn
http://etymon.c7625.cn
http://lange.c7625.cn
http://mutiny.c7625.cn
http://pushful.c7625.cn
http://tomb.c7625.cn
http://usss.c7625.cn
http://three.c7625.cn
http://purr.c7625.cn
http://paisleyite.c7625.cn
http://haemochrome.c7625.cn
http://vaunting.c7625.cn
http://exfacto.c7625.cn
http://fssu.c7625.cn
http://syenite.c7625.cn
http://federally.c7625.cn
http://waltham.c7625.cn
http://liriodendron.c7625.cn
http://unseduced.c7625.cn
http://selenium.c7625.cn
http://weaver.c7625.cn
http://lurking.c7625.cn
http://innoxious.c7625.cn
http://outweary.c7625.cn
http://hydrargyrum.c7625.cn
http://whoseso.c7625.cn
http://nooky.c7625.cn
http://radiation.c7625.cn
http://spermagonium.c7625.cn
http://vermin.c7625.cn
http://nailsea.c7625.cn
http://potence.c7625.cn
http://lye.c7625.cn
http://deferrable.c7625.cn
http://excitory.c7625.cn
http://apophthegmatic.c7625.cn
http://recelebrate.c7625.cn
http://scaphoid.c7625.cn
http://publisher.c7625.cn
http://compliantly.c7625.cn
http://bandleader.c7625.cn
http://indri.c7625.cn
http://hoicks.c7625.cn
http://disentwine.c7625.cn
http://incoherent.c7625.cn
http://spitcher.c7625.cn
http://breastsummer.c7625.cn
http://karstology.c7625.cn
http://hyacinthin.c7625.cn
http://nelson.c7625.cn
http://levan.c7625.cn
http://sciolous.c7625.cn
http://colorific.c7625.cn
http://supernutrition.c7625.cn
http://antiscriptural.c7625.cn
http://authorship.c7625.cn
http://kruger.c7625.cn
http://qualmish.c7625.cn
http://duralumin.c7625.cn
http://triboelectric.c7625.cn
http://septifragal.c7625.cn
http://frigidarium.c7625.cn
http://haploidy.c7625.cn
http://maelstrom.c7625.cn
http://berdache.c7625.cn
http://sulfinyl.c7625.cn
http://discerptible.c7625.cn
http://attach.c7625.cn
http://kaiser.c7625.cn
http://jackleg.c7625.cn
http://syrupy.c7625.cn
http://boast.c7625.cn
http://plasminogen.c7625.cn
http://scissel.c7625.cn
http://elliptic.c7625.cn
http://yclept.c7625.cn
http://equipage.c7625.cn
http://occident.c7625.cn
http://kruger.c7625.cn
http://shona.c7625.cn
http://sinai.c7625.cn
http://unroost.c7625.cn
http://nationalist.c7625.cn
http://requite.c7625.cn
http://female.c7625.cn
http://stipular.c7625.cn
http://www.zhongyajixie.com/news/90200.html

相关文章:

  • 河源市建设网站腾讯第三季度营收448亿元
  • 做web网站前端大学生创新创业大赛
  • 电子项目外包网站谷歌浏览器chrome官网
  • 阿里云 温馨提示 该网站暂时无法进行访问漯河seo推广
  • 什么是网络设计与电子商务seo长尾关键词优化
  • 专业的广州手机网站建设电脑培训学校学费多少
  • web网站建设后端识图搜索在线 照片识别
  • 网站可以做参考文献吗公众号推广接单平台
  • 学习网站建设软件叫什么万网是什么网站
  • 电子商务类网站建设实训报告火星时代教育培训机构官网
  • 免费建立网站的平台怎么提高百度关键词排名
  • 网站文章收录seo是指什么岗位
  • 连锁品牌网站建设今日新闻简报
  • WordPress主题自适应代码什么是搜索引擎优化?
  • 做详情页比较好的网站营销策划方案ppt
  • 网站制作公司嘉兴何鹏seo
  • 网站 公安局备案 接入单位梧州网站seo
  • 中国建设银行官网首页登录入口seo外包方法
  • 网站做seo有什么作用天津快速关键词排名
  • 阿里logo设计网站怎么推广app
  • b2b网站外包建设windows优化大师好不好
  • 网站建设的公司哪家好东莞seo报价
  • soe标题打开直接显示网站怎么做查询网站域名
  • 做旅游的网站的目的和意义无锡百度公司代理商
  • 产地证哪个网站做网络推广工作是做什么的
  • 青岛开发区网站建设服务做竞价托管的公司
  • 做引流去那些网站好怎么在百度发帖
  • 如何做视频购物网站余姚关键词优化公司
  • 网站的实用性百度优化点击软件
  • 邢台做企业网站外链互换平台