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

如何建立小企业网站杭州seo渠道排名

如何建立小企业网站,杭州seo渠道排名,设计网站案例网站,商城属于电商网站吗目录 前言: 1.博客前端页面测试用例图 2.测试用例的代码实现 2.1登录页面的测试 2.2博客列表页面的测试 2.3写博客测试 2.4博客详情页面的测试 2.5已发布博客的标题和时间的测试 2.6注销用户的测试 结束语: 前言: 之前小编给大家讲…

目录

前言:

1.博客前端页面测试用例图

2.测试用例的代码实现

2.1登录页面的测试

2.2博客列表页面的测试

2.3写博客测试

2.4博客详情页面的测试

2.5已发布博客的标题和时间的测试

2.6注销用户的测试

结束语:


前言:

之前小编给大家讲解了有关于Selenium和Junit5自动化测试的一些基础知识,那么下面我们就针对于我们自己做的一个项目来使用Junit来进行一下自动化测试。

博客项目的前后端博客链接:前端☞http://t.csdn.cn/jZkQd  后端☞http://t.csdn.cn/sN1Uq

博客项目的源码Gitee链接☞https://gitee.com/YAUGAOLELE/project

1.博客前端页面测试用例图

2.测试用例的代码实现

代码侧边的展示:

我们一共创建两个类一个是BlogCase另一个是InitAndEnd。具体代码的创建请看下边。

初始化代码的实现:

package BlogTest;import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;//用来放置初始化的操作以及最后的收尾工作
public class InitAndEnd {//创建驱动static WebDriver webDriver;//初识化操作,打开浏览器@BeforeAllstatic void SetUp() {webDriver = new ChromeDriver();}//关闭浏览器@AfterAllstatic void TearDown() {webDriver.quit();}
}

2.1登录页面的测试

代码展示:

