个人博客系统-测试用例+自动化测试

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

一、个人博客系统测试用例

个人博客系统-测试用例+自动化测试,测试用例

二、自动化测试

        使用selenium4 + Junit5单元测试框架,来进行简单的自动化测试。

1. 准备工作

(1)引入依赖,此时的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>myblog-selenium</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.0.0</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-commons</artifactId>
            <version>1.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-reporting</artifactId>
            <version>1.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-suite</artifactId>
            <version>1.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

(2)创建公共类

创建common包,存放公共类。首先创建CommonDriver类来获取驱动。

package com.webAutoTest.common;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.time.Duration;

/**
 * Created with IntelliJ IDEA.
 * Description: 创建驱动对象,并返回该对象
 * User: WangWZ
 * Date: 2023-09-05
 * Time: 9:48
 */
public class CommonDriver {
    //使用单例模式创建驱动
    private static ChromeOptions options = new ChromeOptions();

    public static ChromeDriver driver = null;

    public static ChromeDriver getDriver(){
        if (driver == null) {
            options.addArguments("--remote-allow-origins=*");
            driver = new ChromeDriver(options);
            //创建驱动的时候就加上隐式等待
            //整个测试就都会隐式等待了
            driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        }
        return driver;
    }

}

        如果代码中使用到了进行截图、存储文件的操作以及使用了参数化实现数据来源时,也可以在创建公共类。方便使用。

2. 注册页面 

        后续使用Juit中的 Suit套件 进行执行,所以关闭驱动的方法可以单独一个类。使用@SelectClasses注解执行。

package com.webAutoTest.tests;

import com.webAutoTest.common.CommonDriver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.time.Duration;

/**
 * Created with IntelliJ IDEA.
 * Description: 注册页面测试
 * User: WangWZ
 * Date: 2023-09-05
 * Time: 9:48
 */
public class RegTest {
    //获取驱动对象
    static ChromeDriver driver = CommonDriver.getDriver();

    @BeforeAll
    public static void getURL() {
        driver.get("http://58.87.89.71:8009/reg.html");
        //使用隐式等待渲染页面完成
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    }

    /**
     * 用户名已存在
     * @param username
     * @param password1
     * @param password2
     */
    @ParameterizedTest
    @CsvSource({"王文哲", "456", "456"})
    public void RegNameExist(String username, String password1, String password2) {
        driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);
        driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password1);
        driver.findElement(By.xpath("//*[@id=\"password2\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password2\"]")).sendKeys(password2);
        Alert alert = driver.switchTo().alert();
        String str =alert.getText();
        Assertions.assertEquals("该用户名已被使用,请重新输入", str);
        alert.accept();
    }

    /**
     * 用户名为空
     * @param username
     * @param password1
     * @param password2
     */
    @ParameterizedTest
    @CsvSource({"", "456", "456"})
    public void RegNameNull(String username, String password1, String password2) {
        driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);
        driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password1);
        driver.findElement(By.xpath("//*[@id=\"password2\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password2\"]")).sendKeys(password2);
        Alert alert = driver.switchTo().alert();
        String str =alert.getText();
        Assertions.assertEquals("请先输入用户名", str);
        alert.accept();
    }

    /**
     * 密码为空
     * @param username
     * @param password1
     * @param password2
     */
    @ParameterizedTest
    @CsvSource({"王王文哲", "", ""})
    public void RegPasswordNull(String username, String password1, String password2) {
        driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);
        driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password1);
        driver.findElement(By.xpath("//*[@id=\"password2\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password2\"]")).sendKeys(password2);
        Alert alert = driver.switchTo().alert();
        String str =alert.getText();
        Assertions.assertEquals("请先输入密码", str);
        alert.accept();
    }

    /**
     * 确认密码和密码不一致
     * @param username
     * @param password1
     * @param password2
     */
    @ParameterizedTest
    @CsvSource({"汪汪", "456", "1456"})
    public void RegPasswordDe(String username, String password1, String password2) {
        driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);
        driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password1);
        driver.findElement(By.xpath("//*[@id=\"password2\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password2\"]")).sendKeys(password2);
        Alert alert = driver.switchTo().alert();
        String str =alert.getText();
        Assertions.assertEquals("两次密码输入的不一致,请先检查", str);
        alert.accept();
    }

    /**
     * 用户名或密码中存在特殊字符
     * @param username
     * @param password1
     * @param password2
     */
    @ParameterizedTest
    @CsvSource({"@w王1", "45@6", "45@6"})
    public void RegExistSpecial(String username, String password1, String password2) {
        driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);
        driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password1);
        driver.findElement(By.xpath("//*[@id=\"password2\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password2\"]")).sendKeys(password2);
        Alert alert = driver.switchTo().alert();
        String str =alert.getText();
        Assertions.assertEquals("恭喜,注册成功", str);
        alert.accept();
    }

    /**
     * 注册标题
     */
    @Test
    public void RegTitle() {
        String str = driver.findElement(By.xpath("/html/body/div[2]/div/h3")).getText();
        Assertions.assertEquals("注册",str);
    }

    /**
     * 输入框显示
     */
    @Test
    public void RegNameInput(){
        WebElement element = driver.findElement(By.xpath("//*[@id=\"username\"]"));
        Assertions.assertNotNull(element);
    }
    /**
     * 输入框文字
     */
    @Test
    public void RegUName() {
        String str = driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/span")).getText();
        Assertions.assertEquals("用户名",str);
    }

    /**
     * 密码框显示
     */
    @Test
    public void RegPasswordInput(){
        WebElement element = driver.findElement(By.xpath("//*[@id=\"password\"]"));
        Assertions.assertNotNull(element);
    }
    /**
     * 密码框文字
     */
    @Test
    public void RegPassword() {
        String str = driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/span")).getText();
        Assertions.assertEquals("密码",str);
    }

    /**
     * 确认密码框显示
     */
    @Test
    public void RegPassword2Input(){
        WebElement element = driver.findElement(By.xpath("//*[@id=\"password2\"]"));
        Assertions.assertNotNull(element);
    }
    /**
     * 确认密码框文字
     */
    @Test
    public void RegPassword2() {
        String str = driver.findElement(By.xpath("/html/body/div[2]/div/div[3]/span")).getText();
        Assertions.assertEquals("确认密码",str);
    }

    /**
     * 验证码图片显示
     */
    @Test
    public void RegPhoto(){
        WebElement element = driver.findElement(By.xpath("//*[@id=\"codeimg\"]"));
        Assertions.assertNotNull(element);
    }
    /**
     * 验证码文字
     */
    @Test
    public void RegDraft() {
        String str = driver.findElement(By.xpath("/html/body/div[2]/div/div[4]/span")).getText();
        Assertions.assertEquals("验证码",str);
    }


}

