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

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

在这里插入图片描述

自动化博客项目

  • 用户注册
  • 登录验证
    • 效验个人博客列表页博客数量不为 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);
        //验证url
        String cur_url = webDriver.getCurrentUrl();
        Assertions.assertEquals(blog_list_url, cur_url);

    }

在这里插入图片描述

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

在这里插入图片描述

@Order(3)
    @Test
    //效验 个人博客列表页博客数量不为 0
    void 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)
    @Test
    void 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=15
        String 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.kler.cn/news/109114.html

相关文章:

  • 论坛介绍 | COSCon'23 开源文化(GL)
  • 算法笔记【6】-简单选择排序算法
  • 关于使用ScriptObject作为项目数据配置
  • 私有云:【11】win10安装Agent客户端组件
  • 【Linux】环境变量
  • GoLong的学习之路(十一)语法之标准库 fmt.Printf的使用
  • JDK、JRE及JVM的关系及作用
  • web:[网鼎杯 2020 青龙组]AreUSerialz
  • 第44天:前端及html、Http协议
  • ChinaSoft 论坛巡礼 | 智慧化 IDE 论坛
  • day37(事件轮询机制 ajaxGet执行步骤与案例(五个步骤) ajax属性 PHP返回JSON对象(两种))
  • 08 MIT线性代数-求解Ax=b:可解性与结构Complete Solution of Ax=b
  • 设计模式——装饰器模式(Decorator Pattern)+ Spring相关源码
  • el-table多选表格 实现默认选中 删除选中列表取消勾选等联动效果
  • 292_C++_建立流连接,创建多个线程执行I\O异步操作
  • 搭建MyBatis
  • volatile 系列之如何解决可见性问题
  • excel技巧
  • JVM虚拟机:从结构到指令让你对栈有足够的认识
  • Kali安装docker
  • 婚礼的魅力
  • 清华训练营悟道篇之操作系统的内存管理
  • Redis的瓶颈在哪里?
  • 第一章 初识Android
  • 强大易于编辑的流程图组织图绘制工具draw.io Mac苹果中文版
  • Epinoia-有状态网络的意图验证模块,略读
  • JavaWeb复习
  • Leetcode—21.合并两个有序链表【简单】
  • Hadoop学习总结(搭建Hadoop集群(伪分布式模式))
  • c++系列——智能指针