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

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

二、自动化测试

        使用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 {
}

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

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

相关文章

华为数通方向HCIP-DataCom H12-821题库(单选题:301-320)

第301题 某台路由器运行 IS-IS,其输出信息如图所示,下列说法错误的是? [R1]display isis sdb local verboseDatabase information for ISIS(1) Level-1 Link State Database LSPID Seq Num Checksum Holdtime…

Linux —— 信号阻塞

目录 一&#xff0c;信号内核表示 sigset_t sigprocmask sigpending 二&#xff0c;捕捉信号 sigaction 三&#xff0c;可重入函数 四&#xff0c;volatile 五&#xff0c;SIGCHLD 信号常见概念 实际执行信号的处理动作&#xff0c;称为信号递达Delivery&#xff1b;信…

深眸科技自研轻辙视觉引擎,以AI机器视觉赋能杆号牌识别与分拣

电线杆号牌作为电力行业标识的一种&#xff0c;相当于电线杆的“身份证”&#xff0c;担负着宣传电力知识、安全警示的作用&#xff0c;用于户外使用标记输电线路电压等级、线路名称、杆塔编号等&#xff0c;能够清晰地记录电力线路杆的信息&#xff0c;并为电力线路的更改以及…

面试问题总结(1)

(꒪ꇴ꒪ )&#xff0c;Hello我是祐言QAQ我的博客主页&#xff1a;C/C语言&#xff0c;数据结构&#xff0c;Linux基础&#xff0c;ARM开发板&#xff0c;网络编程等领域UP&#x1f30d;快上&#x1f698;&#xff0c;一起学习&#xff0c;让我们成为一个强大的攻城狮&#xff0…

Matlab 如何计算正弦信号的幅值和初始相角

Matlab 如何计算正弦信号的幅值和初始相角 1、概述 如果已知一个正弦信号的幅值&#xff0c;在FFT后频域上该信号谱线的幅值与设置值不同&#xff0c;而是大了许多&#xff1b;如果不知道某一正弦信号的幅値&#xff0c;又如何通FFT后在頻域上求出该正弦信号的幅值呢? 2、…

Python 交易指南:利用 RSI

一、说明 RSI是相对强弱指数&#xff08;Relative Strength Index&#xff09;的缩写&#xff0c;是一种技术指标。该指标是用来测量股票或其他交易品种的价格波动强度和速度的&#xff0c;属于动量型指标。RSI常用于技术分析和交易策略中&#xff0c;可以帮助交易者判断市场的…

C语言:三子棋小游戏

简介&#xff1a; 目标很简单&#xff1a;实现一个 三子棋小游戏。三子棋大家都玩过&#xff0c;规则就不提及了。本博文中实现的三子棋在对局中&#xff0c;电脑落子是随机的&#xff0c;不具有智能性&#xff0c;玩家的落子位置使用键盘输入坐标。下面开始详细介绍如何实现一…

QT实战之翻金币游戏【未完待续】

文章目录 目录 文章目录 前言 二、创建项目 三、添加资源 四、主界面实现 1、设置游戏主场景配置 2、设置背景图片 3、创建开始按钮 总结 前言 对QT的相关知识与控件进行简单的学习之后&#xff0c;通过实现“翻金币游戏”来巩固与实践所学的QT知识。在制作过程中是根据以下视…

PHP8数组的类型-PHP8知识详解

php 8 引入了对数组的类型提示&#xff0c;以帮助开发者更准确地定义和验证数组的结构。以下是 PHP 8 中支持的数组类型&#xff1a;索引数组、关联数组、混合类型数组。 1、索引数组 (Indexed arrays): PHP索引数组一般表示数组元素在数组中的位置&#xff0c;它由数字组成&a…

飞行动力学 - 第18节-part2-航向操纵面 之 基础点摘要