package BlogTest;import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.By;import java.util.concurrent.TimeUnit;@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BlogCase extends InitAndEnd{/*** 输入正确的账号,密码,登录成功*/@Order(1)@ParameterizedTest@CsvFileSource(resources = "LoginSuccess.csv")void LoginSuccess(String username, String password, String blog_list_url){System.out.println(username + password + blog_list_url);//打开博客登录页面webDriver.get("http://43.138.29.216:8080/blog_system/login.html");webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//输入账号:zhangsan /lisiwebDriver.findElement(By.cssSelector("#username")).sendKeys(username);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//输入密码:123webDriver.findElement(By.cssSelector("#password")).sendKeys(password);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//点击提交按钮webDriver.findElement(By.cssSelector("#submit")).click();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//跳转到列表页//获取到当前页面的urlString cur_url = webDriver.getCurrentUrl();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//如果url=http://43.138.29.216:8080/blog_system/blog_list.html,测试通过,否则测试不通过Assertions.assertEquals(blog_list_url,cur_url);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//列表页展示的是zhangsan/lisi//用户名是zhangsan测试通过,否则测试不通过String cur_admin = webDriver.findElement(By.cssSelector("body > div.container > div.container-left > div > h3")).getText();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);Assertions.assertEquals(username,cur_admin);}
}


结果展示:

2.2博客列表页面的测试

代码展示:

package BlogTest;import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.By;import java.util.concurrent.TimeUnit;@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BlogCase extends InitAndEnd{/*** 输入正确的账号,密码,登录成功*/@Order(1)@ParameterizedTest@CsvFileSource(resources = "LoginSuccess.csv")void LoginSuccess(String username, String password, String blog_list_url){System.out.println(username + password + blog_list_url);//打开博客登录页面webDriver.get("http://43.138.29.216:8080/blog_system/login.html");webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//输入账号:zhangsan /lisiwebDriver.findElement(By.cssSelector("#username")).sendKeys(username);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//输入密码:123webDriver.findElement(By.cssSelector("#password")).sendKeys(password);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//点击提交按钮webDriver.findElement(By.cssSelector("#submit")).click();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//跳转到列表页//获取到当前页面的urlString cur_url = webDriver.getCurrentUrl();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//如果url=http://43.138.29.216:8080/blog_system/blog_list.html,测试通过,否则测试不通过Assertions.assertEquals(blog_list_url,cur_url);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//列表页展示的是zhangsan/lisi//用户名是zhangsan测试通过,否则测试不通过String cur_admin = webDriver.findElement(By.cssSelector("body > div.container > div.container-left > div > h3")).getText();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);Assertions.assertEquals(username,cur_admin);}/***博客列表页面的博客数量不为0*/@Order(2)@Testvoid BlogList() {//打开博客列表页webDriver.get("http://43.138.29.216:8080/blog_system/blog_list.html");//获取页面上的所有博客标题对应的元素,如果这个元素的数量不为0,则认为测试通过//加上只能等待,如果不加的话可能前端页面没有渲染出来,就可能导致获取元素失败webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);int title_num = webDriver.findElements(By.cssSelector(".title")).size();//断言:如果这个元素的数量不为0,则认为测试通过Assertions.assertNotEquals(0,title_num);}
}


结果展示:

2.3写博客测试

代码展示:

package BlogTest;import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;import java.util.concurrent.TimeUnit;import static java.lang.Thread.sleep;@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BlogCase extends InitAndEnd{/*** 输入正确的账号,密码,登录成功*/@Order(1)@ParameterizedTest@CsvFileSource(resources = "LoginSuccess.csv")void LoginSuccess(String username, String password, String blog_list_url){System.out.println(username + password + blog_list_url);//打开博客登录页面webDriver.get("http://43.138.29.216:8080/blog_system/login.html");webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//输入账号:zhangsan /lisiwebDriver.findElement(By.cssSelector("#username")).sendKeys(username);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//输入密码:123webDriver.findElement(By.cssSelector("#password")).sendKeys(password);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//点击提交按钮webDriver.findElement(By.cssSelector("#submit")).click();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//跳转到列表页//获取到当前页面的urlString cur_url = webDriver.getCurrentUrl();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//如果url=http://43.138.29.216:8080/blog_system/blog_list.html,测试通过,否则测试不通过Assertions.assertEquals(blog_list_url,cur_url);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//列表页展示的是zhangsan/lisi//用户名是zhangsan测试通过,否则测试不通过String cur_admin = webDriver.findElement(By.cssSelector("body > div.container > div.container-left > div > h3")).getText();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);Assertions.assertEquals(username,cur_admin);}/***博客列表页面的博客数量不为0*/@Order(2)@Testvoid BlogList() {//打开博客列表页webDriver.get("http://43.138.29.216:8080/blog_system/blog_list.html");//获取页面上的所有博客标题对应的元素,如果这个元素的数量不为0,则认为测试通过//加上只能等待,如果不加的话可能前端页面没有渲染出来,就可能导致获取元素失败webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);int title_num = webDriver.findElements(By.cssSelector(".title")).size();//断言:如果这个元素的数量不为0,则认为测试通过Assertions.assertNotEquals(0,title_num);}/*** 写博客*/@Order(3)@Testvoid EditBlog() throws InterruptedException {//找到写博客按钮,点击webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)")).click();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//找到对应的输入框,输入对应的标题。webDriver.findElement(By.cssSelector("#title-input"));//通过JS进行标题输入webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"title-input\").value=\"自动化测试\"");sleep(3000);//点击提交webDriver.findElement(By.cssSelector("#submit")).click();sleep(3000);//校验//获取当前页面的urlString cur_url = webDriver.getCurrentUrl();Assertions.assertEquals("http://43.138.29.216:8080/blog_system/blog_list.html",cur_url);}
}


结果展示:

2.4博客详情页面的测试

代码展示:

package BlogTest;import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;import static java.lang.Thread.sleep;@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BlogCase extends InitAndEnd{private static Stream<Arguments> Generator() {return Stream.of(Arguments.arguments("http://43.138.29.216:8080/blog_system/blog_detail.html","博客详情页","自动化测试"));}/*** 输入正确的账号,密码,登录成功*/@Order(1)@ParameterizedTest@CsvFileSource(resources = "LoginSuccess.csv")void LoginSuccess(String username, String password, String blog_list_url){System.out.println(username + password + blog_list_url);//打开博客登录页面webDriver.get("http://43.138.29.216:8080/blog_system/login.html");webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//输入账号:zhangsan /lisiwebDriver.findElement(By.cssSelector("#username")).sendKeys(username);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//输入密码:123webDriver.findElement(By.cssSelector("#password")).sendKeys(password);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//点击提交按钮webDriver.findElement(By.cssSelector("#submit")).click();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//跳转到列表页//获取到当前页面的urlString cur_url = webDriver.getCurrentUrl();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//如果url=http://43.138.29.216:8080/blog_system/blog_list.html,测试通过,否则测试不通过Assertions.assertEquals(blog_list_url,cur_url);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//列表页展示的是zhangsan/lisi//用户名是zhangsan测试通过,否则测试不通过String cur_admin = webDriver.findElement(By.cssSelector("body > div.container > div.container-left > div > h3")).getText();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);Assertions.assertEquals(username,cur_admin);}/***博客列表页面的博客数量不为0*/@Order(2)@Testvoid BlogList() {//打开博客列表页webDriver.get("http://43.138.29.216:8080/blog_system/blog_list.html");//获取页面上的所有博客标题对应的元素,如果这个元素的数量不为0,则认为测试通过//加上只能等待,如果不加的话可能前端页面没有渲染出来,就可能导致获取元素失败webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);int title_num = webDriver.findElements(By.cssSelector(".title")).size();//断言:如果这个元素的数量不为0,则认为测试通过Assertions.assertNotEquals(0,title_num);}/*** 写博客*/@Order(3)@Testvoid EditBlog() throws InterruptedException {//找到写博客按钮,点击webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)")).click();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//找到对应的输入框,输入对应的标题。webDriver.findElement(By.cssSelector("#title-input"));//通过JS进行标题输入webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"title-input\").value=\"自动化测试\"");sleep(3000);//点击提交webDriver.findElement(By.cssSelector("#submit")).click();sleep(3000);//校验//获取当前页面的urlString cur_url = webDriver.getCurrentUrl();Assertions.assertEquals("http://43.138.29.216:8080/blog_system/blog_list.html",cur_url);}/*** 博客详情页面的校验* 1.校验url* 2.校验博客标题* 3.页面title是“博客详情页”的测试*/@Order(4)@ParameterizedTest@MethodSource("Generator")void BlogDetail(String expected_url, String expected_title, String expected_blog_title) {//找到第一篇博客对应查看全文的按钮webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.findElement(By.xpath("/html/body/div[2]/div[2]/div[2]/a")).click();//获取当前页面的urlwebDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);String cur_url = webDriver.getCurrentUrl();//获取当前页面的titlewebDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);String cur_title = webDriver.getTitle();//获取博客标题webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);String cur_blog_title = webDriver.findElement(By.cssSelector("body > div.container > div.container-right > h3")).getText();//校验webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
//        Assertions.assertEquals(expected_url,cur_url);Assertions.assertEquals(expected_title,cur_title);Assertions.assertEquals(expected_blog_title,cur_blog_title);if (cur_url.contains(expected_url)) {System.out.println("测试通过");}else {System.out.println(cur_url);System.out.println("测试不通过");}}
}


结果展示:

2.5已发布博客的标题和时间的测试

代码展示:

package BlogTest;import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;import static java.lang.Thread.sleep;@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BlogCase extends InitAndEnd{private static Stream<Arguments> Generator() {return Stream.of(Arguments.arguments("http://43.138.29.216:8080/blog_system/blog_detail.html","博客详情页","自动化测试"));}/*** 输入正确的账号,密码,登录成功*/@Order(1)@ParameterizedTest@CsvFileSource(resources = "LoginSuccess.csv")void LoginSuccess(String username, String password, String blog_list_url){System.out.println(username + password + blog_list_url);//打开博客登录页面webDriver.get("http://43.138.29.216:8080/blog_system/login.html");webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//输入账号:zhangsan /lisiwebDriver.findElement(By.cssSelector("#username")).sendKeys(username);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//输入密码:123webDriver.findElement(By.cssSelector("#password")).sendKeys(password);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//点击提交按钮webDriver.findElement(By.cssSelector("#submit")).click();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//跳转到列表页//获取到当前页面的urlString cur_url = webDriver.getCurrentUrl();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//如果url=http://43.138.29.216:8080/blog_system/blog_list.html,测试通过,否则测试不通过Assertions.assertEquals(blog_list_url,cur_url);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//列表页展示的是zhangsan/lisi//用户名是zhangsan测试通过,否则测试不通过String cur_admin = webDriver.findElement(By.cssSelector("body > div.container > div.container-left > div > h3")).getText();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);Assertions.assertEquals(username,cur_admin);}/***博客列表页面的博客数量不为0*/@Order(2)@Testvoid BlogList() {//打开博客列表页webDriver.get("http://43.138.29.216:8080/blog_system/blog_list.html");//获取页面上的所有博客标题对应的元素,如果这个元素的数量不为0,则认为测试通过//加上只能等待,如果不加的话可能前端页面没有渲染出来,就可能导致获取元素失败webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);int title_num = webDriver.findElements(By.cssSelector(".title")).size();//断言:如果这个元素的数量不为0,则认为测试通过Assertions.assertNotEquals(0,title_num);}/*** 写博客*/@Order(3)@Testvoid EditBlog() throws InterruptedException {//找到写博客按钮,点击webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)")).click();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//找到对应的输入框,输入对应的标题。webDriver.findElement(By.cssSelector("#title-input"));//通过JS进行标题输入webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"title-input\").value=\"自动化测试\"");sleep(3000);//点击提交webDriver.findElement(By.cssSelector("#submit")).click();sleep(3000);//校验//获取当前页面的urlString cur_url = webDriver.getCurrentUrl();Assertions.assertEquals("http://43.138.29.216:8080/blog_system/blog_list.html",cur_url);}/*** 博客详情页面的校验* 1.校验url* 2.校验博客标题* 3.页面title是“博客详情页”的测试*/@Order(4)@ParameterizedTest@MethodSource("Generator")void BlogDetail(String expected_url, String expected_title, String expected_blog_title) {//找到第一篇博客对应查看全文的按钮webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.findElement(By.xpath("/html/body/div[2]/div[2]/div[2]/a")).click();//获取当前页面的urlwebDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);String cur_url = webDriver.getCurrentUrl();//获取当前页面的titlewebDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);String cur_title = webDriver.getTitle();//获取博客标题webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);String cur_blog_title = webDriver.findElement(By.cssSelector("body > div.container > div.container-right > h3")).getText();//校验webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
//        Assertions.assertEquals(expected_url,cur_url);Assertions.assertEquals(expected_title,cur_title);Assertions.assertEquals(expected_blog_title,cur_blog_title);if (cur_url.contains(expected_url)) {System.out.println("测试通过");}else {System.out.println(cur_url);System.out.println("测试不通过");}}@Order(5)@Test/*** 校验已发布博客的标题* 校验已发布博客时间*/void BlogInfoChecked() {webDriver.get("http://43.138.29.216:8080/blog_system/blog_list.html");//获取第一篇博客的标题String first_blog_title = webDriver.findElement(By.cssSelector("body > div.container > div.container-right > div:nth-child(1) > div.title")).getText();//获取第一篇博客的发布时间String first_blog_time = webDriver.findElement(By.xpath("/html/body/div[2]/div[2]/div[1]/div[2]")).getText();//校验博客标题是不是自动化测试Assertions.assertEquals("自动化测试",first_blog_title);//如果是2023-09-03发布的,测试通过if (first_blog_time.contains("2023-09-03")) {System.out.println("测试通过");}else {System.out.println("当前时间是:" + first_blog_time);System.out.println("测试不通过");}}}


结果展示: 

2.6注销用户的测试

代码展示:

package BlogTest;import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;import static java.lang.Thread.sleep;@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BlogCase extends InitAndEnd{private static Stream<Arguments> Generator() {return Stream.of(Arguments.arguments("http://43.138.29.216:8080/blog_system/blog_detail.html","博客详情页","自动化测试"));}/*** 输入正确的账号,密码,登录成功*/@Order(1)@ParameterizedTest@CsvFileSource(resources = "LoginSuccess.csv")void LoginSuccess(String username, String password, String blog_list_url){System.out.println(username + password + blog_list_url);//打开博客登录页面webDriver.get("http://43.138.29.216:8080/blog_system/login.html");webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//输入账号:zhangsan /lisiwebDriver.findElement(By.cssSelector("#username")).sendKeys(username);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//输入密码:123webDriver.findElement(By.cssSelector("#password")).sendKeys(password);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//点击提交按钮webDriver.findElement(By.cssSelector("#submit")).click();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//跳转到列表页//获取到当前页面的urlString cur_url = webDriver.getCurrentUrl();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//如果url=http://43.138.29.216:8080/blog_system/blog_list.html,测试通过,否则测试不通过Assertions.assertEquals(blog_list_url,cur_url);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//列表页展示的是zhangsan/lisi//用户名是zhangsan测试通过,否则测试不通过String cur_admin = webDriver.findElement(By.cssSelector("body > div.container > div.container-left > div > h3")).getText();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);Assertions.assertEquals(username,cur_admin);}/***博客列表页面的博客数量不为0*/@Order(2)@Testvoid BlogList() {//打开博客列表页webDriver.get("http://43.138.29.216:8080/blog_system/blog_list.html");//获取页面上的所有博客标题对应的元素,如果这个元素的数量不为0,则认为测试通过//加上只能等待,如果不加的话可能前端页面没有渲染出来,就可能导致获取元素失败webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);int title_num = webDriver.findElements(By.cssSelector(".title")).size();//断言:如果这个元素的数量不为0,则认为测试通过Assertions.assertNotEquals(0,title_num);}/*** 写博客*/@Order(3)@Testvoid EditBlog() throws InterruptedException {//找到写博客按钮,点击webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)")).click();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//找到对应的输入框,输入对应的标题。webDriver.findElement(By.cssSelector("#title-input"));//通过JS进行标题输入webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);((JavascriptExecutor)webDriver).executeScript("document.getElementById(\"title-input\").value=\"自动化测试\"");sleep(3000);//点击提交webDriver.findElement(By.cssSelector("#submit")).click();sleep(3000);//校验//获取当前页面的urlString cur_url = webDriver.getCurrentUrl();Assertions.assertEquals("http://43.138.29.216:8080/blog_system/blog_list.html",cur_url);}/*** 博客详情页面的校验* 1.校验url* 2.校验博客标题* 3.页面title是“博客详情页”的测试*/@Order(4)@ParameterizedTest@MethodSource("Generator")void BlogDetail(String expected_url, String expected_title, String expected_blog_title) {//找到第一篇博客对应查看全文的按钮webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.findElement(By.xpath("/html/body/div[2]/div[2]/div[2]/a")).click();//获取当前页面的urlwebDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);String cur_url = webDriver.getCurrentUrl();//获取当前页面的titlewebDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);String cur_title = webDriver.getTitle();//获取博客标题webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);String cur_blog_title = webDriver.findElement(By.cssSelector("body > div.container > div.container-right > h3")).getText();//校验webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
//        Assertions.assertEquals(expected_url,cur_url);Assertions.assertEquals(expected_title,cur_title);Assertions.assertEquals(expected_blog_title,cur_blog_title);if (cur_url.contains(expected_url)) {System.out.println("测试通过");}else {System.out.println(cur_url);System.out.println("测试不通过");}}@Order(5)@Test/*** 校验已发布博客的标题* 校验已发布博客时间*/void BlogInfoChecked() {webDriver.get("http://43.138.29.216:8080/blog_system/blog_list.html");//获取第一篇博客的标题String first_blog_title = webDriver.findElement(By.cssSelector("body > div.container > div.container-right > div:nth-child(1) > div.title")).getText();//获取第一篇博客的发布时间String first_blog_time = webDriver.findElement(By.xpath("/html/body/div[2]/div[2]/div[1]/div[2]")).getText();//校验博客标题是不是自动化测试Assertions.assertEquals("自动化测试",first_blog_title);//如果是2023-09-03发布的,测试通过if (first_blog_time.contains("2023-09-03")) {System.out.println("测试通过");}else {System.out.println("当前时间是:" + first_blog_time);System.out.println("测试不通过");}}/*** 注销*/@Order(6)@Testvoid Logout() {webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)")).click();//校验url(登录)webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);String cur_url = webDriver.getCurrentUrl();Assertions.assertEquals("http://43.138.29.216:8080/blog_system/login.html",cur_url);//校验提交按钮webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);WebElement webElement = webDriver.findElement(By.cssSelector("#submit"));webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);Assertions.assertNotNull(webElement);}
}


结果展示:

结束语:

好了这节小编就给大分享到这里啦,希望这节对大家有关于使用Junit5的自动化测试有一定帮助,想要学习的同学记得关注小编和小编一起学习吧!如果文章中有任何错误也欢迎各位大佬及时为小编指点迷津(在此小编先谢过各位大佬啦!)


文章转载自:
http://micelle.tyjp.cn
http://uncomprehended.tyjp.cn
http://conundrum.tyjp.cn
http://irrelievable.tyjp.cn
http://fossick.tyjp.cn
http://jis.tyjp.cn
http://distillage.tyjp.cn
http://triphibian.tyjp.cn
http://dispend.tyjp.cn
http://hurtfully.tyjp.cn
http://trabeate.tyjp.cn
http://fragmentized.tyjp.cn
http://rubiaceous.tyjp.cn
http://authoritative.tyjp.cn
http://semibarbarism.tyjp.cn
http://scantily.tyjp.cn
http://restrained.tyjp.cn
http://anadama.tyjp.cn
http://rheda.tyjp.cn
http://squabby.tyjp.cn
http://wilhelmshaven.tyjp.cn
http://piecework.tyjp.cn
http://bi.tyjp.cn
http://indent.tyjp.cn
http://such.tyjp.cn
http://extenuate.tyjp.cn
http://linin.tyjp.cn
http://boredom.tyjp.cn
http://auxochrome.tyjp.cn
http://fulgurite.tyjp.cn
http://routinism.tyjp.cn
http://pakeha.tyjp.cn
http://diaphysis.tyjp.cn
http://earthshock.tyjp.cn
http://serotinous.tyjp.cn
http://airlift.tyjp.cn
http://briquet.tyjp.cn
http://quadruped.tyjp.cn
http://tuitionary.tyjp.cn
http://trotline.tyjp.cn
http://expurgation.tyjp.cn
http://evergreen.tyjp.cn
http://barbed.tyjp.cn
http://signatory.tyjp.cn
http://heavyset.tyjp.cn
http://aerodontia.tyjp.cn
http://passionist.tyjp.cn
http://cytodifferentiation.tyjp.cn
http://desexualize.tyjp.cn
http://banbury.tyjp.cn
http://karnaugh.tyjp.cn
http://billet.tyjp.cn
http://appendiceal.tyjp.cn
http://hematuresis.tyjp.cn
http://oxyuriasis.tyjp.cn
http://arabella.tyjp.cn
http://acetazolamide.tyjp.cn
http://caesious.tyjp.cn
http://abelmosk.tyjp.cn
http://taratantara.tyjp.cn
http://foveole.tyjp.cn
http://galenical.tyjp.cn
http://skirt.tyjp.cn
http://oct.tyjp.cn
http://degressive.tyjp.cn
http://sexipolar.tyjp.cn
http://urogenital.tyjp.cn
http://makebate.tyjp.cn
http://batt.tyjp.cn
http://pithiness.tyjp.cn
http://sweatproof.tyjp.cn
http://rubensesque.tyjp.cn
http://aeroacoustics.tyjp.cn
http://solifluxion.tyjp.cn
http://elhi.tyjp.cn
http://playfully.tyjp.cn
http://ssg.tyjp.cn
http://nidus.tyjp.cn
http://footbinding.tyjp.cn
http://cyanometry.tyjp.cn
http://incogitable.tyjp.cn
http://straighten.tyjp.cn
http://effervescent.tyjp.cn
http://betook.tyjp.cn
http://shuba.tyjp.cn
http://leechdom.tyjp.cn
http://digitoplantar.tyjp.cn
http://brahmsian.tyjp.cn
http://box.tyjp.cn
http://quail.tyjp.cn
http://gjetost.tyjp.cn
http://icky.tyjp.cn
http://gesticulatory.tyjp.cn
http://geyser.tyjp.cn
http://greisen.tyjp.cn
http://electropolar.tyjp.cn
http://aubade.tyjp.cn
http://mysost.tyjp.cn
http://thermodiffusion.tyjp.cn
http://apostrophic.tyjp.cn
http://www.dt0577.cn/news/65256.html

相关文章:

  • 学校网站建设网络推广视频
  • 大访问量的网站怎么做优化产品推广软文范文
  • 网站搜索功能怎样做杭州网络优化公司排名
  • 做代刷网站赚钱不公司网站模版
  • 欧美风格外贸网站建设网站流量数据分析
  • 如何建立一个网站及app抖音排名优化
  • 做动漫网站侵权吗友情链接官网
  • 相亲网站用什么做的市场监督管理局官网入口
  • 做网站一定要用到dw怎么网上推广自己的产品
  • 新市区做网站网络营销的基本流程
  • 在网站制作完成后网站建设西安seo网站关键词优化
  • 自己搞个网站个人免费建站系统
  • 新手学习做网站2021年热门关键词
  • 如何选择盐城网站开发青岛seo推广公司
  • 有什么做美食的视频网站辽宁seo推广
  • 贵州整站优化seo平台站长工具是什么
  • 徐州哪有做网站的汕头seo代理商
  • 做网站设计师的原因宁波seo怎么做推广渠道
  • 网上发布信息的网站怎么做做企业网站建设公司哪家好
  • 滨州医学院做计算机作业的网站app拉新
  • 阿里云 做网站 靠谱吗五种网络营销推广方法
  • 独立购物网站建设搜索引擎营销案例有哪些
  • 校园二手交易网站开发链接
  • 深圳做网站(官网)百度快照是啥
  • 关于网站的建设免费产品推广网站
  • 国外网页设计分享网站西安seo优化公司
  • 上海网络平台网站建设网站seo视频
  • 网站备案更改吗长沙营销网站建设
  • 做定制校服的网站李守洪
  • bootstrap导航网站百度新闻头条新闻