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

邯郸网站制作费用国建设文化艺术协会网站

邯郸网站制作费用,国建设文化艺术协会网站,网站开发net,网站打开的速度特别慢的原因前言 本篇使用Selenium3Junit5对个人博客进行自动化测试#xff0c;如有错误#xff0c;请在评论区指正#xff0c;让我们一起交流#xff0c;共同进步#xff01; 文章目录 前言一.web自动化测试用例二.测试准备1.注册界面自动化测试测试过程中遇到的Bug: 2.登录界面自动… 前言 本篇使用Selenium3Junit5对个人博客进行自动化测试如有错误请在评论区指正让我们一起交流共同进步 文章目录 前言一.web自动化测试用例二.测试准备1.注册界面自动化测试测试过程中遇到的Bug: 2.登录界面自动化测试登录测试的过程中的Bug: 3.个人博客管理页自动化测试测试个人博客管理页的Bug 4.博客编辑页自动化测试博客编辑页出现的Bug 5.总博客列表页自动化测试6.测试套件 - RunSuiteTest 三、小结参考代码 总结 本文开始 一.web自动化测试用例 描述针对个人博客项目主要测试五个页面注册页登录页个人博客管理页编辑页总博客列表页对其主要功能注册登录编辑查看删除注销等常用功能进行自动化测试 根据博客系统设计部分手工测试用例 二.测试准备 1.创建Maven项目 2.添加相应的依赖 根据编写的测试用例对每个页面进行测试测试每个页面的主要功能添加公共类 dependencies!--添加selenium依赖--!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --dependencygroupIdorg.seleniumhq.selenium/groupIdartifactIdselenium-java/artifactIdversion3.141.59/version/dependency!--保存屏幕截图的包--!-- https://mvnrepository.com/artifact/commons-io/commons-io --dependencygroupIdcommons-io/groupIdartifactIdcommons-io/artifactIdversion2.11.0/version/dependency!--Junit5--!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api --dependencygroupIdorg.junit.jupiter/groupIdartifactIdjunit-jupiter-api/artifactIdversion5.9.1/version/dependency!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-suite --dependencygroupIdorg.junit.platform/groupIdartifactIdjunit-platform-suite/artifactIdversion1.9.1/version/dependency/dependencies公共管理类 public class AutoTestUtils {//每次测试都需要驱动写一个公共类实现代码复用public static WebDriver webDriver;BeforeAllpublic static void SetUp() {if(webDriver null) {System.setProperty(webdriver.chrome.driver,C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe);webDriver new ChromeDriver();}}AfterAllstatic void TearDown() {webDriver.quit();} }对主要测试重点功能进行自动化测试 1.注册界面自动化测试 注册界面测试 - RegTest 1.获取驱动打开注册界面 2.校验界面是否完整 - 测试是否有注册提交按钮 3.校验注册正常操作 4.校验注册失败操作 5.指定注册测试的顺序保证注册测试的正常 测试过程中遇到的Bug: 获取弹窗内容必须在弹窗还没有关闭的状态执行如果弹窗关闭在去获取弹窗text内容会包No such alert错误在注册过程中如果数据库中注册信息重复了但没有弹窗提示在获取alert()弹窗是也会报No such alert错误 注册测试代码 package webAutoTest.TestClass;import org.junit.jupiter.api.*; 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.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.WebDriverWait; import webAutoTest.common.AutoTestUtils;import java.util.concurrent.TimeUnit; import static java.lang.Thread.sleep;TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class RegTest extends AutoTestUtils {/*** 测试注册页面的完整性* 测试注册页面使用XPath获取元素位置 - 需要使用By.xpath()获取如果使用Css选择器回找不到选择器而报错*/Order(1)Testvoid regPageTest() {//1.打开注册页webDriver.get(http://localhost:8080/reg.html);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//2.校验注册框是否存在String reg_title webDriver.findElement(By.xpath(/html/body/div[2]/div/h3)).getText();Assertions.assertEquals(注册, reg_title);//3.注册提交按钮是否存在webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);WebElement webElement webDriver.findElement(By.xpath(//*[id\submit\]));Assertions.assertNotNull(webElement);}/*** 测试注册正常操作* 数据库中已有注册账号 - 不会有弹窗提示操作报错*/Order(2)ParameterizedTestCsvSource({李四,abc,abc})void regSuccessTest(String username, String password1, String password2) throws InterruptedException { // webDriver.get(http://localhost:8080/reg.html);webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//1.清空之前注册操作webDriver.findElement(By.xpath(//*[id\username\])).clear();webDriver.findElement(By.xpath(//*[id\password\])).clear();webDriver.findElement(By.xpath(//*[id\password2\])).clear();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//2.输入注册账号密码确认密码webDriver.findElement(By.xpath(//*[id\username\])).sendKeys(username);webDriver.findElement(By.xpath(//*[id\password\])).sendKeys(password1);webDriver.findElement(By.xpath(//*[id\password2\])).sendKeys(password2);//3.点击提交按钮提交webDriver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);webDriver.findElement(By.xpath(//*[id\submit\])).click();//4.显示注册成功弹窗确认弹窗sleep(1000); //为了测试看清测试过程也为了让页面不用渲染太快导致找不到弹窗报错Alert alert webDriver.switchTo().alert();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);alert.accept();//5.校验是否注册后跳转到登录页面sleep(500);String currentUrl webDriver.getCurrentUrl();Assertions.assertEquals(http://localhost:8080/login.html,currentUrl);//5.再回退到注册页方便后面的测试webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.navigate().back();}/*** 测试登录失败* param username* param password1* param password2* 获取弹窗内容必须在弹窗还没有关闭的状态执行如果弹窗关闭在去获取弹窗text内容会包No such alert错误*/Order(3)ParameterizedTestCsvSource({老六,123,1234})void regFailTest(String username, String password1, String password2) throws InterruptedException {//1.打开注册页面webDriver.get(http://localhost:8080/reg.html);//2.清空注册框webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.findElement(By.xpath(//*[id\username\])).clear();webDriver.findElement(By.xpath(//*[id\password\])).clear();webDriver.findElement(By.xpath(//*[id\password2\])).clear();//3.输入密码判断输入密码两次是否一样webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.findElement(By.xpath(//*[id\username\])).sendKeys(username);webDriver.findElement(By.xpath(//*[id\password\])).sendKeys(password1);webDriver.findElement(By.xpath(//*[id\password2\])).sendKeys(password2);webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.findElement(By.xpath(//*[id\submit\])).click();//4.出现弹窗提示点击确认Alert alert webDriver.switchTo().alert();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);Assertions.assertEquals(两次密码不一致,alert.getText());String info alert.getText();System.out.println(info);alert.accept();} } 测试结果界面 2.登录界面自动化测试 登录界面自动化测试 - LoginTest 1.获取驱动打开登录界面 2.校验界面是否正常 - 测试是否有登录提交按钮 3.校验正常登录 - 多参数测试多个测试用例 4.校验异常登录 - 错误的密码登录 5.对于多组测试需要情况上次输入的内容 6.使用注解保证测试的顺序 登录测试的过程中的Bug: 设置强制等待不设置页面会因为渲染过快alert弹窗还没有弹出就断言判断页面的url从而造成错误对于多组参数的数据下一组测试前需要清空上一组测试的数据测试登录成功后显示个人列表页面对比成功后页面的url对于多组测试数据需要回退不然会断言错误 package webAutoTest.TestClass;import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvFileSource; import org.junit.jupiter.params.provider.CsvSource; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import webAutoTest.common.AutoTestUtils;import org.openqa.selenium.support.ui.WebDriverWait;import static java.lang.Thread.sleep; import static java.time.Duration.ofSeconds; import java.time.Duration; import java.util.concurrent.TimeUnit;TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class LoginTest extends AutoTestUtils {/*** 测试登录页面是否正常显示*/Order(1)Testvoid loginPageTest() {webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//1.打开登录页面看页面是否正常webDriver.get(http://localhost:8080/login.html);//2.登录标题是否存在webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);String login_title webDriver.findElement(By.cssSelector(body div.login-container div h3)).getText();Assertions.assertEquals(登录,login_title);//3.登录提交按钮是否存在webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);WebElement webElement webDriver.findElement(By.cssSelector(#submit));Assertions.assertNotNull(webElement);}/*** 登录成功* param username* param password* throws InterruptedException*/Order(2)ParameterizedTestCsvSource({张三,123,王五,123})void loginSuccessTest(String username,String password) throws InterruptedException {webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//1.清理之前的账号密码 - 多账户登录webDriver.findElement(By.cssSelector(#username)).clear();webDriver.findElement(By.cssSelector(#password)).clear();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//2.找到输入框输入账号密码webDriver.findElement(By.cssSelector(#username)).sendKeys(username);webDriver.findElement(By.cssSelector(#password)).sendKeys(password);//3.点击提交按钮webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);webDriver.findElement(By.cssSelector(#submit)).click();//4.验证个人列表url看是否登录成功sleep(200);String currentUrl webDriver.getCurrentUrl();Assertions.assertEquals(http://localhost:8080/myblog_list.html,currentUrl);//5.为测试多次登录需要回退到登录页webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);webDriver.navigate().back();}/*** 登录失败* param username* param password* param list_url* throws InterruptedException*/Order(3)DisabledParameterizedTestCsvFileSource(resources LoginFail.csv)void LoginFail(String username, String password, String list_url) throws InterruptedException {//1.打开博客登录页webDriver.get(http://localhost:8080/login.html);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//2.输入账号张三, 密码1234webDriver.findElement(By.cssSelector(#username)).sendKeys(username);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);webDriver.findElement(By.cssSelector(#password)).sendKeys(password);webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//3.点击提交webDriver.findElement(By.cssSelector(#submit)).click();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//4.出现弹窗提示用户或密码错误,点击弹窗确认Alert alert webDriver.switchTo().alert();System.out.println(alert.getText());webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);//设置等待时间过短会报错页面渲染过快弹窗捕捉不到导致错误alert.accept();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//5.确认当前是登录页webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);String currentUrl webDriver.getCurrentUrl();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);Assertions.assertNotEquals(list_url,currentUrl);}} 测试结果 3.个人博客管理页自动化测试 个人文章列表页自动化测试 - BlogListTest 1.处于登录状态 2.校验个人博客管理页是否正常 3.校验查看博客按钮编辑博客按钮删除博客按钮 4.测试未登录状态直接跳转登录页 测试个人博客管理页的Bug 必须在登录状态才能看到个人博客列表 package webAutoTest.TestClass;import org.junit.jupiter.api.*; 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 webAutoTest.common.AutoTestUtils;import java.util.Queue; import java.util.concurrent.TimeUnit; import static java.lang.Thread.sleep;TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class BlogListTest extends AutoTestUtils {/*** 测试个人博客管理页面是否完整*/Order(1)ParameterizedTestCsvSource({张三,123})void blogListPageTest(String username, String password) throws InterruptedException {//1.登录webDriver.get(http://localhost:8080/login.html);webDriver.findElement(By.cssSelector(#username)).clear();webDriver.findElement(By.cssSelector(#password)).clear();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//找到输入框输入账号密码webDriver.findElement(By.cssSelector(#username)).sendKeys(username);webDriver.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);sleep(500);//2.测试个人博客管理页面标题String title webDriver.getTitle();System.out.println(title);Assertions.assertEquals(个人博客列表管理页,title);//3.查看全文按钮修改按钮删除按钮是否正常webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);WebElement check_button webDriver.findElement(By.cssSelector(#artListDiv div:nth-child(1) a:nth-child(4)));WebElement update_button webDriver.findElement(By.cssSelector(#artListDiv div:nth-child(1) a:nth-child(5)));WebElement delete_button webDriver.findElement(By.cssSelector(#artListDiv div:nth-child(1) a:nth-child(6)));Assertions.assertNotNull(check_button);Assertions.assertNotNull(update_button);Assertions.assertNotNull(delete_button);}/*** 测试个人博客管理页的* 查看按钮编辑按钮删除按钮*/Order(2)Testvoid blogListTest() {webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//1.校验查看全文点击按钮进入文章详情页webDriver.findElement(By.cssSelector(#artListDiv div:nth-child(1) a:nth-child(4))).click();//2.校验是否到文章详细页urlString content_url webDriver.getCurrentUrl();String expect_url http://localhost:8080/blog_content.html;if(content_url.contains(expect_url)) {System.out.println(查看按钮测试通过);}else {System.out.println(查看按钮测试不通过);}webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.navigate().back();//2.校验修改文章按钮点击按钮进入编辑页webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.findElement(By.cssSelector(#artListDiv div:nth-child(1) a:nth-child(5))).click();//3.校验是否是编辑页的urlString edit_url webDriver.getCurrentUrl();String expect_url2 http://localhost:8080/blog_edit.html;if(edit_url.contains(expect_url2)) {System.out.println(编辑按钮测试通过);}else {System.out.println(编辑按钮不通过);}webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.navigate().back();//4.校验删除按钮点击按钮删除文章webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.findElement(By.cssSelector(#artListDiv div:nth-child(1) a:nth-child(6))).click();//5.弹窗显示删除成功点击确认webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);Alert alert webDriver.switchTo().alert();System.out.println(alert.getText());alert.accept();//6.校验此时第一篇标题webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);String title_text webDriver.findElement(By.cssSelector(#artListDiv div:nth-child(1) div.title)).getText();Assertions.assertNotEquals(java,title_text);}/*** 测试未登录状态博客管理页*/Disabled // 设置无效不随整体执行作为单个测试样例Testvoid unLoginBlogList() {webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//1.直接进入个人博客管理页webDriver.get(http://localhost:8080/myblog_list.html);//2.弹窗显示登录之后再查看Alert alert webDriver.switchTo().alert();System.out.println(alert.getText());alert.accept();//3.校验是否回到登录页webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);String login_url webDriver.getCurrentUrl();Assertions.assertEquals(http://localhost:8080/login.html,login_url);}} 测试结果 4.博客编辑页自动化测试 博客编辑页自动化测试 - BlogEditTest 1.校验编辑页面的完整性 - 发布按钮是否存在 2.校验发布成功后是否能跳转到个人列表管理页 博客编辑页出现的Bug 获取文章标题使用getText()获取文本可能获取不到获取到空字符串造成断言失败可以使用getTitle(); package webAutoTest.TestClass;import org.junit.jupiter.api.*; 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 webAutoTest.common.AutoTestUtils;import java.util.concurrent.TimeUnit;import static java.lang.Thread.sleep;TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class BlogEditTest extends AutoTestUtils {/*** 测试编辑页的完整性*/Order(1)ParameterizedTestCsvSource(张三,123)void blogEditPageTest(String username, String password) throws InterruptedException {//1.登录webDriver.get(http://localhost:8080/login.html);webDriver.findElement(By.cssSelector(#username)).clear();webDriver.findElement(By.cssSelector(#password)).clear();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//找到输入框输入账号密码webDriver.findElement(By.cssSelector(#username)).sendKeys(username);webDriver.findElement(By.cssSelector(#password)).sendKeys(password);//点击提交按钮webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);webDriver.findElement(By.cssSelector(#submit)).click();sleep(500);//2.点击写博客webDriver.findElement(By.cssSelector(body div.nav a:nth-child(5))).click();//3.当前是否到博客编辑页webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);String edit_url webDriver.getCurrentUrl();Assertions.assertEquals(http://localhost:8080/blog_add.html,edit_url);//4.校验发布文章按钮是否存在WebElement webElement webDriver.findElement(By.cssSelector(body div.blog-edit-container div.title button));Assertions.assertNotNull(webElement);}/*** 测试文章发布发布后是否成功跳转* throws InterruptedException*/Order(2)Testvoid blogEditTest() throws InterruptedException {webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//1.输入标题webDriver.findElement(By.cssSelector(#title)).sendKeys(测试实战2);//2.输入正文 - 第三方插件不能使用sendkeywebDriver.findElement(By.cssSelector(#editorDiv div.CodeMirror.cm-s-default.CodeMirror-wrap div.CodeMirror-scroll)).click();//3.点击发布按钮webDriver.findElement(By.cssSelector(body div.blog-edit-container div.title button)).click();//4.发布成功出现弹窗显示是否继续发布点击取消sleep(500);Alert alert webDriver.switchTo().alert();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);System.out.println(alert.getText());alert.dismiss();//5.校验跳转页面到个人博客列表管理页webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);String currentUrl webDriver.getCurrentUrl();Assertions.assertEquals(http://localhost:8080/myblog_list.html,currentUrl);//6.校验发布的文章的标题String text webDriver.findElement(By.cssSelector(#artListDiv div:nth-child(1) div.title)).getText();Assertions.assertEquals(测试实战2,text);} } 测试结果 5.总博客列表页自动化测试 总博客列表页自动化测试 - TotalBlogListTest 1.校验总博客列表页完整 - 首页上一页下一页末页按钮存在 2.校验在第一页点击首页处理弹窗 3.校验在最后一页点击末页处理弹窗 4.未登录查看总博客列表页功能正常 package webAutoTest.TestClass;import org.junit.jupiter.api.*; 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 webAutoTest.common.AutoTestUtils;import java.util.concurrent.TimeUnit;import static java.lang.Thread.sleep;TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class TotalBlogListTest extends AutoTestUtils {/*** 测试总博客列表页是否正常* 校验首页上一页下一页末页*/Order(1)ParameterizedTestCsvSource({张三,123})void totalPageTest(String username,String password) throws InterruptedException {//1.登录webDriver.get(http://localhost:8080/login.html);webDriver.findElement(By.cssSelector(#username)).clear();webDriver.findElement(By.cssSelector(#password)).clear();webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//找到输入框输入账号密码webDriver.findElement(By.cssSelector(#username)).sendKeys(username);webDriver.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);sleep(200);//2.点击主页webDriver.findElement(By.cssSelector(body div.nav a:nth-child(4))).click();webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);//2.校验总列表页是否正常,校验首页上一页下一页末页WebElement first_button webDriver.findElement(By.cssSelector(body div.container div div.blog-pagnation-wrapper button:nth-child(1)));WebElement prev_page_button webDriver.findElement(By.cssSelector(body div.container div div.blog-pagnation-wrapper button:nth-child(2)));WebElement next_page_button webDriver.findElement(By.cssSelector(body div.container div div.blog-pagnation-wrapper button:nth-child(3)));WebElement last_button webDriver.findElement(By.cssSelector(body div.container div div.blog-pagnation-wrapper button:nth-child(4)));Assertions.assertNotNull(first_button);Assertions.assertNotNull(prev_page_button);Assertions.assertNotNull(next_page_button);Assertions.assertNotNull(last_button);}Order(2)Testvoid totalBlogListTest() throws InterruptedException {//1.点击首页webDriver.findElement(By.cssSelector(body div.container div div.blog-pagnation-wrapper button:nth-child(1))).click();//2.出现弹窗显示已在首页点击确认sleep(200);Alert alert webDriver.switchTo().alert();System.out.println(alert.getText());alert.accept();//3.点击下一页校验urlwebDriver.findElement(By.cssSelector(body div.container div div.blog-pagnation-wrapper button:nth-child(3))).click();String currentUrl webDriver.getCurrentUrl();char intdex currentUrl.charAt(currentUrl.length() - 1);Assertions.assertEquals(2,intdex);//4.点击两次末页校验webDriver.findElement(By.cssSelector(body div.container div div.blog-pagnation-wrapper button:nth-child(4))).click();webDriver.findElement(By.cssSelector(body div.container div div.blog-pagnation-wrapper button:nth-child(4))).click();sleep(200);Alert alert1 webDriver.switchTo().alert();System.out.println(alert1.getText());alert1.accept();//5.点击查看全文可以跳转到文章详情页webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);webDriver.findElement(By.cssSelector(#artListDiv div a)).click();String content_url webDriver.getCurrentUrl();if(content_url.contains(http://localhost:8080/blog_content.html)) {System.out.println(查看文章按钮通过);}else {System.out.println(查看文章按钮失败);}}/*** 未登录查看总博客列表页* throws InterruptedException*/DisabledOrder(3)Testvoid unLoginTotalBlogListTest() {//1.获取总博客列表页webDriver.get(http://localhost:8080/blog_list.html);//2.文章列表中第一篇文章显示正常String content_title webDriver.findElement(By.cssSelector(#artListDiv div:nth-child(1) div.title)).getText();Assertions.assertEquals(测试实战2,content_title);//利用断言验证//3.点击文章可以查看文章详情webDriver.findElement(By.cssSelector(#artListDiv div:nth-child(1) a)).click();String content_url webDriver.getCurrentUrl();//4.校验文章详情页urlif(content_url.contains(http://localhost:8080/blog_content.html)) {System.out.println(查看文章按钮通过);}else {System.out.println(查看文章按钮失败);}} } 测试结果 未登录查看总博客列表页 6.测试套件 - RunSuiteTest 测试套件 - RunSuiteTest 通过套件以测试类运行也可写多个测试类会按照顺序执行 package webAutoTest.TestClass;import org.junit.platform.suite.api.SelectClasses; import org.junit.platform.suite.api.Suite;Suite SelectClasses({LoginTest.class}) public class RunSuiteTest { }测试结果 三、小结 注意 需要注意测试的执行顺序不关注可能报错对于多参数测试需要清空上次输入数据页面回退使用SelectClasses的参数指定执行类的顺序测试用例并不是越多越好覆盖较多功能较好测试功能会有遗漏的情况对于测试用例执行顺序会有错误情况 测试优势 1.使用Junit5单元测试框架中的注释提高测试的稳定性提高自动化执行效率指定执行测试顺序指定参数 2.根据个人博客设计的手工测试用例对每个测试用例的常用功能实现自动化测试 3.使用工具类每次测试都需要驱动写一个公共类实现代码复用 4.使用测试套件降低测试人员的工作量 5.使用等待提高自动化运行效率提高自动化的稳定性减小误报的可能性 参考代码 点击查看自动化测试源代码 总结 ✨✨✨各位读友本篇分享到内容如果对你有帮助给个赞鼓励一下吧 感谢每一位一起走到这的伙伴我们可以一起交流进步一起加油吧
http://www.dnsts.com.cn/news/85783.html