飞行动力学 - 第18节-part2-航向操纵面 之 基础点摘要 1. 航向操纵面2. 非常规航向操纵面3. 正方向舵偏角产生的偏航力矩4. 产生或平衡侧滑角 β \beta β所需的方向舵偏角5. 参考资料 1. 航向操纵面 方向舵是航向的主要操纵面。 2. 非常规航向操纵面 开裂式阻力方向舵 ( Spl…

el-table操作列动态自适应设置(根据操作项个数动态设置宽度)

一、目的 目的&#xff1a;表格操作列宽度&#xff0c;根据操作项多少&#xff0c;自动调节宽度背景&#xff1a;用el-table组件开发时&#xff0c;对于表格的操作列的自适应宽度是一个问题&#xff0c;如果不设置&#xff0c;操作按钮多时会有换行问题。如果设置最小宽度或宽…

跟踪源码技巧+阅读源码工具Sourcetrail

基于Eclipse IDE 1、Quick Type Hierarchy 快速查看类继承体系 &#xff08; 快捷键&#xff1a;Ctrl T&#xff09; 查看类很多人可能都知道&#xff0c;可源码阅读的时候更多用来查看方法体系更重要&#xff0c;可以方便快速的定位到方法的实现类。如&#xff1a; 此时如…

使用docker搭建owncloud Harbor 构建镜像

1、使用mysql:5.6和 owncloud 镜像&#xff0c;构建一个个人网盘。 2、安装搭建私有仓库 Harbor 3、编写Dockerfile制作Web应用系统nginx镜像&#xff0c;生成镜像nginx:v1.1&#xff0c;并推送其到私有仓库。具体要求如下&#xff1a; &#xff08;1&#xff09;基于centos基础…

SpringSecurity学习

1.认证 密码校验用户 密码加密存储 Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter {Beanpublic PasswordEncoder passwordEncoder(){return new BCryptPasswordEncoder();}} 我们没有以上代码配置&#xff0c;默认明文存储, {id}password…

解决eNSP和HCL Cloud兼容性的问题

问题&#xff1a;eNSP或HCL无法启动 不兼容的原因&#xff1a;eNSP支持Virtual Box是5.2.44&#xff1b;HCL支持的Virtual Box版本是6.0.14 解决方案&#xff1a;注册表欺骗 再进行重新安装前先把之前的都卸载掉&#xff1a;eNSP、VirtualBox、HCL等 1、先安装Virtual Box 5.…

23个react常见问题

1、setState 是异步还是同步&#xff1f; 合成事件中是异步 钩子函数中的是异步 原生事件中是同步 setTimeout中是同步 相关链接&#xff1a;你真的理解setState吗&#xff1f;&#xff1a; 2、聊聊 react16.4 的生命周期 图片 相关连接&#xff1a;React 生命周期 我对 Reac…

【数据结构】栈---C语言版(详解!!!)

文章目录 &#x1f438;一、栈的概念及结构&#x1f344;1、栈的概念定义&#x1f344;2、动图演示&#x1f332;入栈&#x1f332;出栈&#x1f332;整体过程 &#x1f438;二、栈的实现&#x1f438;三、数组结构栈详解&#x1f34e;创建栈的结构⭕接口1&#xff1a;定义结构…

【uniapp/uview】u-datetime-picker 选择器的过滤器用法

引入&#xff1a;要求日期选择的下拉框在分钟显示时&#xff0c;只显示 0 和 30 分钟&#xff1b; <u-datetime-picker :show"dateShow" :filter"timeFilter" confirm"selDateConfirm" cancel"dateCancel" v-model"value1&qu…

yolov5运行过程遇到的小问题(随时更新)

1.关于git的问题 解决办法&#xff1a;插入下面代码 import os os.environ["GIT_PYTHON_REFRESH"] "quiet"2.页面太小无法完成操作 解决办法: 如果不好使再考虑降低Batch_Size大小或者调整虚拟内存可用硬盘空间大小&#xff01;&#xff08;调整虚拟内存…

实现无公网IP的公网环境下Windows远程桌面Ubuntu 18.04连接,高效远程办公!

文章目录 一、 同个局域网内远程桌面Ubuntu1. 更新软件仓库2. 安装支持包3. 安装XFCE4桌面环境4. 安装XRDP5. 环境设置5.1 XFCE桌面配置5.2 在配置文件中&#xff0c;加入XFCE会话 6 重启服务7. 查看IP地址8. 使用Windows远程桌面连接 二、公网环境系统远程桌面Ubuntu1. 注册cp…