自动化项目实战 [个人博客系统]

在这里插入图片描述

自动化博客项目

  • 用户注册
  • 登录验证
    • 效验个人博客列表页博客数量不为 0
  • 博客系统主页
    • 写博客
  • 我的博客列表页
    • 效验 刚发布的博客的标题和时间
    • 查看 文章详情页
    • 删除文章
      • 效验第一篇博客 不是 "自动化测试"
    • 注销
      • 退出到登录页面,用户名密码为空

用户注册

在这里插入图片描述

 @Order(1)@ParameterizedTest@CsvFileSource(resources = "regmes.csv")void Reg(String username , String password , String password2) throws InterruptedException {webDriver.get("http://211.159.172.237:8080/reg.html");webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//输入注册名webDriver.findElement(By.cssSelector("#username")).sendKeys(username);webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//输入密码webDriver.findElement(By.cssSelector("#password")).sendKeys(password);webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//输入确认密码webDriver.findElement(By.cssSelector("#password2")).sendKeys(password2);webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);sleep(2000);//点击注册webDriver.findElement(By.cssSelector("#submit")).click();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);sleep(2000);webDriver.switchTo().alert().accept();

在这里插入图片描述

登录验证

在这里插入图片描述

 @Order(2)@ParameterizedTest@CsvFileSource(resources = "LoginSuccess.csv")void LoginSuccess(String username , String password , String blog_list_url) throws InterruptedException {//打开登录页webDriver.get("http://211.159.172.237:8080/login.html");webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//输入账号webDriver.findElement(By.cssSelector("#username")).sendKeys(username);webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.findElement(By.cssSelector("#password")).sendKeys(password);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);sleep(3000);webDriver.findElement(By.cssSelector("#submit")).click();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);sleep(1000);//验证urlString cur_url = webDriver.getCurrentUrl();Assertions.assertEquals(blog_list_url, cur_url);}

在这里插入图片描述

效验个人博客列表页博客数量不为 0

在这里插入图片描述

@Order(3)@Test//效验 个人博客列表页博客数量不为 0void MyBlogList() throws InterruptedException {webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);sleep(3000);int title_num = webDriver.findElements(By.cssSelector(".title")).size();Assertions.assertNotEquals(0,title_num);}

博客系统主页

在这里插入图片描述

写博客

在这里插入图片描述

 @Order(4)@Testvoid AddBlog() throws InterruptedException {//到系统主页看看webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(4)")).click();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);sleep(3000);//写博客webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)")).click();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//通过js输入((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"title\").value=\"自动化测试\"");sleep(1500);//点击发布webDriver.findElement(By.cssSelector("body > div.blog-edit-container > div.title > button")).click();sleep(1500);webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//弹窗点击取消webDriver.switchTo().alert().dismiss();String cur_url = webDriver.getCurrentUrl();Assertions.assertEquals("http://211.159.172.237:8080/myblog_list.html",cur_url);sleep(1500);//        webDriver.switchTo().alert().accept();}

我的博客列表页

在这里插入图片描述

效验 刚发布的博客的标题和时间

    @Order(5)@Test//效验已发布博客的标题和时间void BlogInfoChecked() throws InterruptedException {webDriver.get("http://211.159.172.237:8080/myblog_list.html");String first_blog_title = webDriver.findElement(By.cssSelector("#artListDiv > div:nth-child(1) > div.title")).getText();String first_blog_time = webDriver.findElement(By.xpath("//*[@id=\"artListDiv\"]/div[1]/div[2]")).getText();Assertions.assertEquals("自动化测试",first_blog_title);sleep(3000);if(first_blog_time.contains("2023-10-28")) {System.out.println("时间正确");}else {System.out.println("当前时间是 :" + first_blog_time);System.out.println("时间错误");}}

查看 文章详情页

在这里插入图片描述

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BlogCases extends InitAndEnd{public static Stream<Arguments> Generator() {return Stream.of(Arguments.arguments("http://211.159.172.237:8080/blog_content.html","博客正文","自动化测试"));}@Order(6)@ParameterizedTest@MethodSource("Generator")//博客详情页void BlogContent(String expected_url , String expected_title , String expected_blog_title) throws InterruptedException {webDriver.findElement(By.xpath("//*[@id=\"artListDiv\"]/div[1]/a[1]")).click();sleep(3000);//获取当前页面的url , http://211.159.172.237:8080/blog_content.html?aid=15String cur_url = webDriver.getCurrentUrl();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//获取当前页面的标题 , 博客正文String cur_title = webDriver.getTitle();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//获取当前博客的标题 , 自动化测试String blog_title = webDriver.findElement(By.cssSelector("#title")).getText();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//        Assertions.assertEquals(expected_url , cur_url);Assertions.assertEquals(expected_title , cur_title);Assertions.assertEquals(expected_blog_title , blog_title);if(cur_url.contains(expected_url)) {System.out.println("博客详情正确");} else {System.out.println(cur_url);System.out.println("博客详情失败");}sleep(1500);}

删除文章

在这里插入图片描述

效验第一篇博客 不是 “自动化测试”

 @Order(7)@Test//删除刚刚发布的博客void DeleteBlog() throws InterruptedException {webDriver.get("http://211.159.172.237:8080/myblog_list.html");webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.findElement(By.cssSelector("#artListDiv > div:nth-child(1) > a:nth-child(6)")).click();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);sleep(3000);webDriver.switchTo().alert().accept();//效验第一篇博客不是 "自动化测试"String first_blog_title = webDriver.findElement(By.cssSelector("#artListDiv > div:nth-child(1) > div.title")).getText();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);Assertions.assertNotEquals("自动化测试",first_blog_title);sleep(3000);}

注销

在这里插入图片描述

@Order(8)@Test//注销void Logout() throws InterruptedException {webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
//        webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)"));webDriver.findElement(By.xpath("/html/body/div[1]/a[3]")).click();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);webDriver.switchTo().alert().accept();sleep(3000);String cur_url = webDriver.getCurrentUrl();Assertions.assertEquals("http://211.159.172.237:8080/login.html",cur_url);}

退出到登录页面,用户名密码为空

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/122874.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

QT5.15在Ubuntu22.04上编译流程

在我们日常遇到的很多第三方软件中&#xff0c;有部分软件针对开发人员&#xff0c;并不提供预编译成果物&#xff0c;而是需要开发人员自行编译&#xff0c;此类问题有时候不是问题&#xff08;编译步骤的doc详细且清晰时&#xff09;&#xff0c;但有时候又很棘手&#xff08…

数据结构上机实验——二叉树的实现、二叉树遍历、求二叉树的深度/节点数目/叶节点数目、计算二叉树度为1或2的节点数、判断二叉树是否相似

文章目录 数据结构上机实验1.要求2.二叉树的实现2.1创建一颗二叉树2.2对这棵二叉树进行遍历2.3求二叉树的深度/节点数目/叶节点数目2.4计算二叉树中度为 1 或 2 的结点数2.5判断2棵二叉树是否相似&#xff0c;若相似返回1&#xff0c;否则返回0 3.全部源码测试&#xff1a;Bina…

问题 S: 一只小蜜蜂...(初始化dp)

1.注意点&#xff1a; 该题递推公式为斐波那契数列&#xff0c;而n达到50&#xff0c;是非常大的数 &#xff0c; 故应用循环代替递归&#xff0c;同时记录数据 同时用long long数组储存 ​​ 2.注意点&#xff1a;初始化起点&#xff0c;切忌重新递归找数 可以直接初始化所…

前端重新部署如何通知用户更新

标题解决方案 常用的webSocket解决方案 webSocket; 大致逻辑思考应该是前端在部署好后向服务器发送一个状态变更通知&#xff1b;服务器接收后主动向前端push&#xff1b;前端通过心跳检测&#xff0c;接收到相关更新时弹出提示&#xff0c;让用户确认更新&#xff1b; 缺点&a…

什么是Props?

Props是Vue框架中的一个特性&#xff0c;用于父组件向子组件传递数据。它允许父组件将数据传递给子组件&#xff0c;并在子组件中进行使用和显示。 Props的作用是实现父子组件之间的数据通信。通过Props&#xff0c;父组件可以向子组件传递数据&#xff0c;使得子组件能够接收…

设计一个高效算法,将顺序表L的所有元素逆置,要求算法的空间复杂度为O(1)

初始化及打印函数 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #define MaxSize 10//定义最大长度 int InitArr[10] { 1,2,3,4,5,6,7,8,9,10 };typedef struct {int data[MaxSize];//用静态的数据存放数据元素int length;//顺序表当前长度 }Sqlist;//顺序表的类…

java利用StringTokenizer分割字符串

介绍 利用java.util.StringTokenizer的方法&#xff0c;可以将一个字符串拆分为一系列的标记&#xff08;token&#xff09;。StringTokenizer是为了兼容性原因而保留的遗留类。在新的代码中&#xff0c;不建议使用StringTokenizer&#xff0c;而建议使用String类的split方法来…

Ubuntu自建git服务器

Ubuntu 安装 gitlab-ce sudo apt-get update sudo apt-get install gitlab-ce 安装成功 sudo apt-get install gitlab-ce 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 下列【新】软件包将被安装&#xff1a;gitlab-ce 升…

假如我有一台服务器

如果我有一台服务器&#xff0c;我会认真考虑如何充分利用它的潜力来实现自己的创意项目或支持社区。服务器是一个强大的工具&#xff0c;可以用于各种用途&#xff0c;下面我将分享一些潜在的想法&#xff1a; 1. 创意项目的托管&#xff1a; 首先&#xff0c;我会考虑托管自…

私有云:【5】安装VCenter Server

私有云&#xff1a;【5】安装VCenter Server 1、在本地物理机上安装VCenter Server到Esxi1.1、开始安装第一阶段1.2、开始安装第二阶段 2、配置VCenter2.1、分配许可2.2、添加主机2.3、创建数据存储NFS 1、在本地物理机上安装VCenter Server到Esxi 安装前在AD域服务器配置好VC…

HDU 1062:字符串反转

【题目来源】http://acm.hdu.edu.cn/showproblem.php?pid1062【题目描述】 Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.【输入格式】 The input cont…

MAYA教程之建模基础命令介绍

基础命令 视图相关操作 旋转视图 : ALT 鼠标左键平移视图 : ALT 鼠标中键缩放视图 : 滚动鼠标滚轮 或者 ALT 鼠标右键切换视图 : 空格键回到模型 : F 视图状态 选择状态 : Q移动状态 : W旋转状态 : E缩放状态 : R 视图显示 正常显示 : 1正常圆滑同时显示 : 2圆滑显示 …

MySQL - 覆盖索引、索引下推

覆盖索引&#xff08;Covering Index&#xff09; &#xff1a; 覆盖索引是一种索引&#xff0c;包含了查询中需要的所有列&#xff0c;而不仅仅是索引列本身。这种索引可以通过减少磁盘I/O和提高查询性能来优化数据库查询。当一个查询可以完全通过覆盖索引满足时&#xff0c;数…

java 使用策略模式减少if

使用多态&#xff1a;通过使用面向对象的多态特性&#xff0c;可以将不同的逻辑封装到不同的类中&#xff0c;避免大量的 if 语句。使用继承和接口来定义通用的方法&#xff0c;并让具体的实现类实现这些方法。 使用设计模式&#xff1a;使用设计模式可以更好地组织和管理代码逻…

设计模式:责任链模式(C#、JAVA、JavaScript、C++、Python、Go、PHP)

上一篇《享元模式》 下一篇《解释器模式》 简介&#xff1a; 责任链模式&#xff0c;它是一种行为型设计模式&#xff0c;它将许多对象连接起来形成一条链&#xff0c;每个对象处理不同的请求&#xff0c…

word页脚设置,页脚显示第几页共有几页设置步骤

word页脚设置&#xff0c;页脚显示第几页共有几页设置步骤&#xff1a; 具体步骤&#xff1a; 步骤1&#xff1a; 步骤1.1选择页脚---空白页脚 步骤1.2&#xff0c;在"[在此处键入]"&#xff0c;直接输入你需要的格式&#xff0c;如 “第页/共页” 步骤1.3选择第“…

第四部分:JavaScript

一&#xff1a;jQuery 1.1&#xff1a;jQuery介绍 什么是jQuery&#xff1f; jQuery是JavaScript和查询&#xff08;Query&#xff09;&#xff0c;它是辅助JavaScript开发的js类库 jQuery的核心思想 核心思想是write less&#xff0c;do more&#xff0c;所以它实现了很多浏览…

jmeter BeanShell预处理程序:报错JSONObject not found in namespace

1、jmeter运行报错: ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ". . . : Typed variable declaration : Class: JSONObject not found in namespace WARN o.a.j.m.BeanShellPreProcessor: Problem…

AI:40-基于深度学习的森林火灾识别

🚀 本文选自专栏:AI领域专栏 从基础到实践,深入了解算法、案例和最新趋势。无论你是初学者还是经验丰富的数据科学家,通过案例和项目实践,掌握核心概念和实用技能。每篇案例都包含代码实例,详细讲解供大家学习。 📌📌📌本专栏包含以下学习方向: 机器学习、深度学…

【Java】LinkedList 集合

LinkedList集合特点 LinkedList 底层基于双向链表实现增删 效率非常高&#xff0c;查询效率非常低。 LinkedList源码解读分析 LinkedList 是双向链表实现的 ListLinkedList 是非线程安全的&#xff08;线程是不安全的&#xff09;LinkedList 元素允许为null,允许重复元素Linked…