一、项目背景
音乐市场规模逐年扩大,音乐专辑管理系统是一款以音乐专辑为核心,为音乐产业上下游企业提供·一个高效的音乐专辑管理工具,以便更好地管理音乐专辑,采用前后端分离的方法来实现,使用了数据库来存储相关的数据,主要技术栈SpringBoot, SpringMVC ,MyBatis, MySQL, vue
二、项目功能
该音乐专辑管理系统主要实现了以下几个功能:登录、注销、用户管理、平台管理、音乐专辑管理、出入库功能

登录功能:用户名以及密码已经在后端写入了数据库,没有实现账户注册功能,即:用户名以及密码是已经存在的。登录成功后就会跳转到页面主页。但是在未登录情况下按下均只会跳转到登录页面。
用户管理:显示关于用户的详细数据,如账户名、姓名、密码、年龄、性别、电话等,增加用户账户、姓名、密码、年龄、性别、电话等用户信息,删除用户、更改用户信息、利用用户姓名查询用户信息,管理和记录系统中的数据,包括数据的录入、编辑、删除和查询等。
平台管理:对于专辑发布平台的信息进行统计和汇总, 方便用户对于专辑平台进行管理,包括数据的录入、编辑、删除和查询等。
专辑管理:主要对专辑信息进行展示,返回音乐专辑对于专辑名、专辑平台、数量、备注等专辑信息进行核对,管理和记录系统中的数据,包括数据的录入、编辑、删除和查询等,对专辑进行出库入库操作,并对专辑库存数量更新。
三、测试计划
根据测试用例使用selenium4自动化测试工具和junit5单元测试框架结合来实现web自动化测试

3.1 功能测试
1.登陆功能
访问网站-> 跳转到登录页面-> 输入测试数据(用户名+密码) ->单击登录

2.添加功能
访问网站-> 点击添加按钮> 输入测试数据 ->单击确定按钮

3.编辑功能
访问网站-> 点击需要编辑的信息对应的operate按钮-> 修改测试数据 ->单击确定

4.删除功能
访问网站-> 点击需要删除信息对应的delete按钮-> 修改测试数据 -> 单击确定
允许用户从系统中删除不再需要或已过期的信息记录,点击对应delete键。

5.出入库功能
访问网站-> 选择出库还是入库操作> 输入测试数据-> 单击确定-> 增加/减去专辑库存数量

3.2 自动化测试
针对音乐专辑管理项目进行测试,主要由四个页面构成:登录页、用户管理、平台管理和专辑管理,主要功能包括:登录、编辑、添加、删除信息等功能。对于音乐专辑管理系统的测试主要就是针对主要功能进行测试。
1.添加依赖
引入 Maven 依赖,添加selenium4自动化测试工具和junit5单元依赖
<dependencies>
<!--        添加selenium依赖-->
        <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>
        <!--        添加junit5依赖-->
        <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-suite</artifactId>
            <version>1.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
 
2.初始化浏览器驱动
测试前置操作,创建浏览器驱动,测试后置操作,关闭浏览器 ,清除访问痕迹
public class InitAndEnd {
    public static WebDriver  webDriver;
    @BeforeAll
    static void setup(){
        webDriver=new ChromeDriver();
    }
    @AfterAll
    static void teardown(){
//        webDriver.quit();
    }
} 
3.登录测试
用户登录测试 主要测试登录成功情况、登录失败和退出登录三种情况情况 ,
创建驱动,并打开页面
 测试页面是否正常打开
 注意测试的顺序,使用Order注解指定,否则可能会因为执行顺序不对导致测试失败
