个人博客系统-测试用例+自动化测试
一、个人博客系统测试用例
二、自动化测试
使用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单元测试框架,来进行简单的自动化测试。 1. 准备工作 (1)引入依赖,此时的pom.xml文件: <?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函数 返回值:文件指针(FILE*)参数:文件名(包括文件路径&#…...

【C++基础】实现日期类
👻内容专栏: C/C编程 🐨本文概括: C实现日期类。 🐼本文作者: 阿四啊 🐸发布时间:2023.9.7 对于类的成员函数的声明和定义,我们在类和对象上讲到过,需要进行…...
C语言程序设计—通讯录实现
本篇文章主要是实现一个简易的通讯录: 功能如下: 添加用户修改用户删除用户查找用户(可重名)按名字或年龄排序显示用户保存通讯录日志追加 有如下知识点: 动态数组结构体枚举自定义标识符和宏文件打开与存储函数指针…...

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

B-Tree 索引和 Hash 索引的对比
分析&回答 B-Tree 索引的特点 B-tree 索引可以用于使用 , >, >, <, < 或者 BETWEEN 运算符的列比较。如果 LIKE 的参数是一个没有以通配符起始的常量字符串的话也可以使用这种索引。 有时,即使有索引可以使用,MySQL 也不使用任何索引。…...
入门Python编程:了解计算机语言、Python介绍和开发环境搭建
文章目录 Python入门什么是计算机语言1. 机器语言2. 符号语言(汇编)3. 高级语言 编译型语言和解释型语言1. 编译型语言2. 解释型语言 Python的介绍Python开发环境搭建Python的交互界面 python学习专栏python基础知识(0基础入门)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之后新增的一种特性---扩展方法。通过这个属性可以让程序员在现有的类型上添加扩展方法(无需创建新的派生类型、重新编译或者以其他方式修改原始类型)。 扩展方法是一种特殊的静态方法,虽然是静态方法&a…...
uniapp 高度铺满全屏
问题:在有uni-tabbar的情况下,页面铺满剩下的部分 <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实战核心技术第一篇
目录 四 . 基础架构:一条SQl查询语句是如何执行的? 4.1 MySQL逻辑架构图: 4.2 MySQL的Server层和存储引擎层 4.2.1 连接器 4.2.1.1 解释 4.2.1.2 MySQL 异常重启 解决方案: 4.2.1.2.1. 定期断开长连接: 4.2.1.2.2. 初始…...
hivesql执行过程
语法解析 SemanticAnalyzer SemanticAnalyzer是Hive中的语义分析器,负责检查Hive SQL程序的语义是否正确。SemanticAnalyzer会对Hive SQL程序进行以下检查: 检查过程 语法检查 SemanticAnalyzer会检查Hive SQL程序的语法是否正确,包括关…...
C语言学习:8、深入数据类型
数据超过类型规定的大小怎么办 C语言中,如果需要用的整数大于int类型的最大值了怎么办? 我们知道int能表示的最大数是2147483647,最小的数是-2147483648,为什么? 因为字32位系统中,寄存器是32位的&#…...

生成树协议 STP(spanning-tree protocol)
一、STP作用 1、消除环路:通过阻断冗余链路来消除网络中可能存在的环路。 2、链路备份:当活动路径发生故障时,激活备份链路,及时恢复网络连通性。 二、STP选举机制 1、目的:找到阻塞的端口 2、STP交换机的角色&am…...
【LeetCode】312.戳气球
题目 有 n 个气球,编号为0 到 n - 1,每个气球上都标有一个数字,这些数字存在数组 nums 中。 现在要求你戳破所有的气球。戳破第 i 个气球,你可以获得 nums[i - 1] * nums[i] * nums[i 1] 枚硬币。 这里的 i - 1 和 i 1 代表和…...
商业数据分析概论
🐳 我正在和鲸社区参加“商业数据分析训练营活动” https://www.heywhale.com/home/competition/6487de6649463ee38dbaf58b ,以下是我的学习笔记: 学习主题:波士顿房价数据快速查看 日期: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题目描述回溯算法贪心算法 总结 前置知识 参考前文 参考文章: LeetCode刷题笔记【23】…...
游戏出现卡顿有哪些因素
一、服务器CPU内存占用过大会导致卡顿,升级CPU内存或者优化自身程序占用都可以解决。 二、带宽跑满导致卡,可以升级带宽解决。 二、平常不卡,有大型的活动的时候会卡,这方面主要是服务器性能方面不够导致的,性能常说…...
基于算法竞赛的c++编程(28)结构体的进阶应用
结构体的嵌套与复杂数据组织 在C中,结构体可以嵌套使用,形成更复杂的数据结构。例如,可以通过嵌套结构体描述多层级数据关系: struct Address {string city;string street;int zipCode; };struct Employee {string name;int id;…...
uni-app学习笔记二十二---使用vite.config.js全局导入常用依赖
在前面的练习中,每个页面需要使用ref,onShow等生命周期钩子函数时都需要像下面这样导入 import {onMounted, ref} from "vue" 如果不想每个页面都导入,需要使用node.js命令npm安装unplugin-auto-import npm install unplugin-au…...
测试markdown--肇兴
day1: 1、去程:7:04 --11:32高铁 高铁右转上售票大厅2楼,穿过候车厅下一楼,上大巴车 ¥10/人 **2、到达:**12点多到达寨子,买门票,美团/抖音:¥78人 3、中饭&a…...
渲染学进阶内容——模型
最近在写模组的时候发现渲染器里面离不开模型的定义,在渲染的第二篇文章中简单的讲解了一下关于模型部分的内容,其实不管是方块还是方块实体,都离不开模型的内容 🧱 一、CubeListBuilder 功能解析 CubeListBuilder 是 Minecraft Java 版模型系统的核心构建器,用于动态创…...
五年级数学知识边界总结思考-下册
目录 一、背景二、过程1.观察物体小学五年级下册“观察物体”知识点详解:由来、作用与意义**一、知识点核心内容****二、知识点的由来:从生活实践到数学抽象****三、知识的作用:解决实际问题的工具****四、学习的意义:培养核心素养…...

12.找到字符串中所有字母异位词
🧠 题目解析 题目描述: 给定两个字符串 s 和 p,找出 s 中所有 p 的字母异位词的起始索引。 返回的答案以数组形式表示。 字母异位词定义: 若两个字符串包含的字符种类和出现次数完全相同,顺序无所谓,则互为…...

视频行为标注工具BehaviLabel(源码+使用介绍+Windows.Exe版本)
前言: 最近在做行为检测相关的模型,用的是时空图卷积网络(STGCN),但原有kinetic-400数据集数据质量较低,需要进行细粒度的标注,同时粗略搜了下已有开源工具基本都集中于图像分割这块,…...

NXP S32K146 T-Box 携手 SD NAND(贴片式TF卡):驱动汽车智能革新的黄金组合
在汽车智能化的汹涌浪潮中,车辆不再仅仅是传统的交通工具,而是逐步演变为高度智能的移动终端。这一转变的核心支撑,来自于车内关键技术的深度融合与协同创新。车载远程信息处理盒(T-Box)方案:NXP S32K146 与…...
CRMEB 中 PHP 短信扩展开发:涵盖一号通、阿里云、腾讯云、创蓝
目前已有一号通短信、阿里云短信、腾讯云短信扩展 扩展入口文件 文件目录 crmeb\services\sms\Sms.php 默认驱动类型为:一号通 namespace crmeb\services\sms;use crmeb\basic\BaseManager; use crmeb\services\AccessTokenServeService; use crmeb\services\sms\…...

C++ 设计模式 《小明的奶茶加料风波》
👨🎓 模式名称:装饰器模式(Decorator Pattern) 👦 小明最近上线了校园奶茶配送功能,业务火爆,大家都在加料: 有的同学要加波霸 🟤,有的要加椰果…...