博客系统测试报告

目录

1.项目背景

2.项目功能

3.测试计划

3.1.测试用例

3.2.自动化测试

3.2.1.注册页

3.2.2.登录页

3.2.3.我的博客列表页

3.2.4.博客列表页

3.2.5.博客添加页

3.2.6.博客详情页

3.2.7.博客编辑页

3.2.8.个人中心页


1.项目背景

博客系统是一个用于个人或小型团队的网络平台,允许用户创建、发布和管理自己的博客文章。随着个人成长和技术进步,越来越多的人选择使用博客来记录和分享他们的思考、经验和知识,以及与读者互动和交流。因此,开发一个个人博客系统,可以提供一个易于使用和管理的界面,帮助用户快速创建和更新博客文章并与读者展开互动交流,是非常有意义的。

2.项目功能

  1. 注册:用户输入用户名和密码,进行注册。
  2. 登录:用户输入注册过的用户名和密码以及正确的验证码进行登录。如果忘记密码,可通过邮箱找回密码。
  3. 主页:支持根据文章获赞数查看总排名和周排名;支持通过关键字搜索对应文章;支持查看当前登录用户博客列表;支持查看所有用户博客列表;支持分页查询;支持写博客;支持个人中心;支持注销退出登录。
  4. 写博客:支持Markdown格式;支持立即发布、定时发布和保存草稿;支持文章实时保存。
  5. 我的博客列表管理:支持对当前登录用户的发布的文章进行查看、修改和删除。查看全文详情可以看到其他用户对该篇文章的评论、赞或踩;文章修改后也支持立即发布、定时发布和保存草稿。
  6. 博客列表管理:支持对所有用户发布的文章进行查看,通过查看全文详情可以关注作者、对文章赞或踩、给文章发表评论。
  7. 个人中心:支持用户修改头像、昵称、登录名、邮箱、密码;显示用户的文章数量、粉丝和关注数量;新注册的用户没有修改个人信息的情况下会有默认的头像和昵称。

3.测试计划

3.1.测试用例

博客系统测试报告_第1张图片

博客系统测试报告_第2张图片

博客系统测试报告_第3张图片

博客系统测试报告_第4张图片

博客系统测试报告_第5张图片博客系统测试报告_第6张图片

博客系统测试报告_第7张图片

3.2.自动化测试

使用Selenium3+Junit5

3.2.1.注册页

/**
 * 密码和确认密码输入不一致
 *
 * @param username
 * @param password
 * @param password2
 * @throws InterruptedException
 */
@Order(1)
@ParameterizedTest
@CsvFileSource(resources = "test05.csv")
public void RegFail1(String username, String password, String password2) throws InterruptedException {
    //打开注册页面
    webDriver.get("http://47.95.157.248:8080/reg.html");
    webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
    webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
    webDriver.findElement(By.cssSelector("#password2")).sendKeys(password2);
    webDriver.findElement(By.cssSelector("#submit")).click();
    webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    Alert alert = webDriver.switchTo().alert();
    String alertText = alert.getText();
    Assertions.assertEquals("两次密码输入不一致,请先检查,重新输入!" ,alertText);
}

博客系统测试报告_第8张图片

/**
 * 密码为空
 *
 * @param username
 * @param password
 * @param password2
 * @throws InterruptedException
 */
@Order(2)
@ParameterizedTest
@CsvSource({"123, '', 123"})
//密码为空
void RegFail2(String username,String password,String password2) throws InterruptedException {
    //打开注册页面
    webDriver.get("http://47.95.157.248:8080/reg.html");
    webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
    webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
    webDriver.findElement(By.cssSelector("#password2")).sendKeys(password2);
    webDriver.findElement(By.cssSelector("#submit")).click();
    webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    Alert alert = webDriver.switchTo().alert();
    String alertText = alert.getText();
    Assertions.assertEquals("请先输入密码!", alertText);
}

/**
 * 用户名为空
 *
 * @param username
 * @param password
 * @param password2
 * @throws InterruptedException
 */
@Order(3)
@ParameterizedTest
@CsvSource({"'', 123, 123"})
void RegFail3(String username, String password, String password2) throws InterruptedException {
    //打开注册页面
    webDriver.get("http://101.201.119.191:8080/reg.html");
    webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
    webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
    webDriver.findElement(By.cssSelector("#password2")).sendKeys(password2);
    webDriver.findElement(By.cssSelector("#submit")).click();
    webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    Alert alert = webDriver.switchTo().alert();
    String alertText = alert.getText();
    Assertions.assertEquals("请先输入用户名!", alertText);
}

