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

【软件测试】:软件测试实战

1. ⾃动化实施步骤

1.1 编写web测试⽤例

在这里插入图片描述

1.2 ⾃动化测试脚本开发

common

public class AutotestUtils {public static EdgeDriver driver;//
创建驱动对象public static EdgeDriver createDriver(){//
驱动对象已经创建好了
/
没有创建if( driver == null){driver = new EdgeDriver();//
创建隐式等待driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));}return driver;}public AutotestUtils(String url){EdgeDriver driver = createDriver();driver.get(url);}public List<String> getTime(){//
⽂件能不能按照天的维度按⽂件夹进⾏保存//
⽂件格式20230212-123030
毫秒SimpleDateFormat sim1 = new SimpleDateFormat("yyyyMMdd-HHmmssSS");SimpleDateFormat sim2 = new SimpleDateFormat("yyyyMMdd");String filename = sim1.format(System.currentTimeMillis());String dirname = sim2.format(System.currentTimeMillis());List<String> list = new ArrayList<>();list.add(dirname);list.add(filename);return  list;}/*** 
获取屏幕截图,把所有的⽤例执⾏的结果保存下来*/public void getScreenShot(String str) throws IOException {List<String> list = getTime();//dir+filename// ./
指的是当前的项⽬路径下,也就是
BlogAutoTest
下// ./src/test/java/com/blogWebAutoTest/dirname/filename// ./src/test/java/com/blogWebAutoTest/20230212/logintest_20230212
123030
毫秒
.png String filename = 
"./src/test/java/com/blogWebAutoTest/"+list.get(0)+"/"+str+"_"+list.get(1)+".png";File srcfile = driver.getScreenshotAs(OutputType.FILE);//
把屏幕截图⽣成的⽂件放到指定的路径FileUtils.copyFile(srcfile,new File(filename));}}

cases/BlogLogin.py

import time
from selenium.webdriver.common.by import By
from common.Utils import BlogDriver
class BlogLogin:url = ""driver = ""def __init__(self): self.url = "http://192.168.47.135:8653/blog_system/blog_login.html" self.driver = BlogDriver.driver self.driver.get(self.url) def loginSucTest(self): time.sleep(2) self.driver.find_element(By.CSS_SELECTOR, "#username").clear() self.driver.find_element(By.CSS_SELECTOR, "#password").clear() self.driver.find_element(By.CSS_SELECTOR, 
"#username").send_keys("admin")self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123") self.driver.find_element(By.CSS_SELECTOR, "#submit").click()# 对登录结果进⾏检测, 如果跳转到了博客列表⻚才算是登录成功了self.driver.find_element(By.CSS_SELECTOR, "body > div.container > 
div.left > div > img")BlogDriver.getScreenShot() self.driver.back()def loginFailTest(self): self.driver.find_element(By.CSS_SELECTOR, "#username").clear() self.driver.find_element(By.CSS_SELECTOR, "#password").clear() self.driver.find_element(By.CSS_SELECTOR, 
"#username").send_keys("admin")self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("111") self.driver.find_element(By.CSS_SELECTOR, "#submit").click()# 等登录失败的结果进⾏检测, 不能仅仅通过body来校验结果,因为登录成功的结果⻚也有
body元素expect = "⽤⼾名或密码错误!"actual = self.driver.find_element(By.CSS_SELECTOR, "body").text print(actual)BlogDriver.getScreenShot() assert expect == actual self.driver.back()

cases/BlogList.py

from selenium.webdriver.common.by import By
from common.Utils import BlogDriverclass BlogList:url = ""driver = ""def __init__(self): self.driver = BlogDriver.driver self.url = "http://192.168.47.135:8653/blog_system/blog_list.html"self.driver.get(self.url)# 前提:登陆状态下才能进⼊到列表⻚ def ListTest(self):self.driver.find_element(By.CSS_SELECTOR, "body > div.container > 
div.left > div > img")self.driver.find_element(By.CSS_SELECTOR, "body > div.container > 
div.right > div:nth-child(1) > a")articles = self.driver.find_elements(By.CSS_SELECTOR, "body > 
div.container > div.right > div")assert len(articles) > 10#点击⽂章self.driver.find_element(By.CSS_SELECTOR,"body > div.container > 
div.right > div:nth-child(1) > a").click()title = self.driver.titleassert title == "博客详情⻚" BlogDriver.getScreenShot()

cases/BlogDetail.py

from selenium.webdriver.common.by import By
from common.Utils import BlogDriverclass BlogDetail:url = " "driver = ""def __init__(self): self.url = "http://192.168.47.135:8653/blog_system/blog_detail.html?
blogId=15"self.driver = BlogDriver.driver title = self.driver.title#列表⻚已经跳过来了,⽆需再指定url跳转if not title=="博客列表⻚":self.driver.get(self.url) def DetailCheck(self):#body > div.container > div.right > div:nth-child(1) > a BlogDriver.getScreenShot() self.driver.find_element(By.CSS_SELECTOR,"body > div.container > 
div.right > div > h3")self.driver.find_element(By.CSS_SELECTOR,"body > div.container > 
div.right > div > div.date")self.driver.find_element(By.CSS_SELECTOR,"#content")

cases/RunCases.py

from common.Utils import BlogDriverfrom tests import BlogLoginfrom tests import BlogListfrom tests import BlogDetailif __name__ == "__main__":BlogLogin.BlogLogin().loginSucTest() BlogList.BlogList().ListTest() BlogDetail.BlogDetail().DetailCheck() BlogDriver.driver.quit()

1.3 将⾃动化测试补充⾄测试报告

测试报告模板:
在这里插入图片描述
在这里插入图片描述


http://www.mrgr.cn/news/96030.html

相关文章:

  • 3.26[a]paracompute homework
  • vue遗漏的知识点(动态组件.)
  • openpnp,cadence SPB17.4,placement - 从allegro中导出坐标文件的选项会影响贴片精度
  • PyTorch处理数据--Dataset和DataLoader
  • 详解java体系实用知识总结
  • K8S学习之基础五十二:k8s配置jenkins
  • 我的世界1.20.1forge模组进阶开发教程——结构(3)
  • 我的世界进阶教程——结构(2)
  • 【C++网络编程】番外篇(实战):基于Boost.Asio协程的HTTP服务器实现与静态文件服务开发指南
  • macOS 制作dmg磁盘映像安装包
  • 2.0 项目管理前言
  • 车载以太网网络测试 -24【SOME/IP概述】
  • 科普:特征、规则、模型,及Lift(提升度)
  • PyTorch图像预处理--Compose
  • Linux面试题
  • 优选算法系列(4.前缀和 _下) k
  • CAS(Compare And Swap)
  • 23种设计模式-观察者(Observer)设计模式
  • ElasticSearch -- 部署完整步骤
  • 黑盒测试与白盒测试详解