基于SSM前后端分离版本的论坛系统-自动化测试

目录

前言

一、测试环境

二、环境部署

三、测试用例

四、执行测试

4.1、公共类设计

创建浏览器驱动对象

测试套件

释放驱动类

4.2、功能测试

注册页面

登录页面

版块

 帖子

用户个人中心页

站内信

4.3、界面测试

注册页面

登录页面

版块

帖子

用户个人中心页

站内信


前言

        个人论坛系统是一种在线社交平台,为用户提供了丰富的功能,让他们能够轻松地创建帖子、分享信息、讨论话题以及互动交流。

        在开发阶段,实时进行了单元测试,所以本文章主要进行自动化测试(功能、界面),分为设计测试用例和进行测试两方面。

一、测试环境

操作系统:Window11专业版

项目运行环境:IntelliJ IDEA 2022.3.3、JDK1.8、MySQL5.7

浏览器:Chrome、Microsoft Edge

浏览器驱动:ChromeDriver、EdgeDriver

web自动化测试工具:selenium4

单元测试框架:Junit5

测试技术:主要进行功能与界面方面的自动化测试

二、环境部署

在pom.xml中部署

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter-test</artifactId><version>3.0.0</version><scope>test</scope><dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-java</artifactId><version>4.10.0</version></dependency><!--保存屏幕截图文件所要用到的包        --><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>1.4</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-suite</artifactId><version>1.8.2</version><scope>test</scope></dependency>

三、测试用例

四、执行测试

4.1、公共类设计

创建浏览器驱动对象

为了避免在每次测试时都重复创建浏览器驱动对象,浪费资源和时间,我们可以考虑创建一个公共类来统一管理浏览器驱动对象的创建。

public class AutotestUtils {public static ChromeDriver chromeDriver;public static EdgeDriver edgeDriver;//创建驱动对象public static ChromeDriver createChromeDriver(){//驱动创建好了/没有创建if (chromeDriver==null){ChromeOptions options=new ChromeOptions();options.addArguments("--remote-allow-origins=*");chromeDriver=new ChromeDriver(options);//隐式等待Duration duration=Duration.ofSeconds(10);long millis= duration.toMillis();chromeDriver.manage().timeouts().implicitlyWait(millis, TimeUnit.MILLISECONDS);}return chromeDriver;}public static EdgeDriver createEdgeDriver(){//驱动创建好了/没有创建if (edgeDriver==null){EdgeOptions options=new EdgeOptions();options.addArguments("--remote-allow-origins=*");edgeDriver=new EdgeDriver(options);//隐式等待Duration duration=Duration.ofSeconds(10);long millis= duration.toMillis();edgeDriver.manage().timeouts().implicitlyWait(millis,TimeUnit.MILLISECONDS);}return edgeDriver;}
}

测试套件

使用suite测试套件来进行测试,指定类来运行用例

@Suite
@SelectClasses({RegisterPrepareTest.class, LoginPrepareTest.class, BoardPrepareTest.class, ArticlePrepareTest.class,UserPrepareTest.class,MailPrepareTest.class,driverQuitTest.class})
public class runSuite {
}

释放驱动类

单独写一个释放驱动类

public class driverQuitTest extends AutotestUtils {public static ChromeDriver chromeDriver;public static EdgeDriver edgeDriver;@Teststatic void driverQuit(){if (chromeDriver!=null){chromeDriver.quit();} else if (edgeDriver!=null) {edgeDriver.quit();}else {chromeDriver.quit();edgeDriver.quit();}}
}

4.2、功能测试

注册页面

首先定义浏览器对象和url

    /*** 1、浏览器对象* 2、访问登录页面的url*/public static ChromeDriver chromeDriver=createChromeDriver();@BeforeAllstatic void baseControl(){chromeDriver.get("http://49.232.185.203:58080/sign-up.html");}

