个人博客系统-测试用例+自动化测试
一、个人博客系统测试用例
二、自动化测试
使用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内存或者优化自身程序占用都可以解决。 二、带宽跑满导致卡,可以升级带宽解决。 二、平常不卡,有大型的活动的时候会卡,这方面主要是服务器性能方面不够导致的,性能常说…...
在鸿蒙HarmonyOS 5中实现抖音风格的点赞功能
下面我将详细介绍如何使用HarmonyOS SDK在HarmonyOS 5中实现类似抖音的点赞功能,包括动画效果、数据同步和交互优化。 1. 基础点赞功能实现 1.1 创建数据模型 // VideoModel.ets export class VideoModel {id: string "";title: string ""…...

基于当前项目通过npm包形式暴露公共组件
1.package.sjon文件配置 其中xh-flowable就是暴露出去的npm包名 2.创建tpyes文件夹,并新增内容 3.创建package文件夹...

DIY|Mac 搭建 ESP-IDF 开发环境及编译小智 AI
前一阵子在百度 AI 开发者大会上,看到基于小智 AI DIY 玩具的演示,感觉有点意思,想着自己也来试试。 如果只是想烧录现成的固件,乐鑫官方除了提供了 Windows 版本的 Flash 下载工具 之外,还提供了基于网页版的 ESP LA…...

如何理解 IP 数据报中的 TTL?
目录 前言理解 前言 面试灵魂一问:说说对 IP 数据报中 TTL 的理解?我们都知道,IP 数据报由首部和数据两部分组成,首部又分为两部分:固定部分和可变部分,共占 20 字节,而即将讨论的 TTL 就位于首…...

Android 之 kotlin 语言学习笔记三(Kotlin-Java 互操作)
参考官方文档:https://developer.android.google.cn/kotlin/interop?hlzh-cn 一、Java(供 Kotlin 使用) 1、不得使用硬关键字 不要使用 Kotlin 的任何硬关键字作为方法的名称 或字段。允许使用 Kotlin 的软关键字、修饰符关键字和特殊标识…...

HDFS分布式存储 zookeeper
hadoop介绍 狭义上hadoop是指apache的一款开源软件 用java语言实现开源框架,允许使用简单的变成模型跨计算机对大型集群进行分布式处理(1.海量的数据存储 2.海量数据的计算)Hadoop核心组件 hdfs(分布式文件存储系统)&a…...
Mysql8 忘记密码重置,以及问题解决
1.使用免密登录 找到配置MySQL文件,我的文件路径是/etc/mysql/my.cnf,有的人的是/etc/mysql/mysql.cnf 在里最后加入 skip-grant-tables重启MySQL服务 service mysql restartShutting down MySQL… SUCCESS! Starting MySQL… SUCCESS! 重启成功 2.登…...
腾讯云V3签名
想要接入腾讯云的Api,必然先按其文档计算出所要求的签名。 之前也调用过腾讯云的接口,但总是卡在签名这一步,最后放弃选择SDK,这次终于自己代码实现。 可能腾讯云翻新了接口文档,现在阅读起来,清晰了很多&…...
C++课设:简易日历程序(支持传统节假日 + 二十四节气 + 个人纪念日管理)
名人说:路漫漫其修远兮,吾将上下而求索。—— 屈原《离骚》 创作者:Code_流苏(CSDN)(一个喜欢古诗词和编程的Coder😊) 专栏介绍:《编程项目实战》 目录 一、为什么要开发一个日历程序?1. 深入理解时间算法2. 练习面向对象设计3. 学习数据结构应用二、核心算法深度解析…...

android13 app的触摸问题定位分析流程
一、知识点 一般来说,触摸问题都是app层面出问题,我们可以在ViewRootImpl.java添加log的方式定位;如果是touchableRegion的计算问题,就会相对比较麻烦了,需要通过adb shell dumpsys input > input.log指令,且通过打印堆栈的方式,逐步定位问题,并找到修改方案。 问题…...