测试正常登录:多参数测试,是否可以正常跳转到主页面
    @ParameterizedTest
    @CsvSource({"gy2,1234,http://192.168.1.107:8080/IndexHome"})
    void exit(String user,String password,String url) throws InterruptedException {
        webDriver.get("http://192.168.1.107:8080/");
//           //输入账号
        webDriver.findElement(By.cssSelector("#user")).sendKeys(user);
           //输入密码
        webDriver.findElement(By.xpath("//*[@id=\"pass\"]/div/div/input")).sendKeys(password);
           //点击登录
        webDriver.findElement(By.cssSelector("#sure")).click();
           //跳转到主页
        sleep(3000);
        String cur_url=webDriver.getCurrentUrl();
        Assertions.assertEquals(url,cur_url);
        ;
        Actions action = new Actions(webDriver);
        WebElement settings =webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/header/div/div[3]/span"));
        action.moveToElement(settings).perform();
        sleep(3000);
        webDriver.findElement(By.xpath("/html/body/ul/li[2]")).click();
        sleep(3000);
        webDriver.findElement(By.xpath("/html/body/div[2]/div/div[3]/button[2]")).click();
//        sleep(3000);
          String cur_url2=webDriver.getCurrentUrl();
//        sleep(3000);
//        Assertions.assertEquals("http://192.168.1.109:8080/",cur_url2);
    } 
测试异常登录:用户名和密码错误的多种情况
 @ParameterizedTest
    @CsvSource({"gy222,1234,http://192.168.1.107:8080/IndexHome"})
    void loginno(String user,String password,String url) throws InterruptedException {
        webDriver.get("http://192.168.1.107:8080/");
//           //输入账号
        webDriver.findElement(By.cssSelector("#user")).sendKeys(user);
           //输入密码
        webDriver.findElement(By.xpath("//*[@id=\"pass\"]/div/div/input")).sendKeys(password);
           //点击登录
        webDriver.findElement(By.cssSelector("#sure")).click();
           //跳转到主页
        sleep(3000);
        String cur_url=webDriver.getCurrentUrl();
        Assertions.assertEquals(url,cur_url);
    } 
测试退出登录
    @ParameterizedTest
    @CsvSource({"gy2,1234,http://192.168.1.107:8080/IndexHome"})
    void exit(String user,String password,String url) throws InterruptedException {
        webDriver.get("http://192.168.1.107:8080/");
//           //输入账号
        webDriver.findElement(By.cssSelector("#user")).sendKeys(user);
           //输入密码
        webDriver.findElement(By.xpath("//*[@id=\"pass\"]/div/div/input")).sendKeys(password);
           //点击登录
        webDriver.findElement(By.cssSelector("#sure")).click();
           //跳转到主页
        sleep(3000);
        String cur_url=webDriver.getCurrentUrl();
        Assertions.assertEquals(url,cur_url);
        ;
        Actions action = new Actions(webDriver);
        WebElement settings =webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/header/div/div[3]/span"));
        action.moveToElement(settings).perform();
        sleep(3000);
        webDriver.findElement(By.xpath("/html/body/ul/li[2]")).click();
        sleep(3000);
        webDriver.findElement(By.xpath("/html/body/div[2]/div/div[3]/button[2]")).click();
//        sleep(3000);
          String cur_url2=webDriver.getCurrentUrl();
//        sleep(3000);
//        Assertions.assertEquals("http://192.168.1.109:8080/",cur_url2);
    } 
4.添加测试
创建驱动,并打开页面
试页面是否正常打开
在登录成功状态下,点击添加按钮,测试是否可用
点击添加按钮,测试是否可用
弹出添加窗口
输入测试数据
测试确认按钮是否可以正常使用
检验数据是否添加成功
 void add() throws InterruptedException {
        int num=webDriver.findElements(By.cssSelector(".el-table__row")).size();
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/aside/ul/li[2]")).click();
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[1]/button[2]")).click();
        webDriver.findElement(By.xpath("//*[@id=\"name2\"]")).sendKeys("网易云音乐");
//        ((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"name2\").value=\"网易云音乐\";");
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[4]/div/div[3]/span/button[2]")).click();
        sleep(3000);
        int num1=webDriver.findElements(By.cssSelector(".el-table__row")).size();
        Assertions.assertEquals(num+1,num1);
    } 