测试空的用户名能否正常注册

    /*** 测试空的用户名* @param username* @param nickname* @param password* @param passwordRepeat* @throws InterruptedException*/@Order(1)@ParameterizedTest@CsvSource({",baekhyun,1992,1992"})public void testRegisterNullUsername(String username,String nickname,String password,String passwordRepeat) throws InterruptedException {chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#nickname")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#passwordRepeat")).clear();if (nickname!=null){chromeDriver.findElement(By.cssSelector("#nickname")).sendKeys(nickname);}if (password!=null){chromeDriver.findElement(By.cssSelector("#password")).sendKeys(password);}if (passwordRepeat!=null){chromeDriver.findElement(By.cssSelector("#passwordRepeat")).sendKeys(passwordRepeat);}chromeDriver.findElement(By.cssSelector("#policy")).click();chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(1000);String except="用户名不能为空";String actual=chromeDriver.findElement(By.xpath("//*[@id=\"signUpForm\"]/div/div[1]/div")).getText();Assertions.assertEquals(except,actual);Thread.sleep(1000);//复原勾选框chromeDriver.findElement(By.cssSelector("#policy")).click();}

测试空的昵称能否正常注册

    /*** 测试空的昵称* @param username* @param nickname* @param password* @param passwordRepeat*/@Order(2)@ParameterizedTest@CsvSource({"baekhyun,,1992,1992"})public void testRegisterNullNickname(String username,String nickname,String password,String passwordRepeat) throws InterruptedException {chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#nickname")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#passwordRepeat")).clear();if (username!=null){chromeDriver.findElement(By.cssSelector("#username")).sendKeys(username);}if (password!=null){chromeDriver.findElement(By.cssSelector("#password")).sendKeys(password);}if (passwordRepeat!=null){chromeDriver.findElement(By.cssSelector("#passwordRepeat")).sendKeys(passwordRepeat);}chromeDriver.findElement(By.cssSelector("#policy")).click();chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(1000);String except="昵称不能为空";String actual=chromeDriver.findElement(By.xpath("//*[@id=\"signUpForm\"]/div/div[2]/div")).getText();Assertions.assertEquals(except,actual);Thread.sleep(1000);//复原勾选框chromeDriver.findElement(By.cssSelector("#policy")).click();}

测试空的密码能否正常注册

    /*** 测试空的密码* @param username* @param nickname* @param password* @param passwordRepeat* @throws InterruptedException*/@Order(3)@ParameterizedTest@CsvSource({"baekhyun,baekhyun,,1992"})public void testRegisterNullPassword(String username,String nickname,String password,String passwordRepeat) throws InterruptedException {chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#nickname")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#passwordRepeat")).clear();if (username!=null){chromeDriver.findElement(By.cssSelector("#username")).sendKeys(username);}if (nickname!=null){chromeDriver.findElement(By.cssSelector("#nickname")).sendKeys(nickname);}if (passwordRepeat!=null){chromeDriver.findElement(By.cssSelector("#passwordRepeat")).sendKeys(passwordRepeat);}chromeDriver.findElement(By.cssSelector("#policy")).click();chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(1000);String except="密码不能为空";String actual=chromeDriver.findElement(By.xpath("//*[@id=\"signUpForm\"]/div/div[3]/div/div")).getText();Assertions.assertEquals(except,actual);Thread.sleep(1000);//复原勾选框chromeDriver.findElement(By.cssSelector("#policy")).click();}

测试空的确认密码能否正常注册

    /*** 测试空的确认密码* @param username* @param nickname* @param password* @param passwordRepeat* @throws InterruptedException*/@Order(4)@ParameterizedTest@CsvSource({"baekhyun,baekhyun,1992,"})public void testRegisterNullPasswordRepeat(String username,String nickname,String password,String passwordRepeat) throws InterruptedException {chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#nickname")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#passwordRepeat")).clear();if (username!=null){chromeDriver.findElement(By.cssSelector("#username")).sendKeys(username);}if (nickname!=null){chromeDriver.findElement(By.cssSelector("#nickname")).sendKeys(nickname);}if (password!=null){chromeDriver.findElement(By.cssSelector("#password")).sendKeys(password);}chromeDriver.findElement(By.cssSelector("#policy")).click();chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(1000);String except="请检查确认密码";String actual=chromeDriver.findElement(By.xpath("//*[@id=\"signUpForm\"]/div/div[4]/div/div")).getText();Assertions.assertEquals(except,actual);Thread.sleep(1000);//复原勾选框chromeDriver.findElement(By.cssSelector("#policy")).click();}

测试密码和确认密码不一致时能否正常注册

    /*** 测试密码和确认密码不一致* @param username* @param nickname* @param password* @param passwordRepeat* @throws InterruptedException*/@Order(5)@ParameterizedTest@CsvSource({"baekhyun,baekhyun,1992,1993"})public void testRegisterNullSame(String username,String nickname,String password,String passwordRepeat) throws InterruptedException {chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#nickname")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#passwordRepeat")).clear();if (username!=null){chromeDriver.findElement(By.cssSelector("#username")).sendKeys(username);}if (nickname!=null){chromeDriver.findElement(By.cssSelector("#nickname")).sendKeys(nickname);}if (password!=null){chromeDriver.findElement(By.cssSelector("#password")).sendKeys(password);}if (passwordRepeat!=null){chromeDriver.findElement(By.cssSelector("#passwordRepeat")).sendKeys(passwordRepeat);}chromeDriver.findElement(By.cssSelector("#policy")).click();chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(1000);String except="请检查确认密码";String actual=chromeDriver.findElement(By.xpath("//*[@id=\"signUpForm\"]/div/div[4]/div/div")).getText();Assertions.assertEquals(except,actual);Thread.sleep(1000);//复原勾选框chromeDriver.findElement(By.cssSelector("#policy")).click();}

测试用户名已注册时能否正常注册

    /*** 测试用户名已存在* @param username* @param nickname* @param password* @param passwordRepeat* @throws InterruptedException*/@Order(6)@ParameterizedTest@CsvSource({"baekhyun,baekhyun,1992,1992"})public void testRegisterNullExistUsername(String username,String nickname,String password,String passwordRepeat) throws InterruptedException {chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#nickname")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#passwordRepeat")).clear();if (username!=null){chromeDriver.findElement(By.cssSelector("#username")).sendKeys(username);}if (nickname!=null){chromeDriver.findElement(By.cssSelector("#nickname")).sendKeys(nickname);}if (password!=null){chromeDriver.findElement(By.cssSelector("#password")).sendKeys(password);}if (passwordRepeat!=null){chromeDriver.findElement(By.cssSelector("#passwordRepeat")).sendKeys(passwordRepeat);}chromeDriver.findElement(By.cssSelector("#policy")).click();chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(1000);String exp_url="http://49.232.185.203:58080/sign-up.html";String cur_url=chromeDriver.getCurrentUrl();Assertions.assertEquals(exp_url,cur_url);Thread.sleep(1000);//复原勾选框chromeDriver.findElement(By.cssSelector("#policy")).click();Thread.sleep(1000);}

测试没有点击同意协议能否正常注册

    /*** 测试没有点击同意协议* @param username* @param nickname* @param password* @param passwordRepeat* @throws InterruptedException*/@Order(7)@ParameterizedTest@CsvSource({"do,do,1993,1993"})public void testRegisterNullPolicy(String username,String nickname,String password,String passwordRepeat) throws InterruptedException {chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#nickname")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#passwordRepeat")).clear();if (username!=null){chromeDriver.findElement(By.cssSelector("#username")).sendKeys(username);}if (nickname!=null){chromeDriver.findElement(By.cssSelector("#nickname")).sendKeys(nickname);}if (password!=null){chromeDriver.findElement(By.cssSelector("#password")).sendKeys(password);}if (passwordRepeat!=null){chromeDriver.findElement(By.cssSelector("#passwordRepeat")).sendKeys(passwordRepeat);}chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(1000);String exp_url="http://49.232.185.203:58080/sign-up.html";String cur_url=chromeDriver.getCurrentUrl();Assertions.assertEquals(exp_url,cur_url);Thread.sleep(1000);}

测试输入正确的用户名、昵称、密码、确认密码能否正常注册

    /*** 正确的用户名、昵称、密码、确认密码* @param username* @param nickname* @param password* @param passwordRepeat* @throws InterruptedException*/@Order(8)@ParameterizedTest@CsvSource({"sehun,sehun,1994,1994"})public void testRegisterSuccess(String username,String nickname,String password,String passwordRepeat) throws InterruptedException {chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#nickname")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#passwordRepeat")).clear();if (username!=null){chromeDriver.findElement(By.cssSelector("#username")).sendKeys(username);}if (nickname!=null){chromeDriver.findElement(By.cssSelector("#nickname")).sendKeys(nickname);}if (password!=null){chromeDriver.findElement(By.cssSelector("#password")).sendKeys(password);}if (passwordRepeat!=null){chromeDriver.findElement(By.cssSelector("#passwordRepeat")).sendKeys(passwordRepeat);}chromeDriver.findElement(By.cssSelector("#policy")).click();chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(3000);String exp_url="http://49.232.185.203:58080/sign-in.html";String cur_url=chromeDriver.getCurrentUrl();Assertions.assertEquals(exp_url,cur_url);}

测试结果:

登录页面

首先定义浏览器对象和url

    /*** 1、浏览器对象* 2、访问登录页面的url*/public static ChromeDriver chromeDriver=createChromeDriver();@BeforeAllstatic void baseControl(){chromeDriver.get("http://49.232.185.203:58080/sign-in.html");}

测试输入错误的用户名和密码

    /*** 测试错误的用户名或密码* @param username* @param password* @throws InterruptedException*/@Order(1)@ParameterizedTest@CsvSource({"baekhyun,1999","dd,1993"})void testLoginErrorUser(String username,String password) throws InterruptedException {chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#username")).sendKeys(username);chromeDriver.findElement(By.cssSelector("#password")).sendKeys(password);chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(1000);String exp_url="http://49.232.185.203:58080/sign-in.html";String cur_url=chromeDriver.getCurrentUrl();Assertions.assertEquals(exp_url,cur_url);Thread.sleep(1000);}

测试只输入用户名

    /*** 测试空的用户名* @param username* @param password* @throws InterruptedException*/@Order(2)@ParameterizedTest@CsvSource({",1992",",1993"})void testLoginNullUsername(String username,String password) throws InterruptedException {chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();if (password!=null){chromeDriver.findElement(By.cssSelector("#password")).sendKeys(password);}chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(1000);String except="用户名不能为空";String actual=chromeDriver.findElement(By.xpath("//*[@id=\"signInForm\"]/div[1]/div")).getText();Assertions.assertEquals(except,actual);Thread.sleep(1000);}

测试只输入密码

    /*** 测试空的密码* @param username* @param password* @throws InterruptedException*/@Order(3)@ParameterizedTest@CsvSource({"baekhyun,","do,"})void testLoginNullPassword(String username,String password) throws InterruptedException {chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();if (username!=null){chromeDriver.findElement(By.cssSelector("#username")).sendKeys(username);}chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(1000);String except="密码不能为空";String actual=chromeDriver.findElement(By.xpath("//*[@id=\"signInForm\"]/div[2]/div/div")).getText();Assertions.assertEquals(except,actual);Thread.sleep(1000);}

测试输入正确的用户名和密码

    /*** 测试正确的用户名和密码* @param username* @param password* @throws InterruptedException*/@Order(4)@ParameterizedTest@CsvSource({"baekhyun,1992","do,1993"})void testLoginSuccess(String username,String password) throws InterruptedException {chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#username")).sendKeys(username);chromeDriver.findElement(By.cssSelector("#password")).sendKeys(password);chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(1000);String exp_url="http://49.232.185.203:58080/index.html";String cur_url=chromeDriver.getCurrentUrl();Assertions.assertEquals(exp_url,cur_url);chromeDriver.navigate().back();Thread.sleep(1000);}

测试结果:

版块

首先定义浏览器对象和url

    /*** 1、浏览器对象* 2、访问登录页面的url*/public static ChromeDriver chromeDriver=createChromeDriver();@BeforeAllstatic void baseControl(){chromeDriver.get("http://49.232.185.203:58080/sign-in.html");chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#username")).sendKeys("baekhyun");chromeDriver.findElement(By.cssSelector("#password")).sendKeys("1992");chromeDriver.findElement(By.cssSelector("#submit")).click();}

测试是否显示所有帖子信息

    /*** 测试是否显示板块下所有帖子的信息*/@Order(1)@Testvoid testDisplayALLArticle() throws InterruptedException {Thread.sleep(1000);String exp1=chromeDriver.findElement(By.cssSelector("#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong")).getText();Assertions.assertEquals("招聘开发岗位",exp1);String exp2=chromeDriver.findElement(By.cssSelector("#artical-items-body > div:nth-child(2) > div > div.col > div.text-truncate > a > strong")).getText();Assertions.assertEquals("测试测试333",exp2);String exp3=chromeDriver.findElement(By.cssSelector("#artical-items-body > div:nth-child(3) > div > div.col > div.text-truncate > a > strong")).getText();Assertions.assertEquals("测试测试222",exp3);String exp4=chromeDriver.findElement(By.cssSelector("#artical-items-body > div:nth-child(4) > div > div.col > div.text-truncate > a > strong")).getText();Assertions.assertEquals("测试测试111",exp4);}

测试右上角用户信息

    /*** 测试右上角用户信息*/@Order(2)@Testvoid testUserInfo() throws InterruptedException {Thread.sleep(1000);WebElement userinfo=chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown"));Assertions.assertNotNull(userinfo);}

测试站内信按钮

    /*** 测试站内信按钮*/@Order(3)@Testvoid testDisplayMail() throws InterruptedException {Thread.sleep(1000);WebElement mail=chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div"));Assertions.assertNotNull(mail);}

测试点击用户头像是否出现下拉框信息

    /*** 测试点击用户头像是否出现下拉框*/@Order(4)@Testvoid testDisplayDownList() throws InterruptedException {Thread.sleep(1000);//首先得点击下拉框chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown")).click();String exp1=chromeDriver.findElement(By.xpath("//*[@id=\"index_user_profile\"]")).getText();Assertions.assertEquals("我的帖子",exp1);String exp2=chromeDriver.findElement(By.xpath("//*[@id=\"index_user_settings\"]")).getText();Assertions.assertEquals("个人中心",exp2);String quit=chromeDriver.findElement(By.xpath("//*[@id=\"index_user_logout\"]")).getText();Assertions.assertEquals("退出",quit);chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown")).click();}

测试能否跳转到详情页

    /*** 测试能否跳转到详情页*/@Order(5)@Testvoid testArticleDetail() throws InterruptedException {chromeDriver.findElement(By.cssSelector("#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong")).click();String except="招聘开发岗位测试";String actual=chromeDriver.findElement(By.xpath("//*[@id=\"details_article_content\"]/p")).getText();Thread.sleep(1000);Assertions.assertEquals(except,actual);chromeDriver.findElement(By.cssSelector("#nav_board_index > a")).click();}

测试能否正确跳转到帖子编辑页

    /*** 测试发布帖子能否正确跳到帖子编辑页*/@Order(6)@Testvoid Publish1() throws InterruptedException {Thread.sleep(2000);chromeDriver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post")).click();Thread.sleep(3000);String text=chromeDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[1]")).getText();Assertions.assertEquals("发新贴",text);chromeDriver.findElement(By.cssSelector("#nav_board_index > a")).click();}

测试点击版块能否跳转到版块下的所有帖子

    /*** 测试点击版块能否跳到板块下所有的帖子*/@Order(7)@Testvoid testBoardInfo() throws InterruptedException {Thread.sleep(1000);chromeDriver.findElement(By.xpath("//*[@id=\"topBoardList\"]/li[2]")).click();Thread.sleep(2000);String text=chromeDriver.findElement(By.xpath("//*[@id=\"article_list_board_title\"]")).getText();Assertions.assertEquals("Java",text);String exp1=chromeDriver.findElement(By.cssSelector("#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong")).getText();Assertions.assertEquals("测试测试222",exp1);String exp2=chromeDriver.findElement(By.cssSelector("#artical-items-body > div:nth-child(2) > div > div.col > div.text-truncate > a > strong")).getText();Assertions.assertEquals("测试测试111",exp2);}

测试退出按钮能否跳转到登录页面

    /*** 测试退出按钮*/@Order(8)@Testvoid testQuit() throws InterruptedException {//首先得点击下拉框chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown")).click();chromeDriver.findElement(By.xpath("//*[@id=\"index_user_logout\"]")).click();Thread.sleep(1000);String exp_url="http://49.232.185.203:58080/sign-in.html";String actual_url=chromeDriver.getCurrentUrl();Assertions.assertEquals(exp_url,actual_url);}

测试结果:

 帖子

首先定义浏览器对象和url

    /*** 1、浏览器对象* 2、访问登录页面的url*/public static ChromeDriver chromeDriver=createChromeDriver();@BeforeAllstatic void baseControl(){chromeDriver.get("http://49.232.185.203:58080/sign-in.html");chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#username")).sendKeys("baekhyun");chromeDriver.findElement(By.cssSelector("#password")).sendKeys("1992");chromeDriver.findElement(By.cssSelector("#submit")).click();}

测试正确发布帖子

    /*** 测试发布新帖* @throws InterruptedException*/@Order(1)@Testvoid Publish1() throws InterruptedException {chromeDriver.findElement(By.xpath("//*[@id=\"nav_board_index\"]/a/span[2]")).click();chromeDriver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post")).click();chromeDriver.findElement(By.cssSelector("#article_post_title")).sendKeys("自动化测试标题");chromeDriver.manage().timeouts().implicitlyWait(3, TimeUnit.MINUTES);chromeDriver.findElement(By.cssSelector("#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre")).sendKeys("自动化测试内容");chromeDriver.manage().timeouts().implicitlyWait(3, TimeUnit.MINUTES);chromeDriver.findElement(By.cssSelector("#article_post_submit")).click();Thread.sleep(1000);String text = chromeDriver.findElement(By.cssSelector("#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong")).getText();Assertions.assertEquals("自动化测试标题",text);}

测试能否正确跳转到帖子详情页

    /*** 测试能否跳转到详情页*/@Order(1)@Testvoid testArticleDetail() throws InterruptedException {chromeDriver.findElement(By.cssSelector("#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong")).click();String except="招聘开发岗位测试";String actual=chromeDriver.findElement(By.xpath("//*[@id=\"details_article_content\"]/p")).getText();Thread.sleep(1000);Assertions.assertEquals(except,actual);}

测试能否显示帖子的所有信息和用户信息

    /*** 测试是否显示帖子的所有信息和用户信息*/@Order(2)@Testvoid testDisplayArticle_userInfo() throws InterruptedException {//帖子作者String article_username="do";String username=chromeDriver.findElement(By.xpath("//*[@id=\"article_details_author_name\"]")).getText();//帖子标题String article_title="招聘开发岗位";String title=chromeDriver.findElement(By.xpath("//*[@id=\"details_article_title\"]")).getText();//帖子内容String article_content="招聘开发岗位测试";String content=chromeDriver.findElement(By.xpath("//*[@id=\"details_article_content\"]/p")).getText();Thread.sleep(1000);Assertions.assertEquals(article_username,username);Assertions.assertEquals(article_title,title);Assertions.assertEquals(article_content,content);}

测试能否显示帖子的创建时间、点赞数、浏览量、回复数

    /*** 测试是否显示帖子的创建时间、点赞数、浏览量、回复数*/@Order(3)@Testvoid testDisplayarticleInfo(){//帖子创建时间String ex_createTime="2024-05-28 12:08:57";String createTime=chromeDriver.findElement(By.xpath("//*[@id=\"details_article_createTime\"]")).getText();Assertions.assertEquals(ex_createTime,createTime);//点赞数WebElement like_count_nav=chromeDriver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(3) > svg"));Assertions.assertNotNull(like_count_nav);//浏览量WebElement browse_nav=chromeDriver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(2) > svg"));Assertions.assertNotNull(browse_nav);//回复数WebElement reply_nav=chromeDriver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(4) > svg"));Assertions.assertNotNull(reply_nav);}

测试用户不是作者,是否会显示点赞选项

    /*** 测试如果不是作者,是否出现点赞按钮*/@Order(4)@Testvoid testuserNotArticleUser(){//不是作者的情况下//点赞按钮WebElement like_nav=chromeDriver.findElement(By.cssSelector("#details_btn_like_count > svg"));Assertions.assertNotNull(like_nav);}

测试用户是作者,是否显示点赞、编辑、删除选项

    /*** 测试如果是作者,是否显示点赞、编辑、删除按钮*/@Order(5)@Testvoid testuserIsArticleUser(){//是作者的情况下,需先退出当前帖子详情chromeDriver.findElement(By.cssSelector("#nav_board_index > a")).click();//进入作者为别人的帖子详情页chromeDriver.findElement(By.cssSelector("#artical-items-body > div:nth-child(2) > div > div.col > div.text-truncate > a > strong")).click();//点赞按钮WebElement like_nav=chromeDriver.findElement(By.cssSelector("#details_btn_like_count > svg"));Assertions.assertNotNull(like_nav);//编辑按钮WebElement edit_nav=chromeDriver.findElement(By.cssSelector("#details_artile_edit > svg"));Assertions.assertNotNull(edit_nav);//删除按钮WebElement del_nav=chromeDriver.findElement(By.cssSelector("#bit-forum-content > div.page-body > div > div > div:nth-child(1) > div.col-9.card.card-lg > div.card-footer.bg-transparent.mt-auto.justify-content-end > div > div:nth-child(3) > div > a"));Assertions.assertNotNull(del_nav);}

测试结果:

用户个人中心页

首先定义浏览器对象和url

    /*** 1、浏览器对象* 2、访问登录页面的url*/public static ChromeDriver chromeDriver=createChromeDriver();@BeforeAllstatic void baseControl(){chromeDriver.get("http://49.232.185.203:58080/sign-in.html");chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#username")).sendKeys("do");chromeDriver.findElement(By.cssSelector("#password")).sendKeys("1993");chromeDriver.findElement(By.cssSelector("#submit")).click();}

测试能否正确显示当前用户下的所有帖子

    /*** 测试能否正确显示当前用户下的所有帖子*/@Order(1)@Testvoid testDisplayUserAllArticle() throws InterruptedException {Thread.sleep(1000);//首先得点击下拉框chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown")).click();chromeDriver.findElement(By.xpath("//*[@id=\"index_user_profile\"]")).click();String article_title=chromeDriver.findElement(By.xpath("//*[@id=\"profile_article_body\"]/li/div[2]/div/div/div/div/div[1]/a/strong")).getText();Assertions.assertEquals("招聘开发岗位",article_title);}

测试能否正确显示发帖数、邮箱、注册日期、个人介绍

    /*** 测试能否正确显示发帖数、邮箱、注册日期、个人介绍*/@Order(2)@Testvoid testUserInfo(){WebElement articlecount_nav=chromeDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[1]/div/div/div[2]/div/div[1]"));Assertions.assertNotNull(articlecount_nav);WebElement email_nav=chromeDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[1]/div/div/div[2]/div/div[2]"));Assertions.assertNotNull(email_nav);WebElement createtime_nav=chromeDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[1]/div/div/div[2]/div/div[3]"));Assertions.assertNotNull(createtime_nav);WebElement introduce_nav=chromeDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[2]/div/div/div[2]/div/div"));Assertions.assertNotNull(introduce_nav);}

测试能否正确显示他人的帖子信息和用户信息

    /*** 测试能否正确显示他人的帖子信息或用户信息*/@Order(3)@Testvoid testOtherUserInfo(){//点击首页chromeDriver.findElement(By.cssSelector("#nav_board_index > a")).click();//点击别人文章chromeDriver.findElement(By.xpath("//*[@id=\"artical-items-body\"]/div[2]/div/div[2]/div[1]/a/strong")).click();//点击别人的名称进入详情页chromeDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[2]/div/div/div[1]/div[1]/div/h3")).click();WebElement articlecount_nav=chromeDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[1]/div/div/div[2]/div/div[1]"));Assertions.assertNotNull(articlecount_nav);WebElement email_nav=chromeDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[1]/div/div/div[2]/div/div[2]"));Assertions.assertNotNull(email_nav);WebElement createtime_nav=chromeDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[1]/div/div/div[2]/div/div[3]"));Assertions.assertNotNull(createtime_nav);WebElement introduce_nav=chromeDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[2]/div/div/div[2]/div/div"));Assertions.assertNotNull(introduce_nav);}

测试修改昵称、电子邮箱、电话号码

    /*** 测试修改昵称、邮箱地址、电话号码*/@Order(4)@Testvoid testModifyUserInfo() throws InterruptedException {Thread.sleep(1000);//首先得点击下拉框chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown")).click();//点击用户中心chromeDriver.findElement(By.xpath("//*[@id=\"index_user_settings\"]")).click();Thread.sleep(1000);//修改昵称chromeDriver.findElement(By.xpath("//*[@id=\"setting_input_nickname\"]")).clear();chromeDriver.findElement(By.xpath("//*[@id=\"setting_input_nickname\"]")).sendKeys("dodo");chromeDriver.findElement(By.xpath("//*[@id=\"setting_submit_nickname\"]")).click();Thread.sleep(1000);//修改邮箱地址chromeDriver.findElement(By.xpath("//*[@id=\"setting_input_email\"]")).clear();chromeDriver.findElement(By.xpath("//*[@id=\"setting_input_email\"]")).sendKeys("19933@qq.com");chromeDriver.findElement(By.xpath("//*[@id=\"setting_submit_email\"]")).click();Thread.sleep(1000);//修改电话号码chromeDriver.findElement(By.xpath("//*[@id=\"setting_input_phoneNum\"]")).clear();chromeDriver.findElement(By.xpath("//*[@id=\"setting_input_phoneNum\"]")).sendKeys("12727178333");Thread.sleep(1000);chromeDriver.findElement(By.xpath("//*[@id=\"setting_submit_phoneNum\"]")).click();Thread.sleep(2000);//退出chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown")).click();chromeDriver.findElement(By.xpath("//*[@id=\"index_user_logout\"]")).click();Thread.sleep(1000);//登录chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#username")).sendKeys("do");chromeDriver.findElement(By.cssSelector("#password")).sendKeys("1992");chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(3000);chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown")).click();chromeDriver.findElement(By.xpath("//*[@id=\"index_user_settings\"]")).click();Thread.sleep(1000);String nickname=chromeDriver.findElement(By.xpath("//*[@id=\"settings_nickname\"]")).getText();Assertions.assertEquals("dodo",nickname);}

测试修改密码

    /*** 测试修改密码*/@Order(5)@Testvoid testModifyPassword() throws InterruptedException {Thread.sleep(1000);chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown")).click();//点击用户中心chromeDriver.findElement(By.xpath("//*[@id=\"index_user_settings\"]")).click();Thread.sleep(1000);//填写旧密码chromeDriver.findElement(By.xpath("//*[@id=\"settings_input_oldPassword\"]")).sendKeys("1992");//新密码chromeDriver.findElement(By.xpath("//*[@id=\"settings_input_newPassword\"]")).sendKeys("1993");//确认密码chromeDriver.findElement(By.xpath("//*[@id=\"settings_input_passwordRepeat\"]")).sendKeys("1993");Thread.sleep(2000);chromeDriver.findElement(By.xpath("//*[@id=\"settings_submit_password\"]")).click();Thread.sleep(1000);String exp_url="http://49.232.185.203:58080/sign-in.html";String actual_url=chromeDriver.getCurrentUrl();Assertions.assertEquals(exp_url,actual_url);Thread.sleep(1000);chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#username")).sendKeys("do");chromeDriver.findElement(By.cssSelector("#password")).sendKeys("1993");chromeDriver.findElement(By.cssSelector("#submit")).click();Thread.sleep(3000);String exp_url2="http://49.232.185.203:58080/index.html";String actual_url2=chromeDriver.getCurrentUrl();Assertions.assertEquals(exp_url2,actual_url2);}

测试结果:

站内信

首先定义浏览器对象和url

    /*** 1、浏览器对象* 2、访问登录页面的url*/public static ChromeDriver chromeDriver=createChromeDriver();public static EdgeDriver edgeDriver=createEdgeDriver();@BeforeAllstatic void baseControl(){chromeDriver.get("http://49.232.185.203:58080/sign-in.html");chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#username")).sendKeys("do");chromeDriver.findElement(By.cssSelector("#password")).sendKeys("1993");chromeDriver.findElement(By.cssSelector("#submit")).click();edgeDriver.get("http://49.232.185.203:58080/sign-in.html");edgeDriver.findElement(By.cssSelector("#username")).clear();edgeDriver.findElement(By.cssSelector("#password")).clear();edgeDriver.findElement(By.cssSelector("#username")).sendKeys("baekhyun");edgeDriver.findElement(By.cssSelector("#password")).sendKeys("1992");edgeDriver.findElement(By.cssSelector("#submit")).click();}

测试能否成功发送站内信

    /*** 测试能否成功发送站内信*/@Order(1)@Test()@Transactionalvoid testSendMailSuccess() throws InterruptedException {edgeDriver.findElement(By.xpath("//*[@id=\"artical-items-body\"]/div[1]/div/div[2]/div[1]/a/strong")).click();edgeDriver.findElement(By.xpath("//*[@id=\"btn_details_send_message\"]")).click();edgeDriver.findElement(By.xpath("//*[@id=\"index_message_receive_content\"]")).sendKeys("我是baekhyun");edgeDriver.findElement(By.xpath("//*[@id=\"btn_index_send_message\"]")).click();Thread.sleep(1000);String exp_url="http://49.232.185.203:58080/index.html";String actual_url=chromeDriver.getCurrentUrl();Assertions.assertEquals(exp_url,actual_url);Thread.sleep(1000);}

测试能否正确显示站内信

    /*** 测试能否正确显示站内信*/@Order(2)@Testvoid testDisplayMail() throws InterruptedException {chromeDriver.navigate().refresh();Thread.sleep(1000);chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div")).click();String receive=chromeDriver.findElement(By.xpath("//*[@id=\"index_div_message_list\"]/div[1]/div/div[2]/div")).getText();Assertions.assertEquals("我是baekhyun",receive);}

测试站内信未读时,前方是否有[未读]标志

    /*** 测试站内信未读时,前方是否有[未读]标志*/@Order(3)@Testvoid testUnread() throws InterruptedException {chromeDriver.navigate().refresh();Thread.sleep(1000);//点击站内信chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div")).click();String expect=chromeDriver.findElement(By.xpath("//*[@id=\"index_div_message_list\"]/div[1]/div/div[2]/a/span[1]")).getText();Assertions.assertEquals("[未读]",expect);}

测试站内信已读时,前方是否有[已读]标志

    /*** 测试站内信已读时,前方是否有[已读]标志*/@Order(4)@Testvoid testread() throws InterruptedException {chromeDriver.navigate().refresh();Thread.sleep(1000);//点击站内信chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div")).click();//点击要读取的站内信chromeDriver.findElement(By.xpath("//*[@id=\"index_div_message_list\"]/div[1]/div/div[2]/a")).click();//点击退出chromeDriver.findElement(By.xpath("//*[@id=\"index_message_reply_modal\"]/div/div/div[1]/button")).click();Thread.sleep(1000);chromeDriver.navigate().refresh();//点击站内信chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div")).click();String expect=chromeDriver.findElement(By.xpath("//*[@id=\"index_div_message_list\"]/div[1]/div/div[2]/a/span[1]")).getText();Assertions.assertEquals("[已读]",expect);}

测试站内信已回复时,前方是否有[已回复]标志

    /*** 测试站内信已回复时,前方是否有[已回复]标志*/@Order(5)@Testvoid testReplied() throws InterruptedException {Thread.sleep(1000);chromeDriver.navigate().refresh();//点击站内信chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div")).click();//点击要回复的站内信chromeDriver.findElement(By.xpath("//*[@id=\"index_div_message_list\"]/div[1]/div/div[2]/a")).click();//点击回复chromeDriver.findElement(By.xpath("//*[@id=\"btn_index_message_reply\"]")).click();Thread.sleep(1000);//输入要回复的内容chromeDriver.findElement(By.xpath("//*[@id=\"index_message_reply_receive_content\"]")).sendKeys("我是do");//点击发送chromeDriver.findElement(By.xpath("//*[@id=\"btn_index_send_message_reply\"]")).click();Thread.sleep(2000);chromeDriver.navigate().refresh();//点击站内信chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div")).click();String expect=chromeDriver.findElement(By.xpath("//*[@id=\"index_div_message_list\"]/div[1]/div/div[2]/a/span[1]")).getText();Assertions.assertEquals("[已回复]",expect);}

测试回复站内信能否成功

    /*** 测试回复站内信能否成功*/@Order(6)@Testvoid replySuccess() throws InterruptedException {Thread.sleep(1000);edgeDriver.navigate().refresh();//点击站内信edgeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div")).click();//点击要回复的站内信String text=edgeDriver.findElement(By.xpath("//*[@id=\"index_div_message_list\"]/div[1]/div/div[2]/div")).getText();Assertions.assertEquals("我是do",text);}

测试结果:

4.3、界面测试

注册页面

首先定义浏览器对象和url

    /*** 1、浏览器对象* 2、访问登录页面的url*/public static ChromeDriver chromeDriver=createChromeDriver();@BeforeAllstatic void baseControl(){chromeDriver.get("http://49.232.185.203:58080/sign-up.html");}

测试用户注册标题是否存在

    /*** 测试用户注册标题是否存在*/@Order(1)@Testvoid testRegisterTitle(){String expect_title="用户注册";String actual=chromeDriver.findElement(By.xpath("//*[@id=\"signUpForm\"]/div/h2")).getText();Assertions.assertEquals(expect_title,actual);}

测试用户名输入框是否存在

    /*** 测试用户名输入框是否存在*/@Order(2)@Testvoid testUsernameInput(){WebElement userInput=chromeDriver.findElement(By.xpath("//*[@id=\"username\"]"));Assertions.assertNotNull(userInput);}

测试昵称输入框是否存在

    /*** 测试昵称输入框是否存在*/@Order(3)@Testvoid testNicknameInput(){WebElement nicknameInput=chromeDriver.findElement(By.xpath("//*[@id=\"nickname\"]"));Assertions.assertNotNull(nicknameInput);}

测试密码输入框是否存在

    /*** 测试密码输入框是否存在*/@Order(4)@Testvoid testPasswordInput(){WebElement passwordInput=chromeDriver.findElement(By.xpath("//*[@id=\"password\"]"));Assertions.assertNotNull(passwordInput);}

测试确认密码输入框是否存在

    /*** 测试密码确认输入框是否存在*/@Order(5)@Testvoid testPasswordRepeat(){WebElement passwordRepeatInput=chromeDriver.findElement(By.xpath("//*[@id=\"passwordRepeat\"]"));Assertions.assertNotNull(passwordRepeatInput);}

测试注册按钮是否存在

    /*** 测试注册按钮是否存在*/@Order(6)@Testvoid testRegisterButton(){WebElement registerButton=chromeDriver.findElement(By.xpath("//*[@id=\"submit\"]"));Assertions.assertNotNull(registerButton);}

测试登录跳转按钮是否存在

    /*** 测试登录跳转按钮是否存在*/@Order(7)@Testvoid testLoginJumpButton(){WebElement loginJumpButton=chromeDriver.findElement(By.xpath("/html/body/div/div/div[2]/a"));Assertions.assertNotNull(loginJumpButton);}

测试结果:

登录页面

首先定义浏览器对象和url

    /*** 1、浏览器对象* 2、访问登录页面的url*/public static ChromeDriver chromeDriver=createChromeDriver();@BeforeAllstatic void baseControl(){chromeDriver.get("http://49.232.185.203:58080/sign-in.html");}

测试用户登录标题是否存在

    /*** 测试用户登录标题是否存在*/@Order(1)@Testvoid testLoginTitle(){String login_title="用户登录";String except=chromeDriver.findElement(By.xpath("/html/body/div/div/div/div[1]/div/div[2]/div/h2")).getText();Assertions.assertEquals(login_title,except);}

测试用户名输入框是否存在

    /*** 测试用户名输入框是否存在*/@Order(2)@Testvoid usernameInput(){WebElement usernameInput=chromeDriver.findElement(By.xpath("//*[@id=\"username\"]"));Assertions.assertNotNull(usernameInput);}

测试密码输入框是否存在

    /*** 测试密码输入框是否存在*/@Order(3)@Testvoid passwordInput(){WebElement passwordInput=chromeDriver.findElement(By.xpath("//*[@id=\"password\"]"));Assertions.assertNotNull(passwordInput);}

测试登录按钮是否存在

    /*** 测试登录按钮是否存在*/@Order(4)@Testvoid testLoginButton(){WebElement loginButton=chromeDriver.findElement(By.xpath("//*[@id=\"submit\"]"));Assertions.assertNotNull(loginButton);}

测试注册跳转按钮是否存在

    /*** 测试注册跳转按钮是否存在*/@Order(5)@Testvoid testLoginJumpButton(){WebElement loginJumpButton=chromeDriver.findElement(By.xpath("/html/body/div/div/div/div[1]/div/div[3]/a"));Assertions.assertNotNull(loginJumpButton);}

测试结果:

版块

首先定义浏览器对象和url

/*** 1、浏览器对象* 2、访问登录页面的url*/public static ChromeDriver chromeDriver=createChromeDriver();@BeforeAllstatic void baseControl(){chromeDriver.get("http://49.232.185.203:58080/sign-in.html");chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#username")).sendKeys("baekhyun");chromeDriver.findElement(By.cssSelector("#password")).sendKeys("1992");chromeDriver.findElement(By.cssSelector("#submit")).click();}

测试导航栏中版块是否存在

/*** 测试导航栏中版块是否存在*/@Order(1)@Testvoid testExistBoard(){//首页WebElement board1=chromeDriver.findElement(By.xpath("//*[@id=\"nav_board_index\"]/a"));Assertions.assertNotNull(board1);//javaWebElement board2=chromeDriver.findElement(By.xpath("//*[@id=\"topBoardList\"]/li[2]/a"));Assertions.assertNotNull(board2);//c++WebElement board3=chromeDriver.findElement(By.xpath("//*[@id=\"topBoardList\"]/li[2]/a"));Assertions.assertNotNull(board3);//前端技术WebElement board4=chromeDriver.findElement(By.xpath("//*[@id=\"topBoardList\"]/li[2]/a"));Assertions.assertNotNull(board4);//MysqlWebElement board5=chromeDriver.findElement(By.xpath("//*[@id=\"topBoardList\"]/li[2]/a"));Assertions.assertNotNull(board5);//面试宝典WebElement board6=chromeDriver.findElement(By.xpath("//*[@id=\"topBoardList\"]/li[2]/a"));Assertions.assertNotNull(board6);//经验分享WebElement board7=chromeDriver.findElement(By.xpath("//*[@id=\"topBoardList\"]/li[2]/a"));Assertions.assertNotNull(board7);//招聘信息WebElement board8=chromeDriver.findElement(By.xpath("//*[@id=\"topBoardList\"]/li[2]/a"));Assertions.assertNotNull(board8);//福利待遇WebElement board9=chromeDriver.findElement(By.xpath("//*[@id=\"topBoardList\"]/li[2]/a"));Assertions.assertNotNull(board9);//灌水区WebElement board10=chromeDriver.findElement(By.xpath("//*[@id=\"topBoardList\"]/li[2]/a"));Assertions.assertNotNull(board10);}

测试夜间模式按钮是否存在

/*** 测试夜间模式按钮是否存在*/@Order(2)@Testvoid testExistButton(){WebElement button=chromeDriver.findElement(By.xpath("/html/body/div[1]/header[1]/div/div/div[2]/a[1]"));Assertions.assertNotNull(button);}

测试结果:

帖子

首先定义浏览器对象和url

/*** 1、浏览器对象* 2、访问登录页面的url*/public static ChromeDriver chromeDriver=createChromeDriver();@BeforeAllstatic void baseControl(){chromeDriver.get("http://49.232.185.203:58080/sign-in.html");chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#username")).sendKeys("baekhyun");chromeDriver.findElement(By.cssSelector("#password")).sendKeys("1992");chromeDriver.findElement(By.cssSelector("#submit")).click();}

测试发布帖子按钮是否存在

/*** 测试发布帖子按钮是否存在*/@Order(1)@Testvoid testPublish(){WebElement publish= chromeDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[1]/div/div/div[2]/div"));Assertions.assertNotNull(publish);}

测试发私信按钮是否存在

/*** 测试发私信按钮是否存在*/@Order(2)@Testvoid testSendMessage(){chromeDriver.findElement(By.xpath("//*[@id=\"artical-items-body\"]/div[1]/div/div[2]/div[1]/a/strong")).click();WebElement button=chromeDriver.findElement(By.xpath("//*[@id=\"btn_details_send_message\"]"));Assertions.assertNotNull(button);}

测试我的帖子按钮是否存在

/*** 测试我的帖子按钮是否存在*/@Order(3)@Testvoid testMyArticle(){//首先得点击下拉框chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown")).click();WebElement button=chromeDriver.findElement(By.xpath("//*[@id=\"index_user_profile\"]"));Assertions.assertNotNull(button);}

测试结果:

用户个人中心页

首先定义浏览器对象和url

    /*** 1、浏览器对象* 2、访问登录页面的url*/public static ChromeDriver chromeDriver=createChromeDriver();@BeforeAllstatic void baseControl(){chromeDriver.get("http://49.232.185.203:58080/sign-in.html");chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#username")).sendKeys("baekhyun");chromeDriver.findElement(By.cssSelector("#password")).sendKeys("1992");chromeDriver.findElement(By.cssSelector("#submit")).click();}

测试昵称输入框是否存在

    /*** 测试昵称输入框是否存在*/@Order(1)@Testvoid testNicknameInput(){//首先得点击下拉框chromeDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown")).click();chromeDriver.findElement(By.xpath("//*[@id=\"index_user_settings\"]")).click();WebElement nicknameInput=chromeDriver.findElement(By.xpath("//*[@id=\"setting_input_nickname\"]"));Assertions.assertNotNull(nicknameInput);}

测试邮箱地址是否存在

    /*** 测试邮箱地址输入框是否存在*/@Order(2)@Testvoid testEmailInput(){WebElement emailInput=chromeDriver.findElement(By.xpath("//*[@id=\"setting_input_email\"]"));Assertions.assertNotNull(emailInput);}

测试电话号码是否存在

    /*** 测试电话号码输入框是否存在*/@Order(3)@Testvoid testPhoneNumInput(){WebElement phoneNumInput=chromeDriver.findElement(By.xpath("//*[@id=\"setting_input_phoneNum\"]"));Assertions.assertNotNull(phoneNumInput);}

测试原密码是否存在

    /*** 测试原密码输入框是否存在*/@Order(4)@Testvoid testOldPasswordInput(){WebElement oldPasswordInput=chromeDriver.findElement(By.xpath("//*[@id=\"settings_input_oldPassword\"]"));Assertions.assertNotNull(oldPasswordInput);}

测试新密码是否存在

    /*** 测试新密码输入框是否存在*/@Order(5)@Testvoid testNewPasswordInput(){WebElement newPasswordInput=chromeDriver.findElement(By.xpath("//*[@id=\"settings_input_newPassword\"]"));Assertions.assertNotNull(newPasswordInput);}

测试确认密码是否存在

    /*** 测试确认密码输入框是否存在*/@Order(6)@Testvoid testPasswordRepeatInput(){WebElement passwordRepeatInput=chromeDriver.findElement(By.xpath("//*[@id=\"settings_input_passwordRepeat\"]"));Assertions.assertNotNull(passwordRepeatInput);}

测试提交修改按钮是否存在

    /*** 测试提交修改按钮是否存在*/@Order(7)@Testvoid testSubmitInput(){WebElement submitInput=chromeDriver.findElement(By.xpath("//*[@id=\"settings_submit_password\"]"));Assertions.assertNotNull(submitInput);}

测试个人简介标题是否存在

    /*** 测试个人简介标题是否存在*/@Order(8)@Testvoid testProfile(){String text=chromeDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[2]/div/div/div/div[2]/div/h3[5]")).getText();Assertions.assertEquals("个人简介",text);}

测试结果:

站内信

首先定义浏览器对象和url

/*** 1、浏览器对象* 2、访问登录页面的url*/public static ChromeDriver chromeDriver=createChromeDriver();@BeforeAllstatic void baseControl(){chromeDriver.get("http://49.232.185.203:58080/sign-in.html");chromeDriver.findElement(By.cssSelector("#username")).clear();chromeDriver.findElement(By.cssSelector("#password")).clear();chromeDriver.findElement(By.cssSelector("#username")).sendKeys("baekhyun");chromeDriver.findElement(By.cssSelector("#password")).sendKeys("1992");chromeDriver.findElement(By.cssSelector("#submit")).click();}

测试站内信按钮是否存在

     /*** 测试站内信按钮是否存在*/@Order(1)@Testvoid testMailButton(){WebElement mailButton=chromeDriver.findElement(By.xpath("/html/body/div[1]/header[1]/div/div/div[2]/div"));Assertions.assertNotNull(mailButton);}

测试站内信内回复按钮是否存在

    /*** 测试回复站内信按钮是否存在*/@Order(2)@Testvoid testReplyButton() throws InterruptedException {chromeDriver.findElement(By.xpath("/html/body/div[1]/header[1]/div/div/div[2]/div")).click();chromeDriver.findElement(By.xpath("//*[@id=\"index_div_message_list\"]/div/div/div[2]/a")).click();Thread.sleep(1000);WebElement replyButton=chromeDriver.findElement(By.xpath("//*[@id=\"btn_index_message_reply\"]"));Assertions.assertNotNull(replyButton);}

测试站内信内取消按钮是否存在

    /*** 测试站内信取消按钮是否存在*/@Order(3)@Testvoid testCancellationButton(){WebElement cancellationButton=chromeDriver.findElement(By.xpath("//*[@id=\"index_message_reply_cancel\"]"));Assertions.assertNotNull(cancellationButton);}

测试结果:

测试套件结果:

总结:目前针对论坛系统的测试如上述博客,由于部分用例无法进行自动化测试,所以进行相应的人工测试,且测试通过

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/20537.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Qt秘籍】[005]-Qt的首次邂逅-创建

一、如何创建文件&#xff1f; 当我们打开Qt Creator&#xff0c;你会发现整个界面类目繁多。现在&#xff0c;让我们直接开始新建一个项目。 1.点击左上角的“文件”>点击“新建文件或项目” 2.如图&#xff0c;选择“Application”>“Qt Wifgets application”> “…

奇偶校验位

描述 题目描述&#xff1a; 现在需要对输入的32位数据进行奇偶校验,根据sel输出校验结果&#xff08;1输出奇校验&#xff0c;0输出偶校验&#xff09; 信号示意图&#xff1a; 波形示意图&#xff1a; 输入描述&#xff1a; 输入信号 bus sel 类型 wi…

rust安装

目录 一、安装1.1 在Windows上安装1.2 在Linux下安装 二、包管理工具三、Hello World3.1 安装IDE3.2 输出Hello World 一、安装 1.1 在Windows上安装 点击页面 安装 Rust - Rust 程序设计语言 (rust-lang.org)&#xff0c;选择"下载RUSTUP-INIT.EXE(64位&#xff09;&qu…

2021JSP普及组第三题:插入排序

2021JSP普及组第三题 题目&#xff1a; 思路&#xff1a; 题目要求排序后根据操作进行对应操作。 操作一需要显示某位置数据排序后的位置&#xff0c;所以需要定义结构体数组储存原数据的位置和数据本身排序后所得数据要根据原位置输出排序后的位置&#xff0c;所以建立一个新…

Linux网络编程:应用层协议|HTTPS

目录 1.预备知识 1.1.加密和解密 1.2.常见加密方式 1.2.1.对称加密 1.2.2.非对称加密 ​编辑 1.3.数据摘要&#xff08;数据指纹&#xff09;和数据签名 1.4.证书 1.4.1.CA认证 1.4.2.证书和数字签名 2.HTTPS协议 2.1.自行设计HTTPS加密方案 2.1.1.只使用对称加密 …

构建企业级AI私有知识库

一、引言 在当今竞争激烈的市场环境中&#xff0c;企业为了保持竞争优势&#xff0c;需要高效地管理和利用内部知识资源。构建一个企业级AI私有知识库&#xff0c;不仅可以集中存储和管理企业知识&#xff0c;还能通过人工智能技术实现知识的智能化处理和利用。本文将详细介绍…

软考系统集成项目管理工程师第7章思维导图发布

2024年开年&#xff0c;软考系统集成项目管理工程师官方教程&#xff0c;迎来了阔别7年的大改版&#xff0c;改版之后的软考中项考试&#xff0c;离同宗兄弟高项考试渐行渐远。 中项第3版教程&#xff0c;仅仅从教程来看&#xff0c;其难度已经不亚于高级的信息系统项目管理师&…

WebGL开发三维家装设计

使用WebGL开发三维家装设计软件是一项复杂而有趣的任务&#xff0c;涉及3D建模、渲染、用户交互等多个方面。以下是详细的开发步骤和技术要点。北京木奇移动技术有限公司&#xff0c;专业的软件外包开发公司&#xff0c;欢迎交流合作。 1. 需求分析 目标用户 家装设计师家装公…

AVL树(C++)

文章目录 1. 键值对2. AVL树2.1 AVL树的概念2.2 AVL树节点的定义2.3 AVL树的插入2.3.1 按照二叉搜索树的方式插入新节点2.3.2 调整节点的平衡因子 2.4 AVL树的旋转2.4.1 右单旋2.4.2 左单旋2.4.3 左右双旋2.4.4 右左双旋 3. AVL树的删除4. AVL树的验证4. 源码 1. 键值对 键值对…

用follow.it为您的网站添加邮箱订阅功能(附2024版教程)

多数情况下网站用户浏览一次就不会来了&#xff08;即使用户已收藏您的网站&#xff09;&#xff0c;因为用户很可能已把您的网站忘了。那么怎么样才能抓住网站回头客&#xff0c;让用户再次回到您的网站呢&#xff1f;除了提供更优质的原创内容外&#xff0c;比较好的方法是给…

笔试强训week7

day1 Q1 难度⭐⭐ 旋转字符串_牛客题霸_牛客网 (nowcoder.com) 题目&#xff1a; 字符串旋转: 给定两字符串A和B&#xff0c;如果能将A从中间某个位置分割为左右两部分字符串&#xff08;可以为空串&#xff09;&#xff0c;并将左边的字符串移动到右边字符串后面组成新的…

c++新闻发布系统(支持登录注册)

c新闻发布系统(支持登录注册),支持新闻发布标题和内容 首先查看效果,系统主界面 vx:sredxc 这段代码是一个简单的新闻管理系统的实现。它包括两个类&#xff1a;UserManager&#xff08;用户管理&#xff09;和NewsManager&#xff08;新闻管理&#xff09;。UserManager负责用…

机器学习模型调试学习总结

1.学习内容 模型调试方法&#xff1a;冻结部分层&#xff0c;训练剩余层 实践&#xff1a;在一个预训练的 BERT 模型上冻结部分层&#xff0c;并训练剩余的层 模型调试方法&#xff1a;线性探测&#xff08;Linear Probe&#xff09; 实践&#xff1a;在一个预训练的 BERT …

crossover软件安装显示程序错误 crossover中文字体下载失败 运行exe乱码 crossover怎么运行软件

虽然Mac用户一直在不断的增加&#xff0c;但是很多人因为习惯了使用Windows系统上的软件&#xff0c;让他们在使用Mac时&#xff0c;也想照常使用Windows上的软件。借助系统兼容工具CrossOver&#xff0c;则可以便捷地在Mac中跨系统使用Windows系统下的应用和文件。 CrossOver…

深度学习入门

文章目录 深度学习基础前言深度学习应用计算机视觉 神经网络基础得分函数 f(x,W)损失函数Softmax分类器前向传播反向传播神经网络整体架构过拟合的解决办法激活函数 深度学习基础 前言 机器学习流程&#xff1a; 数据获取特征工程建立模型评估与应用 特征工程的作用&#x…

高考试卷押运车视频监控解决方案

一、引言 高考作为我国教育领域的重要事件&#xff0c;其公正、公平和安全性一直备受社会关注。试卷押运作为高考的重要环节&#xff0c;其安全性直接关系到高考的顺利进行和考生的切身利益。因此&#xff0c;对高考试卷押运车实施视频监控解决方案&#xff0c;对于确保试卷安…

蓝桥杯练习系统(算法训练)ALGO-935 互质数个数

资源限制 内存限制&#xff1a;256.0MB C/C时间限制&#xff1a;1.0s Java时间限制&#xff1a;3.0s Python时间限制&#xff1a;5.0s 互质数个数 问题描述 已知正整数x&#xff0c;求1~x-1中&#xff0c;有多少与x互质的数。&#xff08;互质是指两个数最大公约数为1&…

PieCloudDB Database Flink Connector:让数据流动起来

面对客户环境中长期运行的各种类型的传统数据库&#xff0c;如何优雅地设计数据迁移的方案&#xff0c;既能灵活地应对各种数据导入场景和多源异构数据库&#xff0c;又能满足客户对数据导入结果的准确性、一致性、实时性的要求&#xff0c;让客户平滑地迁移到 PieCloudDB 数据…

arco design表单label和输入框的空间分布

表单空间分布 arco利用的栅格系统来实现label、input的大小分布 <a-form :model"formData.form" :label-col-props"{ span: 6 }" :wrapper-col-props"{ span: 18 }" >// 其它...... </a-form>栅格系统中&#xff0c;默认空间总量2…

FreeRtos进阶——通用链表的实现方式

通用链表实现方式&#xff08;一&#xff09; struct node_t {struct node_t *next; };struct person {struct node_t node;char *name;int age; };struct dog {struct node_t node;char *name;int age;char *class; };在此链表中&#xff0c;node结构体被放在了最前面&#x…