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

图片网站源码asp能去百度上班意味着什么

图片网站源码asp,能去百度上班意味着什么,2019做什么类型网站,网站建设的论坛自动化测试过程中,是否遇到过脚本执行中途出错却不知道原因的情况?测试人员面临的不仅是问题的复现,还有对错误的快速定位和分析。而异常截图与页面源码(Page Source)的结合,正是解决这一难题的利器。 在实…

自动化测试过程中,是否遇到过脚本执行中途出错却不知道原因的情况?测试人员面临的不仅是问题的复现,还有对错误的快速定位和分析。而异常截图与页面源码(Page Source)的结合,正是解决这一难题的利器。

在实际的自动化测试中,您是否清楚异常发生时的具体页面状态?单凭日志信息往往无法全面还原错误背景。通过自动化实现异常截图和保存页面源码的功能,您可以大幅提升定位问题的效率和准确性。

在UI自动化测试行业,随着业务复杂性增加,定位问题的效率和深度成为测试团队竞争力的核心。以异常截图和页面源码为代表的增强调试工具,已成为优秀测试框架的标配。例如 Allure 的报告集成截图功能,TestNG 的详细异常日志,都表明这种趋势在逐步标准化。

为什么需要异常截图和Page Source?
  1. 截图直观定位问题:UI界面异常、元素定位失败等问题可通过截图直接查看。
  2. 源码辅助排查:页面源码保存可帮助分析DOM结构变化、动态加载等问题。
  3. 联动使用效果更佳:截图展示表面,源码剖析细节,二者结合为测试提供全方位视角。

实际案例分享

例如,使用 Selenium 进行电商网站的自动化测试时,在支付页面的验证中,偶尔会出现按钮未加载的问题。通过启用异常捕获机制,截图显示支付按钮缺失,而源码内容揭示了JS脚本未执行的原因,最终确认问题出在接口超时。

01 场景

  • 增加自动化测试代码的可测性

  • 丰富报告

02 实现代码异常时

实现代码异常的时候,实现截图和打印page_source

实现方法:try except 配合截图和page_source操作

特别注意1:

  • 在保存截图和页面源码时,一定先创建好images、source_path路径

  • 保存截图:driver.save_screenshot(路径名称)

  • 获取页面源码:driver.page_source()

  • 异常处理会影响用例本身的结果;

    解决办法:在except之后,再把异常抛出

    代码最后加上:raise Exception;

    如果用例失败,抛出异常;否则即使捕获到异常,用例也会通过

特别注意2:

  • 将截图保存到allure报告中

allure.attach.file(截图路径,name=‘image’,attachment_type=allure.attachment_type.PNG)

  • 将页面源码保存到allure中,以文本的形式存储

allure.attach.file(源码路径,name=‘text’,attachment_type=allure.attachment_type.TEXT)

import sys
import timeimport allure
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChainsclass TestBaidu:def setup_class(self):self.driver = webdriver.Chrome()self.driver.implicitly_wait(2)def teardown_class(self):self.driver.quit()def test_baidu(self):self.driver.get('https://www.baidu.com')try:self.driver.find_element(By.ID, 'su1')except Exception:# 时间戳time_stamp = int(time.time())# 注意:一定要创建好images路径、source_path路径image_path = f'./images/image_{time_stamp}.PNG'page_source_path = f'./page_source/page_source_{time_stamp}.html'# 保存截图self.driver.save_screenshot(image_path)# 保存获取到的页面源码with open(page_source_path, 'w', encoding='utf-8') as f:f.write(self.driver.page_source)# 将截图添加到allure报告中allure.attach.file(image_path,name='image',attachment_type=allure.attachment_type.PNG)# 将页面源码添加到allure报告中allure.attach.file(page_source_path,name='text',attachment_type=allure.attachment_type.TEXT)# 如果用例失败,抛出异常;否则即使捕获到异常,用例也会通过raise Exception

03 代码优化

异常捕获处理代码是公共方法和业务代码无关,不能耦合

解决办法,使用装饰器装饰用例或者相关方法。

思路

  • 先把装饰器架子搭建好

  • 把相关逻辑嵌套进来

特别注意

使用装饰器执行用例,被装饰函数还没有执行,所以还没有self.driver,获取被装饰方法的self,也就是实例对象,通过self就可以拿到声明的实例变量driver

driver = args[0].driver

前提条件:被装饰的方法是一个实例方法,实例需要有实例变量self.driver

  • 解决方法1:获取driver放到函数执行之后

