当前位置: 首页 > news >正文

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

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

二、自动化测试

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

1. 准备工作

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

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.example</groupId><artifactId>myblog-selenium</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><dependencies><!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --><dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-java</artifactId><version>4.0.0</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.6</version></dependency><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId><version>5.8.2</version><scope>test</scope></dependency><dependency><groupId>org.junit.platform</groupId><artifactId>junit-platform-commons</artifactId><version>1.8.2</version><scope>test</scope></dependency><dependency><groupId>org.junit.platform</groupId><artifactId>junit-platform-reporting</artifactId><version>1.8.2</version><scope>test</scope></dependency><dependency><groupId>org.junit.platform</groupId><artifactId>junit-platform-suite</artifactId><version>1.8.2</version><scope>test</scope></dependency></dependencies></project>

(2)创建公共类

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

package com.webAutoTest.common;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.time.Duration;/*** Created with IntelliJ IDEA.* Description: 创建驱动对象,并返回该对象* User: WangWZ* Date: 2023-09-05* Time: 9:48*/
public class CommonDriver {//使用单例模式创建驱动private static ChromeOptions options = new ChromeOptions();public static ChromeDriver driver = null;public static ChromeDriver getDriver(){if (driver == null) {options.addArguments("--remote-allow-origins=*");driver = new ChromeDriver(options);//创建驱动的时候就加上隐式等待//整个测试就都会隐式等待了driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));}return driver;}}

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

2. 注册页面 

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

package com.webAutoTest.tests;import com.webAutoTest.common.CommonDriver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;import java.time.Duration;/*** Created with IntelliJ IDEA.* Description: 注册页面测试* User: WangWZ* Date: 2023-09-05* Time: 9:48*/
public class RegTest {//获取驱动对象static ChromeDriver driver = CommonDriver.getDriver();@BeforeAllpublic static void getURL() {driver.get("http://58.87.89.71:8009/reg.html");//使用隐式等待渲染页面完成driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));}/*** 用户名已存在* @param username* @param password1* @param password2*/@ParameterizedTest@CsvSource({"王文哲", "456", "456"})public void RegNameExist(String username, String password1, String password2) {driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password1);driver.findElement(By.xpath("//*[@id=\"password2\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password2\"]")).sendKeys(password2);Alert alert = driver.switchTo().alert();String str =alert.getText();Assertions.assertEquals("该用户名已被使用,请重新输入", str);alert.accept();}/*** 用户名为空* @param username* @param password1* @param password2*/@ParameterizedTest@CsvSource({"", "456", "456"})public void RegNameNull(String username, String password1, String password2) {driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password1);driver.findElement(By.xpath("//*[@id=\"password2\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password2\"]")).sendKeys(password2);Alert alert = driver.switchTo().alert();String str =alert.getText();Assertions.assertEquals("请先输入用户名", str);alert.accept();}/*** 密码为空* @param username* @param password1* @param password2*/@ParameterizedTest@CsvSource({"王王文哲", "", ""})public void RegPasswordNull(String username, String password1, String password2) {driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password1);driver.findElement(By.xpath("//*[@id=\"password2\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password2\"]")).sendKeys(password2);Alert alert = driver.switchTo().alert();String str =alert.getText();Assertions.assertEquals("请先输入密码", str);alert.accept();}/*** 确认密码和密码不一致* @param username* @param password1* @param password2*/@ParameterizedTest@CsvSource({"汪汪", "456", "1456"})public void RegPasswordDe(String username, String password1, String password2) {driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password1);driver.findElement(By.xpath("//*[@id=\"password2\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password2\"]")).sendKeys(password2);Alert alert = driver.switchTo().alert();String str =alert.getText();Assertions.assertEquals("两次密码输入的不一致,请先检查", str);alert.accept();}/*** 用户名或密码中存在特殊字符* @param username* @param password1* @param password2*/@ParameterizedTest@CsvSource({"@w王1", "45@6", "45@6"})public void RegExistSpecial(String username, String password1, String password2) {driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password1);driver.findElement(By.xpath("//*[@id=\"password2\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password2\"]")).sendKeys(password2);Alert alert = driver.switchTo().alert();String str =alert.getText();Assertions.assertEquals("恭喜,注册成功", str);alert.accept();}/*** 注册标题*/@Testpublic void RegTitle() {String str = driver.findElement(By.xpath("/html/body/div[2]/div/h3")).getText();Assertions.assertEquals("注册",str);}/*** 输入框显示*/@Testpublic void RegNameInput(){WebElement element = driver.findElement(By.xpath("//*[@id=\"username\"]"));Assertions.assertNotNull(element);}/*** 输入框文字*/@Testpublic void RegUName() {String str = driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/span")).getText();Assertions.assertEquals("用户名",str);}/*** 密码框显示*/@Testpublic void RegPasswordInput(){WebElement element = driver.findElement(By.xpath("//*[@id=\"password\"]"));Assertions.assertNotNull(element);}/*** 密码框文字*/@Testpublic void RegPassword() {String str = driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/span")).getText();Assertions.assertEquals("密码",str);}/*** 确认密码框显示*/@Testpublic void RegPassword2Input(){WebElement element = driver.findElement(By.xpath("//*[@id=\"password2\"]"));Assertions.assertNotNull(element);}/*** 确认密码框文字*/@Testpublic void RegPassword2() {String str = driver.findElement(By.xpath("/html/body/div[2]/div/div[3]/span")).getText();Assertions.assertEquals("确认密码",str);}/*** 验证码图片显示*/@Testpublic void RegPhoto(){WebElement element = driver.findElement(By.xpath("//*[@id=\"codeimg\"]"));Assertions.assertNotNull(element);}/*** 验证码文字*/@Testpublic void RegDraft() {String str = driver.findElement(By.xpath("/html/body/div[2]/div/div[4]/span")).getText();Assertions.assertEquals("验证码",str);}}

3. 登录页面

package com.webAutoTest.tests;import com.webAutoTest.common.CommonDriver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;import java.time.Duration;/*** Created with IntelliJ IDEA.* Description: 登录页面* User: WangWZ* Date: 2023-09-05* Time: 9:49*/
public class LoginTest {ChromeDriver driver = CommonDriver.getDriver();@BeforeEachpublic void getUrl(){driver.get("http://58.87.89.71:8009/login.html");driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));}/*** 正确的用户名和密码*/@ParameterizedTest@CsvSource({"王文哲","123"})public void LoginTrue(String username, String password) {driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password);driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();String str = driver.getCurrentUrl();Assertions.assertEquals("http://58.87.89.71:8009/myblog_list.html",str);driver.navigate();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));}/*** 错误的用户名和密码*/@ParameterizedTest@CsvSource({"王文哲","1234"})public void LoginFalse(String username, String password) {driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password);driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));Alert alert = driver.switchTo().alert();String str = alert.getText();Assertions.assertEquals("抱歉登录失败,用户名或密码输入错误,请重试!",str);alert.accept();}/*** 登录密码为空*/@ParameterizedTest@CsvSource({"王文哲",""})public void LoginPasswordNull(String username, String password) {driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password);driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));Alert alert = driver.switchTo().alert();String str = alert.getText();Assertions.assertEquals("请先输入密码!",str);alert.accept();}/*** 用户名为空*/@ParameterizedTest@CsvSource({"","123"})public void LoginNameNull(String username, String password) {driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password);driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));Alert alert = driver.switchTo().alert();String str = alert.getText();Assertions.assertEquals("请先输入用户名!",str);alert.accept();}/*** 密码或用户名有特殊字符*/@ParameterizedTest@CsvSource({"@w王1", "45@6"})public void Login(String username, String password) {driver.findElement(By.xpath("//*[@id=\"username\"]")).clear();driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(password);driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));String str = driver.getCurrentUrl();Assertions.assertEquals("http://58.87.89.71:8009/myblog_list.html",str);driver.navigate();}/*** 注册按钮功能*/@Testpublic void LoginToReg() {driver.findElement(By.xpath("/html/body/div[1]/a[3]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));String str = driver.getCurrentUrl();Assertions.assertEquals("http://58.87.89.71:8009/reg.html",str);driver.navigate();}/*** 登录标题*/@Testpublic void LoginTitle() {String str = driver.findElement(By.xpath("/html/body/div[2]/div/h3")).getText();Assertions.assertEquals("登录",str);}/*** 输入框显示*/@Testpublic void LoginNameInput(){WebElement element = driver.findElement(By.xpath("//*[@id=\"username\"]"));Assertions.assertNotNull(element);}/*** 输入框文字*/@Testpublic void LoginUName() {String str = driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/span")).getText();Assertions.assertEquals("用户名",str);}/*** 密码框显示*/@Testpublic void LoginPasswordInput(){WebElement element = driver.findElement(By.xpath("//*[@id=\"password\"]"));Assertions.assertNotNull(element);}/*** 密码框文字*/@Testpublic void LoginPassword() {String str = driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/span")).getText();Assertions.assertEquals("密码",str);}/*** 登录按钮*/@Testpublic void LoginSub() {String str = driver.findElement(By.xpath("//*[@id=\"submit\"]")).getText();Assertions.assertEquals("提交",str);}}

4. 列表页面

package com.webAutoTest.tests;import com.webAutoTest.common.CommonDriver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;import java.time.Duration;/*** Created with IntelliJ IDEA.* Description: 列表页面* User: WangWZ* Date: 2023-09-05* Time: 9:49*/
public class ListTest {ChromeDriver driver = CommonDriver.getDriver();@BeforeEachpublic void getUrl(){driver.get("http://58.87.89.71:8009/login.html");driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));}/*** 主页按钮*/@Testpublic void ListToL() {driver.findElement(By.xpath("/html/body/div[1]/a[1]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));String str = driver.getCurrentUrl();Assertions.assertEquals("http://58.87.89.71:8009/login.html",str);driver.navigate();}/*** 写博客按钮*/@Testpublic void ListToEdit() {driver.findElement(By.xpath("/html/body/div[1]/a[2]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));String str = driver.getCurrentUrl();Assertions.assertEquals("http://58.87.89.71:8009/blog_add.html",str);driver.navigate();}/*** 我的主页按钮*/@Testpublic void ListToMyL() {driver.findElement(By.xpath("/html/body/div[1]/a[3]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));String str = driver.getCurrentUrl();Assertions.assertEquals("http://58.87.89.71:8009/myblog_list.html",str);driver.navigate();}/*** 分页功能,第一页*/@Testpublic void ListByPage() {driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/button[2]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));Alert alert = driver.switchTo().alert();String str = alert.getText();Assertions.assertEquals("当前已经在首页了",str);alert.accept();}}

5. 写博客页面

package com.webAutoTest.tests;import com.webAutoTest.common.CommonDriver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;import java.time.Duration;/*** Created with IntelliJ IDEA.* Description:写博客页面* User: WangWZ* Date: 2023-09-05* Time: 9:50*/
public class EditTest {ChromeDriver driver = CommonDriver.getDriver();@BeforeEachpublic void getUrl(){driver.get("http://58.87.89.71:8009/blog_add.html");driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));}/*** 标题为空*/@ParameterizedTest@CsvSource({"","111111"})public void EditTitleNull(String title,String content) {driver.findElement(By.xpath("//*[@id=\"title\"]")).clear();driver.findElement(By.xpath("//*[@id=\"title\"]")).sendKeys(title);driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).clear();driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).sendKeys(content);driver.findElement(By.xpath("/html/body/div[2]/div[1]/button[1]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));Alert alert = driver.switchTo().alert();alert.accept();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));Alert alert2 = driver.switchTo().alert();String str2 =alert.getText();Assertions.assertEquals("请先输入标题!", str2);alert.accept();}/*** 内容为空*/@ParameterizedTest@CsvSource({"222",""})public void EditContentNull(String title,String content) {driver.findElement(By.xpath("//*[@id=\"title\"]")).clear();driver.findElement(By.xpath("//*[@id=\"title\"]")).sendKeys(title);driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).clear();driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).sendKeys(content);driver.findElement(By.xpath("/html/body/div[2]/div[1]/button[1]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));Alert alert = driver.switchTo().alert();alert.accept();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));Alert alert2 = driver.switchTo().alert();String str2 =alert.getText();Assertions.assertEquals("请先输入文章内容!", str2);alert.accept();}/*** 发布文章*/@ParameterizedTest@CsvSource({"Java精选","数据类型"})public void EditSub(String title,String content) {driver.findElement(By.xpath("//*[@id=\"title\"]")).clear();driver.findElement(By.xpath("//*[@id=\"title\"]")).sendKeys(title);driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).clear();driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).sendKeys(content);driver.findElement(By.xpath("/html/body/div[2]/div[1]/button[1]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));Alert alert = driver.switchTo().alert();alert.accept();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));Alert alert2 = driver.switchTo().alert();String str2 =alert.getText();Assertions.assertEquals("恭喜:文章添加成功!是否继续添加文章?", str2);alert.dismiss();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));String url = driver.getCurrentUrl();Assertions.assertEquals("http://58.87.89.71:8009/myblog_list.html", url);driver.navigate();}/*** 存为草稿*/@ParameterizedTest@CsvSource({"Java精选2","数据类型2"})public void EditSubDraft(String title,String content) {driver.findElement(By.xpath("//*[@id=\"title\"]")).clear();driver.findElement(By.xpath("//*[@id=\"title\"]")).sendKeys(title);driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).clear();driver.findElement(By.xpath("//*[@id=\"editorDiv\"]/div[1]/div[6]")).sendKeys(content);driver.findElement(By.xpath("/html/body/div[2]/div[1]/button[2]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));Alert alert = driver.switchTo().alert();String str =alert.getText();Assertions.assertEquals("恭喜:保存草稿成功!", str);alert.accept();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));String url = driver.getCurrentUrl();Assertions.assertEquals("http://58.87.89.71:8009/mydraftblog_list.html", url);driver.navigate();}}

6.  草稿箱页面

package com.webAutoTest.tests;import com.webAutoTest.common.CommonDriver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;import java.time.Duration;/*** Created with IntelliJ IDEA.* Description: 草稿箱页面* User: WangWZ* Date: 2023-09-05* Time: 9:49*/
public class DraftTest {ChromeDriver driver = CommonDriver.getDriver();@BeforeEachpublic void getUrl(){driver.get("http://58.87.89.71:8009/login.html");driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));}/*** 主页按钮*/@Testpublic void ListToL() {driver.findElement(By.xpath("/html/body/div[1]/a[1]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));String str = driver.getCurrentUrl();Assertions.assertEquals("http://58.87.89.71:8009/login.html",str);driver.navigate();}/*** 写博客按钮*/@Testpublic void ListToEdit() {driver.findElement(By.xpath("/html/body/div[1]/a[2]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));String str = driver.getCurrentUrl();Assertions.assertEquals("http://58.87.89.71:8009/blog_add.html",str);driver.navigate();}/*** 我的主页按钮*/@Testpublic void ListToMyL() {driver.findElement(By.xpath("/html/body/div[1]/a[3]")).click();driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));String str = driver.getCurrentUrl();Assertions.assertEquals("http://58.87.89.71:8009/myblog_list.html",str);driver.navigate();}}

7. 文章详情页面

package com.webAutoTest.tests;import com.webAutoTest.common.CommonDriver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;/*** Created with IntelliJ IDEA.* Description:* User: WangWZ* Date: 2023-09-05* Time: 9:49*/
public class DetailTest {static ChromeDriver driver = CommonDriver.getDriver();@BeforeEachpublic void getUrl(){driver.get("http://58.87.89.71:8009/mydraftblog_list.html");}/** 文章文字是否正确* */@Testpublic void testWz(){String text = driver.findElement(By.cssSelector("/html/body/div[2]/div[1]/div/div[1]/span[1]")).getText();Assertions.assertEquals("文章",text);}/** 分类文字是否正确* */@Testpublic void testFl(){String text = driver.findElement(By.cssSelector("/html/body/div[2]/div[1]/div/div[1]/span[2]")).getText();Assertions.assertEquals("分类",text);}}

三、使用套件Suit执行

具体Junit注解:Junit 单元测试框架(简单使用)

package com.webAutoTest.tests;import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;/*** Created with IntelliJ IDEA.* Description:* User: WangWZ* Date: 2023-09-05* Time: 16:54*/
@Suite
@SelectClasses({LoginTest.class,RegTest.class,LoginTest.class,ListTest.class,EditTest.class,DetailTest.class,DriverQuitTest.class})
public class RunSuit {
}

相关文章:

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

一、个人博客系统测试用例 二、自动化测试 使用selenium4 Junit5单元测试框架&#xff0c;来进行简单的自动化测试。 1. 准备工作 &#xff08;1&#xff09;引入依赖&#xff0c;此时的pom.xml文件&#xff1a; <?xml version"1.0" encoding"UTF-8&quo…...

C语言文件读写常用函数

文章目录 1. fopen函数2. fclose函数3. fgetc函数4. fgets函数5. fputc函数6. fputs函数7. fprintf函数8. fscanf函数9. fseek函数10. ftell函数 1. fopen函数 返回值&#xff1a;文件指针&#xff08;FILE*&#xff09;参数&#xff1a;文件名&#xff08;包括文件路径&#…...

【C++基础】实现日期类

​&#x1f47b;内容专栏&#xff1a; C/C编程 &#x1f428;本文概括&#xff1a; C实现日期类。 &#x1f43c;本文作者&#xff1a; 阿四啊 &#x1f438;发布时间&#xff1a;2023.9.7 对于类的成员函数的声明和定义&#xff0c;我们在类和对象上讲到过&#xff0c;需要进行…...

C语言程序设计—通讯录实现

本篇文章主要是实现一个简易的通讯录&#xff1a; 功能如下&#xff1a; 添加用户修改用户删除用户查找用户&#xff08;可重名&#xff09;按名字或年龄排序显示用户保存通讯录日志追加 有如下知识点&#xff1a; 动态数组结构体枚举自定义标识符和宏文件打开与存储函数指针…...

实战:大数据Flink CDC同步Mysql数据到ElasticSearch

文章目录 前言知识积累CDC简介CDC的种类常见的CDC方案比较 Springboot接入Flink CDC环境准备项目搭建 本地运行集群运行将项目打包将包传入集群启动远程将包部署到flink集群 写在最后 前言 前面的博文我们分享了大数据分布式流处理计算框架Flink和其基础环境的搭建&#xff0c…...

B-Tree 索引和 Hash 索引的对比

分析&回答 B-Tree 索引的特点 B-tree 索引可以用于使用 , >, >, <, < 或者 BETWEEN 运算符的列比较。如果 LIKE 的参数是一个没有以通配符起始的常量字符串的话也可以使用这种索引。 有时&#xff0c;即使有索引可以使用&#xff0c;MySQL 也不使用任何索引。…...

入门Python编程:了解计算机语言、Python介绍和开发环境搭建

文章目录 Python入门什么是计算机语言1. 机器语言2. 符号语言&#xff08;汇编&#xff09;3. 高级语言 编译型语言和解释型语言1. 编译型语言2. 解释型语言 Python的介绍Python开发环境搭建Python的交互界面 python学习专栏python基础知识&#xff08;0基础入门&#xff09;py…...

深度解析Redisson框架的分布式锁运行原理与高级知识点

推荐阅读 项目实战:AI文本 OCR识别最佳实践 AI Gamma一键生成PPT工具直达链接 玩转cloud Studio 在线编码神器 玩转 GPU AI绘画、AI讲话、翻译,GPU点亮AI想象空间 资源分享 史上最全文档AI绘画stablediffusion资料分享 AI绘画关于SD,MJ,GPT,SDXL百科全书 AI绘画 stable…...

C#扩展方法

参数列表中this的这种用法是在.NET 3.0之后新增的一种特性---扩展方法。通过这个属性可以让程序员在现有的类型上添加扩展方法&#xff08;无需创建新的派生类型、重新编译或者以其他方式修改原始类型&#xff09;。 扩展方法是一种特殊的静态方法&#xff0c;虽然是静态方法&a…...

uniapp 高度铺满全屏

问题&#xff1a;在有uni-tabbar的情况下&#xff0c;页面铺满剩下的部分 <template><view :style"{height:screenHeightpx}" class"page"></view> </template> <script>export default {data() {return {screenHeight: &q…...

UG\NX二次开发 判断向量在指定的公差内是否为零,判断是否是零向量 UF_VEC3_is_zero

文章作者:里海 来源网站:王牌飞行员_里海_里海NX二次开发3000例,里海BlockUI专栏,C\C++-CSDN博客 简介: UG\NX二次开发 判断向量在指定的公差内是否为零,判断是否是零向量 UF_VEC3_is_zero 效果: 代码: #include "me.hpp"void ufusr(char* param, int* retco…...

2023年MySQL实战核心技术第一篇

目录 四 . 基础架构&#xff1a;一条SQl查询语句是如何执行的&#xff1f; 4.1 MySQL逻辑架构图&#xff1a; 4.2 MySQL的Server层和存储引擎层 4.2.1 连接器 4.2.1.1 解释 4.2.1.2 MySQL 异常重启 解决方案&#xff1a; 4.2.1.2.1. 定期断开长连接&#xff1a; 4.2.1.2.2. 初始…...

hivesql执行过程

语法解析 SemanticAnalyzer SemanticAnalyzer是Hive中的语义分析器&#xff0c;负责检查Hive SQL程序的语义是否正确。SemanticAnalyzer会对Hive SQL程序进行以下检查&#xff1a; 检查过程 语法检查 SemanticAnalyzer会检查Hive SQL程序的语法是否正确&#xff0c;包括关…...

C语言学习:8、深入数据类型

数据超过类型规定的大小怎么办 C语言中&#xff0c;如果需要用的整数大于int类型的最大值了怎么办&#xff1f; 我们知道int能表示的最大数是2147483647&#xff0c;最小的数是-2147483648&#xff0c;为什么&#xff1f; 因为字32位系统中&#xff0c;寄存器是32位的&#…...

生成树协议 STP(spanning-tree protocol)

一、STP作用 1、消除环路&#xff1a;通过阻断冗余链路来消除网络中可能存在的环路。 2、链路备份&#xff1a;当活动路径发生故障时&#xff0c;激活备份链路&#xff0c;及时恢复网络连通性。 二、STP选举机制 1、目的&#xff1a;找到阻塞的端口 2、STP交换机的角色&am…...

【LeetCode】312.戳气球

题目 有 n 个气球&#xff0c;编号为0 到 n - 1&#xff0c;每个气球上都标有一个数字&#xff0c;这些数字存在数组 nums 中。 现在要求你戳破所有的气球。戳破第 i 个气球&#xff0c;你可以获得 nums[i - 1] * nums[i] * nums[i 1] 枚硬币。 这里的 i - 1 和 i 1 代表和…...

商业数据分析概论

&#x1f433; 我正在和鲸社区参加“商业数据分析训练营活动” https://www.heywhale.com/home/competition/6487de6649463ee38dbaf58b &#xff0c;以下是我的学习笔记&#xff1a; 学习主题&#xff1a;波士顿房价数据快速查看 日期&#xff1a;2023.9.4 关键概念/知识点&…...

Golang GUI框架

Golang GUI框架fyne fyne简介第一个fyne应用fyne应用程序和运行循环fyne更新GUI内容fyne窗口处理fyne解决中文乱码问题fyne应用打包fyne画布和画布对象fyne容器和布局fyne绘制和动画fyne盒子布局fyne网格grid布局fyne网格包裹布局fyne边框布局fyne表单布局fyne中心布局fyne ma…...

LeetCode刷题笔记【24】:贪心算法专题-2(买卖股票的最佳时机II、跳跃游戏、跳跃游戏II)

文章目录 前置知识122.买卖股票的最佳时机II题目描述贪心-直观写法贪心-优化代码更简洁 55. 跳跃游戏题目描述贪心-借助ability数组贪心-只用int far记录最远距离 45.跳跃游戏II题目描述回溯算法贪心算法 总结 前置知识 参考前文 参考文章&#xff1a; LeetCode刷题笔记【23】…...

游戏出现卡顿有哪些因素

一、服务器CPU内存占用过大会导致卡顿&#xff0c;升级CPU内存或者优化自身程序占用都可以解决。 二、带宽跑满导致卡&#xff0c;可以升级带宽解决。 二、平常不卡&#xff0c;有大型的活动的时候会卡&#xff0c;这方面主要是服务器性能方面不够导致的&#xff0c;性能常说…...

2025年能源电力系统与流体力学国际会议 (EPSFD 2025)

2025年能源电力系统与流体力学国际会议&#xff08;EPSFD 2025&#xff09;将于本年度在美丽的杭州盛大召开。作为全球能源、电力系统以及流体力学领域的顶级盛会&#xff0c;EPSFD 2025旨在为来自世界各地的科学家、工程师和研究人员提供一个展示最新研究成果、分享实践经验及…...

基于uniapp+WebSocket实现聊天对话、消息监听、消息推送、聊天室等功能,多端兼容

基于 ​UniApp + WebSocket​实现多端兼容的实时通讯系统,涵盖WebSocket连接建立、消息收发机制、多端兼容性配置、消息实时监听等功能,适配​微信小程序、H5、Android、iOS等终端 目录 技术选型分析WebSocket协议优势UniApp跨平台特性WebSocket 基础实现连接管理消息收发连接…...

连锁超市冷库节能解决方案:如何实现超市降本增效

在连锁超市冷库运营中&#xff0c;高能耗、设备损耗快、人工管理低效等问题长期困扰企业。御控冷库节能解决方案通过智能控制化霜、按需化霜、实时监控、故障诊断、自动预警、远程控制开关六大核心技术&#xff0c;实现年省电费15%-60%&#xff0c;且不改动原有装备、安装快捷、…...

STM32标准库-DMA直接存储器存取

文章目录 一、DMA1.1简介1.2存储器映像1.3DMA框图1.4DMA基本结构1.5DMA请求1.6数据宽度与对齐1.7数据转运DMA1.8ADC扫描模式DMA 二、数据转运DMA2.1接线图2.2代码2.3相关API 一、DMA 1.1简介 DMA&#xff08;Direct Memory Access&#xff09;直接存储器存取 DMA可以提供外设…...

Spring Boot面试题精选汇总

&#x1f91f;致敬读者 &#x1f7e9;感谢阅读&#x1f7e6;笑口常开&#x1f7ea;生日快乐⬛早点睡觉 &#x1f4d8;博主相关 &#x1f7e7;博主信息&#x1f7e8;博客首页&#x1f7eb;专栏推荐&#x1f7e5;活动信息 文章目录 Spring Boot面试题精选汇总⚙️ **一、核心概…...

ardupilot 开发环境eclipse 中import 缺少C++

目录 文章目录 目录摘要1.修复过程摘要 本节主要解决ardupilot 开发环境eclipse 中import 缺少C++,无法导入ardupilot代码,会引起查看不方便的问题。如下图所示 1.修复过程 0.安装ubuntu 软件中自带的eclipse 1.打开eclipse—Help—install new software 2.在 Work with中…...

基于Java+MySQL实现(GUI)客户管理系统

客户资料管理系统的设计与实现 第一章 需求分析 1.1 需求总体介绍 本项目为了方便维护客户信息为了方便维护客户信息&#xff0c;对客户进行统一管理&#xff0c;可以把所有客户信息录入系统&#xff0c;进行维护和统计功能。可通过文件的方式保存相关录入数据&#xff0c;对…...

[免费]微信小程序问卷调查系统(SpringBoot后端+Vue管理端)【论文+源码+SQL脚本】

大家好&#xff0c;我是java1234_小锋老师&#xff0c;看到一个不错的微信小程序问卷调查系统(SpringBoot后端Vue管理端)【论文源码SQL脚本】&#xff0c;分享下哈。 项目视频演示 【免费】微信小程序问卷调查系统(SpringBoot后端Vue管理端) Java毕业设计_哔哩哔哩_bilibili 项…...

TSN交换机正在重构工业网络,PROFINET和EtherCAT会被取代吗?

在工业自动化持续演进的今天&#xff0c;通信网络的角色正变得愈发关键。 2025年6月6日&#xff0c;为期三天的华南国际工业博览会在深圳国际会展中心&#xff08;宝安&#xff09;圆满落幕。作为国内工业通信领域的技术型企业&#xff0c;光路科技&#xff08;Fiberroad&…...

【LeetCode】算法详解#6 ---除自身以外数组的乘积

1.题目介绍 给定一个整数数组 nums&#xff0c;返回 数组 answer &#xff0c;其中 answer[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积 。 题目数据 保证 数组 nums之中任意元素的全部前缀元素和后缀的乘积都在 32 位 整数范围内。 请 不要使用除法&#xff0c;且在 O…...