/**
 * 注册成功
 *
 * @throws InterruptedException
 */
@Order(4)
@ParameterizedTest
@CsvFileSource(resources = "test04.csv")
void RegSuccess(String username, String password, String password2) throws InterruptedException {
    //打开注册页面
    webDriver.get("http://47.95.157.248:8080/reg.html");
    webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    //输入账号zhi
    webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
    webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    //输入密码123
    webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
    webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    //输入确认密码123
    webDriver.findElement(By.cssSelector("#password2")).sendKeys(password2);
    webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    //点击提交按钮
    webDriver.findElement(By.cssSelector("#submit")).click();
    webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = webDriver.switchTo().alert();
    String alertText = alert.getText();
    Assertions.assertEquals("恭喜:注册成功!", alertText);
    // 关闭弹框
    alert.accept();
}

3.2.2.登录页

/**
 * 用户名错误
 *
 * @param username
 * @param password
 * @throws InterruptedException
 */
@Order(5)
@ParameterizedTest
@CsvFileSource(resources = "test06.csv")
public void LoginFail1(String username, String password, String valicode) throws InterruptedException {
    //打开登录页面
    webDriver.get("http://47.95.157.248:8080/login.html");
    webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
    webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
    webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
    webDriver.findElement(By.cssSelector("#submit")).click();
    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = webDriver.switchTo().alert();
    String alertText = alert.getText();
    Assertions.assertEquals("抱歉:登录失败!用户名不存在!",alertText);
    // 关闭弹框
    alert.accept();
}

/**
 * 密码错误
 *
 * @param username
 * @param password
 * @throws InterruptedException
 */
@Order(6)
@ParameterizedTest
@CsvFileSource(resources = "test07.csv")
public void LoginFail2(String username, String password, String valicode) throws InterruptedException {
    //打开登录页面
    webDriver.get("http://47.95.157.248:8080/login.html");
    webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
    webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
    webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
    webDriver.findElement(By.cssSelector("#submit")).click();
    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = webDriver.switchTo().alert();
    String alertText = alert.getText();
    Assertions.assertEquals("抱歉:登录失败!一天内密码输入错误五次,账户将会被冻结!还剩余:4次机会!", alertText);
    // 关闭弹框
    alert.accept();
}

/**
 * 用户名为空
 *
 * @param username
 * @param password
 * @throws InterruptedException
 */
@Order(7)
@ParameterizedTest
@CsvSource({"'', 123, 1234"})
public void LoginFail3(String username, String password, String valicode) throws InterruptedException {
    //打开登录页面
    webDriver.get("http://47.95.157.248:8080/login.html");
    webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
    webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
    webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
    webDriver.findElement(By.cssSelector("#submit")).click();
    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = webDriver.switchTo().alert();
    String alertText = alert.getText();
    Assertions.assertEquals("请先输入用户名!",alertText);
    // 关闭弹框
    alert.accept();
}

/**
 * 密码为空
 *
 * @param username
 * @param password
 * @throws InterruptedException
 */
@Order(8)
@ParameterizedTest
@CsvSource({"res, '', 1234"})
public void LoginFail4(String username, String password, String valicode) throws InterruptedException {
    //打开登录页面
    webDriver.get("http://47.95.157.248:8080/login.html");
    webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
    webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
    webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
    webDriver.findElement(By.cssSelector("#submit")).click();
    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = webDriver.switchTo().alert();
    String alertText = alert.getText();
    Assertions.assertEquals("请先输入密码!",alertText);
    // 关闭弹框
    alert.accept();
}

/**
 * 验证码错误
 *
 * @param username
 * @param password
 * @throws InterruptedException
 */
@Order(9)
@ParameterizedTest
@CsvFileSource(resources = "test08.csv")
public void LoginFail5(String username, String password, String valicode) throws InterruptedException {
    //打开登录页面
    webDriver.get("http://47.95.157.248:8080/login.html");
    webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
    webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
    webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
    webDriver.findElement(By.cssSelector("#submit")).click();
    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = webDriver.switchTo().alert();
    String alertText = alert.getText();
    Assertions.assertEquals("抱歉:登录失败!验证码错误!", alertText);
    // 关闭弹框
    alert.accept();
}

/**
 * 登陆成功
 *
 * @param username
 * @param password
 * @param valicode
 * @throws InterruptedException
 */