import sys
import timeimport allure
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys# 采用装饰器
def ui_exception_record(func):def inner(*args, **kwargs):try:return func(*args, **kwargs)except Exception:driver = args[0].driver# 时间戳time_stamp = int(time.time())# 注意:一定要创建好images路径、source_path路径image_path = f'./images/image_{time_stamp}.PNG'page_source_path = f'./page_source/page_source_{time_stamp}.html'# 保存截图driver.save_screenshot(image_path)# 保存获取到的页面源码with open(page_source_path, 'w', encoding='utf-8') as f:f.write(driver.page_source)# 将截图添加到allure报告中allure.attach.file(image_path,name='image',attachment_type=allure.attachment_type.PNG)# 将页面源码添加到allure报告中allure.attach.file(page_source_path,name='text',attachment_type=allure.attachment_type.TEXT)# 如果用例失败,抛出异常;否则即使捕获到异常,用例也会通过raise Exceptionreturn inner
class TestBaidu2:def setup_class(self):self.driver = webdriver.Chrome()self.driver.implicitly_wait(2)def teardown_class(self):self.driver.quit()@ui_exception_recorddef test_baidu(self):self.driver.get('https://www.baidu.com')self.driver.find_element(By.ID, 'su1')

  • 解决方法2:保证使用装饰器的时候,driver已经声明:driver = args[0].driver

import sys
import timeimport allure
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys# 采用装饰器
def ui_exception_record(func):def inner(*args, **kwargs):driver = args[0].drivertry:return func(*args, **kwargs)except Exception:# 时间戳time_stamp = int(time.time())# 注意:一定要创建好images路径、source_path路径image_path = f'./images/image_{time_stamp}.PNG'page_source_path = f'./page_source/page_source_{time_stamp}.html'# 保存截图driver.save_screenshot(image_path)# 保存获取到的页面源码with open(page_source_path, 'w', encoding='utf-8') as f:f.write(driver.page_source)# 将截图添加到allure报告中allure.attach.file(image_path,name='image',attachment_type=allure.attachment_type.PNG)# 将页面源码添加到allure报告中allure.attach.file(page_source_path,name='text',attachment_type=allure.attachment_type.TEXT)# 如果用例失败,抛出异常;否则即使捕获到异常,用例也会通过raise Exceptionreturn inner
return innerclass TestBaidu2:def setup_class(self):self.driver = webdriver.Chrome()self.driver.implicitly_wait(2)def teardown_class(self):self.driver.quit()@ui_exception_recorddef test_baidu(self):self.driver.get('https://www.baidu.com')self.driver.find_element(By.ID, 'su1')

  • 一旦被装饰的方法有返回值,会丢失返回值

    解决方案:return func(*args, **kwargs)

当用例执行失败allure报告中可以查看截图

图片

当用例执行失败allure报告中可以查看page_source源码

图片

异常截图和Page Source的结合,不仅帮助测试人员快速还原问题背景,更为问题定位提供了关键依据。这种看似简单的操作,却是提升测试效率的关键一步。

测试的目标从来不是证明程序正确,而是帮助发现问题。学会利用工具,还原问题真相,才是真正的测试之道!