3. 登录页面

package com.webAutoTest.tests;

import com.webAutoTest.common.CommonDriver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.time.Duration;

/**
 * Created with IntelliJ IDEA.
 * Description: 登录页面
 * User: WangWZ
 * Date: 2023-09-05
 * Time: 9:49
 */
public class LoginTest {
    ChromeDriver driver = CommonDriver.getDriver();

    @BeforeEach
    public void getUrl(){
        driver.get("http://58.87.89.71:8009/login.html");
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    }

    /**
     * 正确的用户名和密码
     */
    @ParameterizedTest
    @CsvSource({"王文哲","123"})
    public void LoginTrue(String username, String password) {
        driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);
        driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password);
        driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();
        String str = driver.getCurrentUrl();
        Assertions.assertEquals("http://58.87.89.71:8009/myblog_list.html",str);
        driver.navigate();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    }

    /**
     * 错误的用户名和密码
     */
    @ParameterizedTest
    @CsvSource({"王文哲","1234"})
    public void LoginFalse(String username, String password) {
        driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);
        driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password);
        driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        Alert alert = driver.switchTo().alert();
        String str = alert.getText();
        Assertions.assertEquals("抱歉登录失败,用户名或密码输入错误,请重试!",str);
        alert.accept();
    }

    /**
     * 登录密码为空
     */
    @ParameterizedTest
    @CsvSource({"王文哲",""})
    public void LoginPasswordNull(String username, String password) {
        driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);
        driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password);
        driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        Alert alert = driver.switchTo().alert();
        String str = alert.getText();
        Assertions.assertEquals("请先输入密码!",str);
        alert.accept();
    }

    /**
     * 用户名为空
     */
    @ParameterizedTest
    @CsvSource({"","123"})
    public void LoginNameNull(String username, String password) {
        driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);
        driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password);
        driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        Alert alert = driver.switchTo().alert();
        String str = alert.getText();
        Assertions.assertEquals("请先输入用户名!",str);
        alert.accept();
    }

    /**
     * 密码或用户名有特殊字符
     */
    @ParameterizedTest
    @CsvSource({"@w王1", "45@6"})
    public void Login(String username, String password) {
        driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);
        driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password);
        driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        String str = driver.getCurrentUrl();
        Assertions.assertEquals("http://58.87.89.71:8009/myblog_list.html",str);
        driver.navigate();
    }

    /**
     * 注册按钮功能
     */
    @Test
    public void LoginToReg() {
        driver.findElement(By.xpath("/html/body/div[1]/a[3]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        String str = driver.getCurrentUrl();
        Assertions.assertEquals("http://58.87.89.71:8009/reg.html",str);
        driver.navigate();
    }

    /**
     * 登录标题
     */
    @Test
    public void LoginTitle() {
        String str = driver.findElement(By.xpath("/html/body/div[2]/div/h3")).getText();
        Assertions.assertEquals("登录",str);
    }

    /**
     * 输入框显示
     */
    @Test
    public void LoginNameInput(){
        WebElement element = driver.findElement(By.xpath("//*[@id=\"username\"]"));
        Assertions.assertNotNull(element);
    }
    /**
     * 输入框文字
     */
    @Test
    public void LoginUName() {
        String str = driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/span")).getText();
        Assertions.assertEquals("用户名",str);
    }

    /**
     * 密码框显示
     */
    @Test
    public void LoginPasswordInput(){
        WebElement element = driver.findElement(By.xpath("//*[@id=\"password\"]"));
        Assertions.assertNotNull(element);
    }
    /**
     * 密码框文字
     */
    @Test
    public void LoginPassword() {
        String str = driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/span")).getText();
        Assertions.assertEquals("密码",str);
    }

    /**
     * 登录按钮
     */
    @Test
    public void LoginSub() {
        String str = driver.findElement(By.xpath("//*[@id=\"submit\"]")).getText();
        Assertions.assertEquals("提交",str);
    }





}

4. 列表页面

package com.webAutoTest.tests;

import com.webAutoTest.common.CommonDriver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;

import java.time.Duration;

/**
 * Created with IntelliJ IDEA.
 * Description: 列表页面
 * User: WangWZ
 * Date: 2023-09-05
 * Time: 9:49
 */
public class ListTest {
    ChromeDriver driver = CommonDriver.getDriver();

    @BeforeEach
    public void getUrl(){
        driver.get("http://58.87.89.71:8009/login.html");
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    }

    /**
     * 主页按钮
     */
    @Test
    public void ListToL() {
        driver.findElement(By.xpath("/html/body/div[1]/a[1]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        String str = driver.getCurrentUrl();
        Assertions.assertEquals("http://58.87.89.71:8009/login.html",str);
        driver.navigate();
    }

    /**
     * 写博客按钮
     */
    @Test
    public void ListToEdit() {
        driver.findElement(By.xpath("/html/body/div[1]/a[2]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        String str = driver.getCurrentUrl();
        Assertions.assertEquals("http://58.87.89.71:8009/blog_add.html",str);
        driver.navigate();
    }

    /**
     * 我的主页按钮
     */
    @Test
    public void ListToMyL() {
        driver.findElement(By.xpath("/html/body/div[1]/a[3]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        String str = driver.getCurrentUrl();
        Assertions.assertEquals("http://58.87.89.71:8009/myblog_list.html",str);
        driver.navigate();
    }

    /**
     * 分页功能,第一页
     */
    @Test
    public void ListByPage() {
        driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/button[2]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        Alert alert = driver.switchTo().alert();
        String str = alert.getText();
        Assertions.assertEquals("当前已经在首页了",str);
        alert.accept();
    }



}

5. 写博客页面

package com.webAutoTest.tests;

import com.webAutoTest.common.CommonDriver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;

import java.time.Duration;

/**
 * Created with IntelliJ IDEA.
 * Description:写博客页面
 * User: WangWZ
 * Date: 2023-09-05
 * Time: 9:50
 */
public class EditTest {
    ChromeDriver driver = CommonDriver.getDriver();

    @BeforeEach
    public void getUrl(){
        driver.get("http://58.87.89.71:8009/blog_add.html");
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    }

    /**
     * 标题为空
     */
    @ParameterizedTest
    @CsvSource({"","111111"})
    public void EditTitleNull(String title,String content) {
        driver.findElement(By.xpath("//*[@id=\"title\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"title\"]")).sendKeys(title);
        driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).clear();
        driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).sendKeys(content);
        driver.findElement(By.xpath("/html/body/div[2]/div[1]/button[1]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        Alert alert = driver.switchTo().alert();
        alert.accept();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        Alert alert2 = driver.switchTo().alert();
        String str2 =alert.getText();
        Assertions.assertEquals("请先输入标题!", str2);
        alert.accept();
    }

    /**
     * 内容为空
     */
    @ParameterizedTest
    @CsvSource({"222",""})
    public void EditContentNull(String title,String content) {
        driver.findElement(By.xpath("//*[@id=\"title\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"title\"]")).sendKeys(title);
        driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).clear();
        driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).sendKeys(content);
        driver.findElement(By.xpath("/html/body/div[2]/div[1]/button[1]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        Alert alert = driver.switchTo().alert();
        alert.accept();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        Alert alert2 = driver.switchTo().alert();
        String str2 =alert.getText();
        Assertions.assertEquals("请先输入文章内容!", str2);
        alert.accept();
    }

    /**
     * 发布文章
     */
    @ParameterizedTest
    @CsvSource({"Java精选","数据类型"})
    public void EditSub(String title,String content) {
        driver.findElement(By.xpath("//*[@id=\"title\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"title\"]")).sendKeys(title);
        driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).clear();
        driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).sendKeys(content);
        driver.findElement(By.xpath("/html/body/div[2]/div[1]/button[1]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        Alert alert = driver.switchTo().alert();
        alert.accept();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        Alert alert2 = driver.switchTo().alert();
        String str2 =alert.getText();
        Assertions.assertEquals("恭喜:文章添加成功!是否继续添加文章?", str2);
        alert.dismiss();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        String url = driver.getCurrentUrl();
        Assertions.assertEquals("http://58.87.89.71:8009/myblog_list.html", url);
        driver.navigate();
    }

    /**
     * 存为草稿
     */
    @ParameterizedTest
    @CsvSource({"Java精选2","数据类型2"})
    public void EditSubDraft(String title,String content) {
        driver.findElement(By.xpath("//*[@id=\"title\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"title\"]")).sendKeys(title);
        driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).clear();
        driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).sendKeys(content);
        driver.findElement(By.xpath("/html/body/div[2]/div[1]/button[2]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        Alert alert = driver.switchTo().alert();
        String str =alert.getText();
        Assertions.assertEquals("恭喜:保存草稿成功!", str);
        alert.accept();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

        String url = driver.getCurrentUrl();
        Assertions.assertEquals("http://58.87.89.71:8009/mydraftblog_list.html", url);
        driver.navigate();
    }

}

6.  草稿箱页面

package com.webAutoTest.tests;

import com.webAutoTest.common.CommonDriver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;

import java.time.Duration;

/**
 * Created with IntelliJ IDEA.
 * Description: 草稿箱页面
 * User: WangWZ
 * Date: 2023-09-05
 * Time: 9:49
 */
public class DraftTest {
    ChromeDriver driver = CommonDriver.getDriver();

    @BeforeEach
    public void getUrl(){
        driver.get("http://58.87.89.71:8009/login.html");
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    }

    /**
     * 主页按钮
     */
    @Test
    public void ListToL() {
        driver.findElement(By.xpath("/html/body/div[1]/a[1]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        String str = driver.getCurrentUrl();
        Assertions.assertEquals("http://58.87.89.71:8009/login.html",str);
        driver.navigate();
    }

    /**
     * 写博客按钮
     */
    @Test
    public void ListToEdit() {
        driver.findElement(By.xpath("/html/body/div[1]/a[2]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        String str = driver.getCurrentUrl();
        Assertions.assertEquals("http://58.87.89.71:8009/blog_add.html",str);
        driver.navigate();
    }

    /**
     * 我的主页按钮
     */
    @Test
    public void ListToMyL() {
        driver.findElement(By.xpath("/html/body/div[1]/a[3]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        String str = driver.getCurrentUrl();
        Assertions.assertEquals("http://58.87.89.71:8009/myblog_list.html",str);
        driver.navigate();
    }


}

7. 文章详情页面

package com.webAutoTest.tests;

import com.webAutoTest.common.CommonDriver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;


/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WangWZ
 * Date: 2023-09-05
 * Time: 9:49
 */
public class DetailTest {
    static ChromeDriver driver = CommonDriver.getDriver();
    @BeforeEach
    public void getUrl(){
        driver.get("http://58.87.89.71:8009/mydraftblog_list.html");

    }
    /*
     * 文章文字是否正确
     * */
    @Test
    public void testWz(){
        String text = driver.findElement(By.cssSelector("/html/body/div[2]/div[1]/div/div[1]/span[1]")).getText();
        Assertions.assertEquals("文章",text);
    }
    /*
     * 分类文字是否正确
     * */
    @Test
    public void testFl(){
        String text = driver.findElement(By.cssSelector("/html/body/div[2]/div[1]/div/div[1]/span[2]")).getText();
        Assertions.assertEquals("分类",text);
    }

}

三、使用套件Suit执行

具体Junit注解:Junit 单元测试框架(简单使用)文章来源地址https://www.toymoban.com/news/detail-704182.html

package com.webAutoTest.tests;

import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WangWZ
 * Date: 2023-09-05
 * Time: 16:54
 */
@Suite
@SelectClasses({LoginTest.class,RegTest.class,LoginTest.class,ListTest.class,EditTest.class,DetailTest.class,DriverQuitTest.class})
public class RunSuit {
}

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

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

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

相关文章

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

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

    2024年02月15日
    浏览(43)
  • 博客系统自动化测试项目实战(测试系列9)

    目录 前言: 1.博客前端页面测试用例图 2.测试用例的代码实现 2.1登录页面的测试 2.2博客列表页面的测试 2.3写博客测试 2.4博客详情页面的测试 2.5已发布博客的标题和时间的测试 2.6注销用户的测试 结束语: 之前小编给大家讲解了有关于Selenium和Junit5自动化测试的一些基础知

    2024年02月10日
    浏览(29)
  • Selenium+python怎么搭建自动化测试框架、执行自动化测试用例、生成自动化测试报告、发送测试报告邮件

    本人在网上查找了很多做自动化的教程和实例,偶然的一个机会接触到了selenium,觉得非常好用。后来就在网上查阅各种selenium的教程,但是网上的东西真的是太多了,以至于很多东西参考完后无法系统的学习和应用。 以下整理的只是书中自动化项目的知识内容,介绍怎么搭

    2024年02月05日
    浏览(49)
  • 模型生成自动化测试用例

    自动产生的测试用例本就应该由程序自动执行,这其实也就是NModel推荐的模式。先回过头来看看文章中制作的模型,模型里面将登录、注销、用户名以及密码等要素都抽象出来了,而NModel是以这些抽象出来的动作(登录、注销)和状态(用户名、密码)为依据,产生测试用例

    2024年02月09日
    浏览(37)
  • 【测试】MeterSphere单接口用例、自动化场景用例测试教程

    1、在对应的模块下创建接口 2、接口的详细信息填写 3、为该接口添加测试用例 设置断言规则 4、调试单接口测试用例通过(若不通过,根据请求内容、响应体和断言结果排查错误) 1、根据测试场景将单接口自动化用例进行组合,形成场景自动化测试用 输入场景用例名称,

    2024年02月13日
    浏览(40)
  • pytest自动化测试指定执行测试用例

    1、在控制台执行 打开cmd,进入项目目录 指定执行某个模块  pytest testcasesLogisticsPlatformCarSourcetest_CarSourceList.py 指定执行某个目录及其子目录的所有测试文件  pytest testcasesLogisticsPlatformCarSource 指定执行某个模块的某个类的某个测试用例   pytest testcasesLogisticsPlatformHome_p

    2024年02月15日
    浏览(27)
  • 自动化测试用例设计实例

    在编写用例之间,笔者再次强调几点编写自动化测试用例的原则: 1、一个脚本是一个完整的场景,从用户登陆操作到用户退出系统关闭浏览器。 2、一个脚本脚本只验证一个功能点,不要试图用户登陆系统后把所有的功能都进行验证再退出系统 3、尽量只做功能中正向逻辑的

    2024年02月12日
    浏览(29)
  • 接口自动化测试系列-yml管理测试用例

    项目源码 整体目录结构,目录说明参考 测试用例结构类似httprunner写法,可参考demo 主要核心函数 用例读取转换json 测试用例格式处理函数

    2024年02月09日
    浏览(36)
  • 接口自动化测试系列-excel管理测试用例

    代码源码: 框架结构 excel用例demo excel数据处理 requests请求封装 检查点函数 数据处理工厂 发送邮件函数

    2024年02月10日
    浏览(37)
  • 从0到1精通自动化测试,pytest自动化测试框架,skip跳过用例(八)

    pytest.mark.skip可以标记无法在某些平台上运行的测试功能,或者希望自己失败的测试功能 skip意味着只有在满足某些条件时才希望测试通过,否则pytest应该跳过运行测试。 常见示例是在非Windows平台上跳过仅限Windows的测试,或跳过测试依赖于当前不可用的外部资源(例如数据库

    2024年02月11日
    浏览(42)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包