@Order(10)
@ParameterizedTest
@CsvFileSource(resources = "test03.csv")
void LoginSuccess(String username, String password, String valicode) throws InterruptedException {
    //打开登录页面
    webDriver.get("http://47.95.157.248: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);
    webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
    //点击提交按钮
    webDriver.findElement(By.cssSelector("#submit")).click();
    sleep(3000);
    //跳转到列表页
    //获取到当前页面的url
    String cur_url = webDriver.getCurrentUrl();
    Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html", cur_url);
    String cur_name = webDriver.findElement(By.cssSelector("#userNickName")).getText();
    Assertions.assertEquals("用户11", cur_name);
}

3.2.3.我的博客列表页

/**
 * 发布的博客数量不为0
 */
@Order(11)
@Test
void MyBlogList1() {
    //打开博客列表页
    webDriver.get("http://47.95.157.248:8080/myblog_list.html");
    //获取页面上所有博客标题对应的元素
    webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    int title_num = webDriver.findElements(By.cssSelector(".title")).size();
    //如果元素数量局部为0,测试通过
    Assertions.assertNotEquals(0, title_num);
}

/**
 * 点击查看全文按钮能跳转到对应页面
 *
 * @throws InterruptedException
 */
 @Order(12)
 @Test
 void MyBlogList2() throws InterruptedException {
    webDriver.get("http://47.95.157.248:8080/myblog_list.html");
    webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    webDriver.findElement(By.cssSelector("#artlist > div:nth-child(1) > a:nth-child(4)")).click();
    sleep(40);
    String cur_url = webDriver.getCurrentUrl();
    webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    Assertions.assertEquals("http://47.95.157.248:8080/blog_content.html?id=58",cur_url);
}
/**
 * 点击修改按钮能够跳转到对应页面
 *
 * @throws InterruptedException
 */
@Test
void MyBlogList3() throws InterruptedException {
    webDriver.get("http://47.95.157.248:8080/myblog_list.html");
    webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    webDriver.findElement(By.cssSelector("#artlist > div:nth-child(1) > a:nth-child(5)")).click();
    sleep(40);
    String cur_url = webDriver.getCurrentUrl();
    webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    Assertions.assertEquals("http://47.95.157.248:8080/blog_edit.html?id=58",cur_url);
}

3.2.4.博客列表页

package blog;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.concurrent.TimeUnit;
import static java.lang.Thread.sleep;

/**
 * 博客列表页
 */
public class BlogList extends InitAndEnd{
    /**
     * 登陆成功
     *
     * @param username
     * @param password
     * @param valicode
     * @throws InterruptedException
     */
    @Order(1)
    @ParameterizedTest
    @CsvFileSource(resources = "test05.csv")
    void LoginSuccess(String username,String password,String valicode) throws InterruptedException {
        //打开登录页面
        webDriver.get("http://47.95.157.248:8080/login.html");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
        //点击提交按钮
        webDriver.findElement(By.cssSelector("#submit")).click();
        sleep(300);
        //跳转到列表页
        //获取到当前页面的url
        String cur_url = webDriver.getCurrentUrl();
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html",cur_url);
        String cur_name = webDriver.findElement(By.cssSelector("#userNickName")).getText();
        Assertions.assertEquals("用户18",cur_name);
    }

    /**
     * 点击下一页按钮页面能正常跳转
     *
     * @throws InterruptedException
     */
    @Test
    void BlogList2() throws InterruptedException {
        webDriver.get("http://47.95.157.248:8080/blog_list.html");
        WebDriverWait wait = new WebDriverWait(webDriver, 10);
        webDriver.findElement(By.xpath("//*[@id=\"pageDiv\"]/button[3]")).click();
        sleep(300);
        String cur_url = webDriver.getCurrentUrl();
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        Assertions.assertEquals("http://47.95.157.248:8080/blog_list.html?pageIndex=2&pageSize=3&searchName=null", cur_url);
    }

    /**
     * 点击首页按钮页面能正常显示
     *
     * @throws InterruptedException
     */
    @Test
    void BlogList3() throws InterruptedException {
        webDriver.get("http://47.95.157.248:8080/blog_list.html");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#pageDiv > button.button.is-primary")).click();
        WebDriverWait wait = new WebDriverWait(webDriver, 10);
        wait.until(ExpectedConditions.alertIsPresent());
        Alert alert = webDriver.switchTo().alert();
        String alertText = alert.getText();
        Assertions.assertEquals("抱歉:不能跳转啦,当前已经在首页!", alertText);
        // 关闭弹框
        alert.accept();
    }

    /**
     * 点击查看全文按钮能跳转到对应页面
     *
     * @throws InterruptedException
     */
    @Test
    void BlogList1() throws InterruptedException {
        webDriver.get("http://47.95.157.248:8080/blog_list.html");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#artlist > div:nth-child(1) > a")).click();
        sleep(300);
        String cur_url = webDriver.getCurrentUrl();
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        Assertions.assertEquals("http://47.95.157.248:8080/blog_content.html?id=10", cur_url);
    }

    /**
     * 点击博客添加按钮跳转至文章添加页
     */
    @Test
    void BlogList4(){
        webDriver.get("http://47.95.157.248:8080/blog_list.html");
        webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#writeMessage")).click();
        webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        String cur_url = webDriver.getCurrentUrl();
        webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        Assertions.assertEquals("http://47.95.157.248:8080/blog_add.html", cur_url);
    }
}

3.2.5.博客添加页

package blog;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import java.util.concurrent.TimeUnit;
import static java.lang.Thread.sleep;

/**
 * 博客添加页
 */
public class BlogAdd extends InitAndEnd{
    /**
     * 登陆成功
     *
     * @param username
     * @param password
     * @param valicode
     * @throws InterruptedException
     */
    @Order(1)
    @ParameterizedTest
    @CsvFileSource(resources = "test05.csv")
    void LoginSuccess(String username,String password,String valicode) throws InterruptedException {
        //打开登录页面
        webDriver.get("http://47.95.157.248:8080/login.html");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
        //点击提交按钮
        webDriver.findElement(By.cssSelector("#submit")).click();
        sleep(40);
        //跳转到列表页
        //获取到当前页面的url
        String cur_url = webDriver.getCurrentUrl();
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html",cur_url);
        String cur_name = webDriver.findElement(By.cssSelector("#userNickName")).getText();
        Assertions.assertEquals("用户18", cur_name);
    }

    /**
     * 左侧的文章草稿列数目不应该为0(即左侧的草稿列表应该能正常显示)
     */
    //浏览器和驱动版本不一致!
    @Test
    void BlogAdd2(){
        webDriver.get("http://47.95.157.248:8080/blog_add.html");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        int title_num = webDriver.findElements(By.cssSelector("#leftContain > div > header > p")).size();
        Assertions.assertNotEquals(0, title_num);
    }

    /**
     * 点击发布文章按钮文章能正常发布
     */
    //有问题!
    @Test
    void BlogAdd3() throws InterruptedException {
        webDriver.get("http://47.95.157.248:8080/blog_add.html");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        //通过JS脚本进行标题输入
        ((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"title\").value=\"自动化测试\"");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        ///点击发布
        webDriver.findElement(By.cssSelector("body > div.edit-contain > div.blog-edit-container > div.title > button:nth-child(2)")).click();
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

        Alert alert = webDriver.switchTo().alert();
        String alertText = alert.getText();
        Assertions.assertEquals("恭喜:添加成功!是否继续添加文章?", alertText);
        alert.dismiss();
        String cur_url = webDriver.getCurrentUrl();
        Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html", cur_url);

    }
}

3.2.6.博客详情页

package blog;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.By;
import java.util.concurrent.TimeUnit;
import static java.lang.Thread.sleep;

public class BlogContent extends InitAndEnd {
    /**
     * 登陆成功
     * @param username
     * @param password
     * @param valicode
     * @throws InterruptedException
     */
    @Order(1)
    @ParameterizedTest
    @CsvFileSource(resources = "test05.csv")
    void LoginSuccess(String username,String password,String valicode) throws InterruptedException {
        //打开登录页面
        webDriver.get("http://47.95.157.248:8080/login.html");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
        //点击提交按钮
        webDriver.findElement(By.cssSelector("#submit")).click();
        sleep(3000);
//        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        //跳转到列表页
        //获取到当前页面的url
        String cur_url = webDriver.getCurrentUrl();
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html",cur_url);
        String cur_name = webDriver.findElement(By.cssSelector("#userNickName")).getText();
        Assertions.assertEquals("用户18",cur_name);
    }


    /**
     * 点击关注按钮是否能正常关注
     * @throws InterruptedException
     */
    @Test
    void BlogContent1() throws InterruptedException {
        webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(4)")).click();
        webDriver.get("http://47.95.157.248:8080/blog_content.html?id=66");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#pink")).click();
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        String cur_str = webDriver.findElement(By.cssSelector("#pink")).getText();
        Assertions.assertEquals("取消关注", cur_str);
    }

    /**
     * 刷新进入一次页面阅读量是否加1
     * @throws InterruptedException
     */
    @Test
    void BlogContent2() throws InterruptedException {
        webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(4)")).click();
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#artlist > div:nth-child(3) > a")).click();
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        String cur_count = webDriver.findElement(By.cssSelector("#rcount")).getText();
        Assertions.assertEquals("5", cur_count);
    }
}

3.2.7.博客编辑页

package blog;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import java.util.concurrent.TimeUnit;
import static java.lang.Thread.sleep;

public class BlogEdit extends InitAndEnd {
    /**
     * 登陆成功
     * @param username
     * @param password
     * @param valicode
     * @throws InterruptedException
     */
    @Order(1)
    @ParameterizedTest
    @CsvFileSource(resources = "test05.csv")
    void LoginSuccess(String username,String password,String valicode) throws InterruptedException {
        //打开登录页面
        webDriver.get("http://47.95.157.248:8080/login.html");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
        //点击提交按钮
        webDriver.findElement(By.cssSelector("#submit")).click();
        sleep(40);
        //跳转到列表页
        //获取到当前页面的url
        String cur_url = webDriver.getCurrentUrl();
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html", cur_url);
        String cur_name = webDriver.findElement(By.cssSelector("#userNickName")).getText();
        Assertions.assertEquals("用户18", cur_name);
    }

    /**
     * 修改文章后点击发布按钮,文章是否能发布成功
     * @throws InterruptedException
     */
    @Test
    void BlogEdit1() throws InterruptedException {
        webDriver.findElement(By.cssSelector("#artlist > div:nth-child(1) > a:nth-child(5)")).click();
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        //通过JS脚本进行标题输入
        ((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"title\").value=\"自动化测试111\"");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        ///点击发布
        webDriver.findElement(By.cssSelector("body > div.edit-contain > div > div.title > button:nth-child(2)")).click();
        sleep(5000);
        //
        Alert alert = webDriver.switchTo().alert();
        String alertText = alert.getText();
        Assertions.assertEquals("恭喜:成功!",alertText);
        alert.accept();
        String cur_url = webDriver.getCurrentUrl();
        Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html",cur_url);
    }
}

3.2.8.个人中心页

package blog;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import java.util.concurrent.TimeUnit;
import static blog.InitAndEnd.webDriver;
import static java.lang.Thread.sleep;

/**
 * 个人中心页
 */
public class PersonCenter extends InitAndEnd {
    /**
     * 登陆成功
     * @param username
     * @param password
     * @param valicode
     * @throws InterruptedException
     */
    @Order(1)
    @ParameterizedTest
    @CsvFileSource(resources = "test05.csv")
    void LoginSuccess(String username,String password,String valicode) throws InterruptedException {
        //打开登录页面
        webDriver.get("http://47.95.157.248:8080/login.html");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#username")).sendKeys(username);
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#password")).sendKeys(password);
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#valicode")).sendKeys(valicode);
        //点击提交按钮
        webDriver.findElement(By.cssSelector("#submit")).click();
        sleep(3000);
        //跳转到列表页
        //获取到当前页面的url
        String cur_url = webDriver.getCurrentUrl();
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        Assertions.assertEquals("http://47.95.157.248:8080/myblog_list.html", cur_url);
        String cur_name = webDriver.findElement(By.cssSelector("#userNickName")).getText();
        Assertions.assertEquals("用户18", cur_name);
    }

    /**
     * 自己关注列表的数量是否显示正确
     * @throws InterruptedException
     */
    @Test
    void PersonalCenter1() throws InterruptedException {
        webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)")).click();
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        String cur_str = webDriver.findElement(By.cssSelector("#pinkMyCount")).getText();
        Assertions.assertEquals("2", cur_str);
    }

    /**
     * 修改个人信息是否能提交成功
     * @throws InterruptedException
     */
    @Test
    void PersonalCenter2() throws InterruptedException {
        //通过JS脚本进行标题输入
        //输入名称
        ((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"nickname\").value=\"小刘\"");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        //输入登录名
        ((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"username\").value=\"xioaliu\"");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        //输入邮箱
        ((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"email\").value=\"[email protected]\"");
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        //点击提交按钮
        webDriver.findElement(By.cssSelector("#personInfo > div.btn_submit > button.btn")).click();
        sleep(5000);
        //验证是否正确
        Alert alert = webDriver.switchTo().alert();
        String alertText = alert.getText();
        Assertions.assertEquals("恭喜:修改成功!", alertText);
        alert.accept();
    }
}

你可能感兴趣的:(测试,服务器,linux,数据库)