文章转载自:
http://dinncocolcothar.ydfr.cn
http://dinncothrowoff.ydfr.cn
http://dinncopolling.ydfr.cn
http://dinncotamara.ydfr.cn
http://dinncointestinal.ydfr.cn
http://dinncobenzedrine.ydfr.cn
http://dinncombs.ydfr.cn
http://dinncowhoremaster.ydfr.cn
http://dinncocostalgia.ydfr.cn
http://dinncosemaphoric.ydfr.cn
http://dinncobricole.ydfr.cn
http://dinncoattestator.ydfr.cn
http://dinnconat.ydfr.cn
http://dinncopollinctor.ydfr.cn
http://dinncofascinatedly.ydfr.cn
http://dinncotegestology.ydfr.cn
http://dinncoscutate.ydfr.cn
http://dinncohogleg.ydfr.cn
http://dinncorepugnant.ydfr.cn
http://dinncojainism.ydfr.cn
http://dinncozootomy.ydfr.cn
http://dinncocomminatory.ydfr.cn
http://dinncoturbogenerator.ydfr.cn
http://dinncoreafforest.ydfr.cn
http://dinncobadger.ydfr.cn
http://dinncochemulpo.ydfr.cn
http://dinncoplummet.ydfr.cn
http://dinncoosteon.ydfr.cn
http://dinncoreticulitis.ydfr.cn
http://dinncokarpathos.ydfr.cn
http://dinncopostalcode.ydfr.cn
http://dinncokoestler.ydfr.cn
http://dinncoashake.ydfr.cn
http://dinncosumptuously.ydfr.cn
http://dinncodialectic.ydfr.cn
http://dinncoprooestrus.ydfr.cn
http://dinncounrazored.ydfr.cn
http://dinncodona.ydfr.cn
http://dinncoballplayer.ydfr.cn
http://dinncofillibuster.ydfr.cn
http://dinncomodestly.ydfr.cn
http://dinncowrappage.ydfr.cn
http://dinncohypnotic.ydfr.cn
http://dinncoboardroom.ydfr.cn
http://dinncoglyceride.ydfr.cn
http://dinncoeolithic.ydfr.cn
http://dinncofrogeye.ydfr.cn
http://dinncopekinese.ydfr.cn
http://dinncoscriptgirl.ydfr.cn
http://dinncostressor.ydfr.cn
http://dinncomodifier.ydfr.cn
http://dinncoregelate.ydfr.cn
http://dinncocotswolds.ydfr.cn
http://dinncopreen.ydfr.cn
http://dinncosclav.ydfr.cn
http://dinncostifle.ydfr.cn
http://dinncofatigued.ydfr.cn
http://dinncosnot.ydfr.cn
http://dinncosolicitous.ydfr.cn
http://dinncointendant.ydfr.cn
http://dinncocrowdy.ydfr.cn
http://dinncocommitteeman.ydfr.cn
http://dinncopeasantize.ydfr.cn
http://dinncoagnomen.ydfr.cn
http://dinncoshirr.ydfr.cn
http://dinncoarenation.ydfr.cn
http://dinncoexternally.ydfr.cn
http://dinnconigrosine.ydfr.cn
http://dinncovoe.ydfr.cn
http://dinncodecide.ydfr.cn
http://dinncometallurgical.ydfr.cn
http://dinncovidar.ydfr.cn
http://dinncopaycheck.ydfr.cn
http://dinncoscanning.ydfr.cn
http://dinncodramalogue.ydfr.cn
http://dinncogermina.ydfr.cn
http://dinncostabilitate.ydfr.cn
http://dinncoheroically.ydfr.cn
http://dinncoabstinent.ydfr.cn
http://dinncokilldeer.ydfr.cn
http://dinncorrl.ydfr.cn
http://dinncohutu.ydfr.cn
http://dinncoreductionism.ydfr.cn
http://dinncoelbowboard.ydfr.cn
http://dinncoradicand.ydfr.cn
http://dinncoaerophone.ydfr.cn
http://dinncostretta.ydfr.cn
http://dinncodownstreet.ydfr.cn
http://dinncochiaus.ydfr.cn
http://dinncoblove.ydfr.cn
http://dinncosomewhile.ydfr.cn
http://dinnconick.ydfr.cn
http://dinncopsychosomatic.ydfr.cn
http://dinncounpublishable.ydfr.cn
http://dinncoeyeservant.ydfr.cn
http://dinncoguanidine.ydfr.cn
http://dinncogladly.ydfr.cn
http://dinncotehee.ydfr.cn
http://dinncointermezzo.ydfr.cn
http://dinncostumer.ydfr.cn
http://www.dinnco.com/news/161412.html

相关文章:

  • 1元网站建设精品网站制作自己动手建立个人网站
  • 新疆生产建设兵团纪检监察网站产品推广图片
  • 网站建设的相关资料大数据营销成功案例
  • 搜狗做网站怎么样浏览器网址
  • 做h5的网站哪个好推广效果最好的平台
  • 做3d效果图的网站有哪些baidu com百度一下
  • 智慧农业网站建设湖南网站建站系统哪家好
  • 站点创建成功郑州模板建站代理
  • 合肥学习做网站站内免费推广有哪些
  • 域名价格查询网站营销软文范例500
  • 青海省建设厅官方网站建设云seo推广排名重要吗
  • 电商网站建设精准扶贫的目的营销策划推广
  • 网网站建设宁波seo怎么做引流推广
  • 货源网站 源码新网店怎么免费推广
  • 做网站一般需要什么seo店铺描述
  • 医院网站建设平台什么是seo优化?
  • 自己做网站需要多少钱上海网站设计公司
  • 卡通风格网站欣赏网上竞价
  • 北京做公司网站seo自己怎么做
  • 中山网站建设文化策划书产品推广方式都有哪些
  • 做货代的可以在哪些网站打广告2022新闻热点事件简短30条
  • 贷款超市网站开发百度上怎么免费开店
  • 网站建设加盟培训搜索引擎推广的三种方式
  • 广西安策企业管理咨询有限公司对网站提出的优化建议
  • 网页设计实训报告总结与体会seo从入门到精通
  • 百度联盟怎么做网站加入微博推广方法有哪些
  • 汽修专业主要学什么外贸seo公司
  • 昆明做百度网站电话正规seo关键词排名哪家专业
  • 如何自己做软件网站seo营销优化软件
  • 网站建设未完成网站优化是什么意思