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

这篇具有很好参考价值的文章主要介绍了自动化项目实战 [个人博客系统]。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

自动化项目实战 [个人博客系统],自动化,windows,运维,1024程序员节,单元测试

用户注册

自动化项目实战 [个人博客系统],自动化,windows,运维,1024程序员节,单元测试

 @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();

自动化项目实战 [个人博客系统],自动化,windows,运维,1024程序员节,单元测试

登录验证

自动化项目实战 [个人博客系统],自动化,windows,运维,1024程序员节,单元测试

 @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);

    }

自动化项目实战 [个人博客系统],自动化,windows,运维,1024程序员节,单元测试

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

自动化项目实战 [个人博客系统],自动化,windows,运维,1024程序员节,单元测试

@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);
    }

博客系统主页

自动化项目实战 [个人博客系统],自动化,windows,运维,1024程序员节,单元测试

写博客

自动化项目实战 [个人博客系统],自动化,windows,运维,1024程序员节,单元测试

 @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();

    }

我的博客列表页

自动化项目实战 [个人博客系统],自动化,windows,运维,1024程序员节,单元测试

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

    @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("时间错误");
        }
    }

查看 文章详情页

自动化项目实战 [个人博客系统],自动化,windows,运维,1024程序员节,单元测试

@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);
    }

删除文章

自动化项目实战 [个人博客系统],自动化,windows,运维,1024程序员节,单元测试

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

 @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);

    }

注销

自动化项目实战 [个人博客系统],自动化,windows,运维,1024程序员节,单元测试

@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);

    }

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

自动化项目实战 [个人博客系统],自动化,windows,运维,1024程序员节,单元测试文章来源地址https://www.toymoban.com/news/detail-718388.html

到了这里,关于自动化项目实战 [个人博客系统]的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • 博客系统实现自动化测试

    博客系统实现自动化测试

    目录 一、设计博客系统的测试用例 二、利用测试用例进行测试  测试登录页面 界面测试  功能测试 测试博客列表页  界面测试 功能测试  测试博客详情页  界面测试 功能测试 博客编辑页测试 界面测试 功能测试  测试的文件放在maven项目的test文件夹下,需要在之前的mav

    2024年02月02日
    浏览(10)
  • 博客系统之自动化测试

    博客系统之自动化测试

    背景: 针对个人博客项目进行测试,个人博客主要由四个页面构成:登录页、列表页、详情页和编辑页,主要功能包括:用户登录功能、发布博客功能、查看文章详情功能、查看文章列表功能、删除文章功能、退出功能。对于个人博客的测试主要就是针对主要功能进行测试,

    2024年02月12日
    浏览(8)
  • 项目实战-RuoYi后台管理系统-登录功能Postman接口自动化脚本分享

        先来回顾一下之前写过的关于RuoYi后台管理系统项目实战相关的几篇文章: 测试项目实战----RuoYi后台管理系统 项目实战-RuoYi后台管理系统-用户管理测试点设计 项目实战-RuoYi后台管理系统-登录相关接口分析 Docker搭建webdis用于提供api查询redis中的数据 项目实战-RuoYi后台管

    2023年04月20日
    浏览(11)
  • 【软件测试】基于博客系统的自动化测试

    【软件测试】基于博客系统的自动化测试

    目录 1.我的博客系统链接 2.使用selenium对博客系统进行自动化测试 1.引入依赖 2.创建公共类 3.创建测试套件类 4.测试登陆界面 5. 测试博客列表页 6.测试写博客页面 7.测试删除博客 8.最终运行结果 用户登录 创建一个maven项目,在pop.xml中引入以下依赖 因为对每一个页面进行测试

    2024年02月15日
    浏览(10)
  • Python+Selenium自动化测试项目实战

    Python+Selenium自动化测试项目实战

    第 1 章 自动化测试 1.1、自动化测试介绍 自动化测试就是通过自动化测试工具帮我们打开浏览器,输入网址,输入账号密码登录,及登录后的操作,总的说来自动化测试就是通过自动化测试脚本来帮我们从繁琐重复的手工测试里面解脱出来,把时间和精力花到更好的地方去,

    2023年04月17日
    浏览(13)
  • 爬虫 + 自动化利器---selenium详解以及实战项目

    什么是selenium Selenium是一个用于Web应用程序测试的工具。 只要在测试用例中把预期的用户行为与结果都描述出来,我们就得到了一个可以自动化运行的功能测试套件。 Selenium测试套件直接运行在浏览器中,就像真正的用户在操作浏览器一样。 Selenium也是一款同样使用Apache Li

    2024年02月09日
    浏览(15)
  • po+selenium+unittest自动化测试项目实战

    po+selenium+unittest自动化测试项目实战

    1、新建一个包名:common(用于存放基本函数封装) (1)在common包下新建一个base.py文件,作用:页面操作封装。base.py文件代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

    2024年01月17日
    浏览(16)
  • Python+selenium自动化测试实战项目(全面,完整,详细)

    前言 之前的文章说过, 要写一篇自动化实战的文章, 这段时间比较忙再加回家过清明一直没有更新,今天整理一下实战项目的代码共大家学习。(注:项目是针对我们公司内部系统的测试,只能内部网络访问,外部网络无法访问) 问: 1.外部网络无法访问,代码也无法运行

    2024年02月13日
    浏览(9)
  • 【python+selenium自动化测试实战项目】全面、完整、详细

    【python+selenium自动化测试实战项目】全面、完整、详细

    项目名称:**公司电子零售会员系统 项目目的:实现电子零售会员系统项目自动化测试执行 项目版本:v1.0 项目目录 项目环境 本版 python 36 pip insatll selenium PyCharm 2017.2.4 Windows 10 10.0 HTMLTestRunner.py 项目框架 unittest单元测试框架 pageobject 设计模式 UI对象库思想 项目设计 1.一个模

    2024年02月06日
    浏览(15)
  • 三天精通Selenium Web 自动化 - 项目实战环境准备

    三天精通Selenium Web 自动化 - 项目实战环境准备

     返回 TestNG,即Testing Next Generation,下一代测试技术,是一套根据JUnit和NUnit思想而构建的利用注释来强化测试功能的一个测试框架,即可以用来做单元测试,也可以用来做集成测试。更多细节可以到官网去了解:TestNG - Welcome 1.1 安装TestNG 打开eclipse,菜单help - Install New Softwa

    2024年02月04日
    浏览(9)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包