相关文章:

  • 自己建私人网站做外贸不好做0元做游戏代理
  • 网站开发 英文文章教人做衣服的网站
  • 网站策划书的内容百度推广优化技巧
  • 商城类网站建设报价安康市电梯公司
  • 网站模块怎么恢复网罗设计网站
  • pc端网站用vs做网站
  • 怎么查网站做站点地图招代理网站建设公司
  • 盐山国外网站建设虹口广州网站建设
  • 网站改标题降权专业做app下载网站有哪些
  • 有人从搜索引擎找网站建设吗什么是seo优化?
  • 买了空间和域名 怎么做网站wordpress媒体ip地址
  • 如何发布自己做的网站dede网站 设置404 错误页面
  • 图书馆信息化网站建设毕业设计做音乐网站
  • 自己制作一个网站需要多少钱海外购物网
  • 生产建设兵团第三师政务网站APP和网站是一样吗
  • 自己做的网站怎么链接火车头采集中国建筑协会官网
  • 文化馆门户网站建设的作用及意义网络职业有哪些
  • 沭阳住房和城乡建设局网站网站推广总结
  • 文化建设网站枣庄网页制作公司
  • 外贸建站哪个最便宜宁波市建设网
  • 自己做民宿在什么网站上投放新闻稿发布平台
  • 北方外贸网站建设外贸客户如何开发
  • 学网站制作多少钱wordpress微信登录调用
  • 4徐汇区网站建设如何设计制作企业网站
  • 狠狠做网站 百度一下深圳专业建网站公司排行
  • php就是做网站吗营销qq手机版
  • 网站开速度几秒湘乡网站seo
  • 百度云服务器搭建网站步骤深圳市住房和建设保障局
  • 网站建设总体流程投票制作网站
  • 快速网站收录wordpress注册模板