5.编辑测试
单击需修改信息对应的operate按钮,测试编辑按钮是否可以使用
弹出编辑窗口
修改信息
对信息进行修改,单击确定
单击确认,关闭窗口
检验数据是否修改成功
    void update() throws InterruptedException {
        WebElement select = webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[2]/div[3]/table/tbody"));
        List<WebElement> allOptions = select.findElements(By.className("el-table__row"));
        String  x="//*[@id=\"app\"]/section/section/main/div/div[2]/div[3]/table/tbody/tr["+ 2 +"]/td[4]/div/button[1]";
        System.out.println(x);
        webDriver.findElement(By.xpath(x)).click();
        webDriver.findElement(By.xpath("//*[@id=\"name2\"]")).clear();
        webDriver.findElement(By.xpath("//*[@id=\"name2\"]")).sendKeys("K4");
        webDriver.findElement(By.name( "sure" )).click();
        String lasttext=webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[2]/div[3]/table/tbody/tr[2]/td[2]")).getText();
        Assertions.assertEquals("K4",lasttext);
    } 
6.删除测试
选择需要删除的信息对应的delete按钮,测试“删除”按钮是否可用
单击确认
检验信息是否删除成功
void del() throws InterruptedException {
        WebElement select = webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[2]/div[3]/table/tbody"));
        List<WebElement> allOptions = select.findElements(By.className("el-table__row"));
        JavascriptExecutor js;
        // 获取最后一个选项的索引
//        int lastOptionIndex = allOptions.size() - 1;
        int num1=select.findElements(By.className("el-table__row")).size();
        System.out.println("");
        String  x="//*[@id=\"app\"]/section/section/main/div/div[2]/div[3]/table/tbody/tr["+ num1+"]/td[4]/div/button[2]";
        System.out.println(x);
        webDriver.findElement(By.xpath(x)).click();
        sleep(3000);
        int num2=select.findElements(By.className("el-table__row")).size();
        String cx="/html/body/div[1]/section/section/main/div/div[2]/div[3]/table/tbody/tr["+num2+"]/td[2]/div";
        String lasttext= webDriver.findElement(By.xpath(cx)).getText();
        System.out.println(lasttext);
        Assertions.assertNotEquals("网易云音乐",lasttext);
    } 
7.出入库操作
已登录状态下,单击专辑管理模块, 进入专辑管理模块详情页
异常情况:只点击出库、入库按钮,提示请选择记录
单击需要出入库的专辑信息
再点击出入库按钮,测试按钮是否可用
弹出出入库窗口,输入出入库的数量
单击确认,关闭窗口
专辑数量增加(入库)/减少(出库)
 @Test
    public void comealbum() throws InterruptedException {
    
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/aside/ul/li[3]/span")).click();
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[2]/div[3]/table/tbody/tr[1]")).click();
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[1]/button[3]")).click();
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[5]/div/div[2]/form/div[2]/div/div/input")).sendKeys("20");
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[5]/div/div[3]/span/button[2]/span")).click();
    }
    @Test
    public void noalbum() throws InterruptedException {
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/aside/ul/li[3]/span")).click();
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[1]/button[3]")).click();
    }
    @Test
    public void leftalbum() throws InterruptedException {
    
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/aside/ul/li[3]/span")).click();
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[2]/div[3]/table/tbody/tr[1]")).click();
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[1]/button[3]")).click();
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[1]/button[4]")).sendKeys("20");
        webDriver.findElement(By.xpath("//*[@id=\"app\"]/section/section/main/div/div[5]/div/div[3]/span/button[2]/span")).click();
    } 
3.3 性能测试
使用loadrunner进行简单性能测试:针对登录、编辑、添加以及删除信息、出入库、注销等功能进行简单的性能测试。然后在实现的过程中,插入集合点以及事务等,并通过设置来实现用户的并发操作。



















