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

目录

前言

一、测试环境

二、环境部署

三、测试用例

四、执行测试

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({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/19436.shtml

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

相关文章

Redis实战篇3:优惠券秒杀

说明 该实战篇基于某马的Redis课程中的《某马点评项目》。非常适合有相关经验、缺少企业级解决方案&#xff0c;或者想要复习的人观看&#xff0c;全篇都会一步一步的推导其为什么要这么做&#xff0c;分析其优缺点&#xff0c;达到能够应用的地步。 本实战篇中心思想就是把项目…

Mariadb操作命令指南

MariaDB简介 ​ 以下内容仅是站长或网友个人学习笔记、总结和研究收藏。不保证正确性&#xff0c;因使用而带来的风险与本站无关&#xff01; 数据库应用程序与主应用程序分开存在&#xff0c;并存储数据集合。 每个数据库都使用一个或多个API来创建&#xff0c;访问&#xf…

分立元件实现稳压

电路原理图 优点&#xff1a;电压精度高&#xff0c;可以调整输出电压 缺点&#xff1a;压差大时效率较低&#xff0c;发热严重。 参考连接 TL431-高效5V精密稳压器-电路知识干货 (qq.com)https://mp.weixin.qq.com/s?__bizMzkxNzIxNTc5OQ&mid2247484878&idx1&…

操作系统教材第6版——个人笔记1

第一章 计算机操作系统概述 操作系统是计算机系统中最重要的系统软件&#xff0c;它统一管理计算机系统的硬件资源与信息资源&#xff0c;控制与调度上层软件的执行并为其提供易于使用的接口。从资源管理、程序控制、操作控制、人机交互、程序接口、系统结构6个角度深入观察操…

Github 如何配置 PNPM 的 CI 环境

最近出于兴趣在写一个前端框架 echox&#xff0c;然后在 Github 上给它配置了最简单的 CI 环境&#xff0c;这里简单记录一下。 特殊目录 首先需要在项目根目录里面创建 Github 仓库中的一个特殊目录&#xff1a;.github/workflows&#xff0c;用于存放 Github Actions 的工作…

269 基于matlab的四连杆机构动力学参数计算

基于matlab的四连杆机构动力学参数计算。将抽油机简化为4连杆机构&#xff0c;仿真出悬点的位移、速度、加速度、扭矩因数、游梁转角等参数&#xff0c;并绘出图形。程序已调通&#xff0c;可直接运行。 269机构动力学参数计算 位移、速度、加速度 - 小红书 (xiaohongshu.com)

段码屏|液晶显示模块|超低功耗LCD驱动芯片

1 简介 PC164S32 是一款支持 128 点 (32 4)显示 的多功能 LCD 控制器芯片&#xff0c;内部存储器RAM数据直接映射到 LCD 显示。可软件配置特性使其适用于包括 LCD 模块和显示子系统在内的多种 LCD 应用。主控制器与 PC164S32接口仅需3 或 4 条线。内置的省电模式极大的降低了功…

我给线程池管理框架hippo4j找bug

1 虚拟机参数不生效 hippo4j的docker启动脚本位于 docker/docker-startup.sh 。从下图可以看到 JAVA_OPT放在了jar包名 hippo4j-server.jar之后&#xff0c;而只有项目参数才放在jar包名之后。 实际上这里JAVA_OPT中包含虚拟机参数&#xff0c;而虚拟机参数要放在jar包名之前…

使用 CNN 训练自己的数据集

CNN&#xff08;练习数据集&#xff09; 1.导包&#xff1a;2.导入数据集&#xff1a;3. 使用image_dataset_from_directory()将数据加载tf.data.Dataset中&#xff1a;4. 查看数据集中的一部分图像&#xff0c;以及它们对应的标签&#xff1a;5.迭代数据集 train_ds&#xff0…

【漏洞复现】DT-高清车牌识别摄像机 任意文件读取漏洞

0x01 产品简介 DT-高清 车牌识别摄像机是一款先进的安防设备&#xff0c;采用高清图像传感器和先进的识别算法&#xff0c;能够精准、快速地识别车牌信息。其高清晰该摄像机结合了智能识别技术&#xff0c;支持实时监宴图像质量确保在各种光照和天气条件下都能准确捕捉车牌信息…

【面试八股总结】MySQL事务:事务特性、事务并行、事务的隔离级别

参考资料&#xff1a;小林coding 一、事务的特性ACID 原子性&#xff08;Atomicity&#xff09; 一个事务是一个不可分割的工作单位&#xff0c;事务中的所有操作&#xff0c;要么全部完成&#xff0c;要么全部不完成&#xff0c;不会结束在中间某个环节。原子性是通过 undo …

C#根据数据量自动排版标签的样例

这是一个C#根据数据量自动排版标签的样例 using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Drawing; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using HslCommuni…

代码随想录算法训练营第四十五天 | 1049. 最后一块石头的重量 II、494. 目标和、474.一和零

1049. 最后一块石头的重量 II 视频讲解&#xff1a; 动态规划之背包问题&#xff0c;这个背包最多能装多少&#xff1f;LeetCode&#xff1a;1049.最后一块石头的重量II_哔哩哔哩_bilibili 代码随想录 解题思路 直接将这一些石头&#xff0c;分为两堆&#xff0c;让他们尽可能…

C语言 | Leetcode C语言题解之第120题三角形最小路径和

题目&#xff1a; 题解&#xff1a; int minimumTotal(int** triangle, int triangleSize, int* triangleColSize) {int f[triangleSize];memset(f, 0, sizeof(f));f[0] triangle[0][0];for (int i 1; i < triangleSize; i) {f[i] f[i - 1] triangle[i][i];for (int j …

【excel】设置二级联动菜单

文章目录 【需求】在一级菜单选定后&#xff0c;二级菜单联动显示一级菜单下的可选项【步骤】step1 制作辅助列1.列转行2.在辅助列中匹配班级成员 之前做完了 【excel】设置可变下拉菜单&#xff08;一级联动下拉菜单&#xff09;&#xff0c;开始做二级联动菜单。 【需求】在…

python实现——综合类型数据挖掘任务(无监督的分类任务)

综合类型数据挖掘任务 航空公司客户价值分析。航空公司客户价值分析。航空公司客户价值分析。航空公司已积累了大量的会员档案信息和其乘坐航班记录&#xff08;air_data.csv&#xff09;&#xff0c;以2014年3月31日为结束时间抽取两年内有乘机记录的所有客户的详细数据。利用…

万界星空科技MES系统功能介绍

制造执行系统或MES 是一个全面的动态软件系统&#xff0c;用于监视、跟踪、记录和控制从原材料到成品的制造过程。MES在企业资源规划(ERP) 和过程控制系统之间提供了一个功能层&#xff0c;为决策者提供了提高车间效率和优化生产所需的数据。 万界星空科技MES 系统基础功能&am…

【全开源】Java短剧系统微信小程序+H5+微信公众号+APP 源码

打造属于你的精彩短视频平台 一、引言&#xff1a;为何选择短剧系统小程序&#xff1f; 在当今数字化时代&#xff0c;短视频已经成为人们日常生活中不可或缺的一部分。而短剧系统小程序源码&#xff0c;作为构建短视频平台的强大工具&#xff0c;为广大开发者提供了快速搭建…

03-树1 树的同构(浙大数据结构PTA习题)

03-树1 树的同构 分数 25 作者 陈越 单位 浙江大学 给定两棵树 T1​ 和 T2​。如果 T1​ 可以通过若干次左右孩子互换就变成 T2​&#xff0c;则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的&#xff0c;因为我们把其中一棵树的结点A、B、G…

CSPM.pdf

PDF转图片 归档&#xff1a;