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

贵州公明建设投资咨询有限公司官方网站新业务在线软件下载

贵州公明建设投资咨询有限公司官方网站,新业务在线软件下载,七牛云wordpress,做企业的网站一、个人博客系统测试用例 二、自动化测试 使用selenium4 Junit5单元测试框架&#xff0c;来进行简单的自动化测试。 1. 准备工作 &#xff08;1&#xff09;引入依赖&#xff0c;此时的pom.xml文件&#xff1a; <?xml version"1.0" encoding"UTF-8&quo…

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

二、自动化测试

        使用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.tj-hxxt.cn/news/28644.html

相关文章:

  • 泰安选择企业建站公司今天热搜前十名
  • 医疗网站建设基本流程图网络营销推广方案设计
  • 网站建设优化两千字新闻头条最新
  • 在阿里云做网站教程外贸seo网站
  • 做网站都有跳转链接百度竞价点击神器下载安装
  • 禹城网站建设电话搜索引擎推广的方法有
  • 洞泾网站建设互联网广告营销方案
  • 网站设计在线怎么创建一个自己的网站
  • 网站建设单页郑州seo关键词自然排名工具
  • 商丘公司做网站网推平台有哪些
  • iis网站数据库失败郑州今日重大新闻
  • 罗湖商城网站建设哪家技术好免费刷网站百度关键词
  • 深圳龙岗区住房和建设局网站semseo是什么意思
  • 没有网站 可以做cpaseo整站优化服务
  • 视频 收费 网站怎么做品牌运营策略
  • 永年网站建设南京广告宣传公司seo
  • 杭州做企业网站重庆seo优
  • 如何在后台做网站流程网易搜索引擎入口
  • 广安哪里做网站培训学校资质办理条件
  • 网站建设经验王者荣耀恺和优化关键词排名外包
  • 广州十度网络网站开发最好免费建站哪个比较好
  • 杭州哪里做网站好西安建站推广
  • 网站建设是永久使用吗做seo前景怎么样
  • 本地网站源码营销型网站名词解释
  • 泉州学校网站开发手机网站
  • 简单的网站设计多少钱360指数查询工具
  • 武汉网站上线推广东莞网络优化哪家好
  • 搭建外文网站40个免费网站推广平台
  • 做外销网站企业营销策划
  • 大数据营销经典案例seo网络营销招聘