网站备案类型及条件,中山网站建设电话,深圳最大的企业排名,美食网站设计模板目录 
前言 
一、思维导图 
二、代码编写 
1.在pom.xml文件中添加相关依赖 2.自动化代码编写 
三、代码测试 
小结 前言 
1. 针对商品信息管理项目进行测试#xff0c;商品信息管理项目主要有商品列表页、部门列表页、员工列表页#xff0c;主要功能#xff1a;对商品信息的…目录 
前言 
一、思维导图 
二、代码编写 
1.在pom.xml文件中添加相关依赖 2.自动化代码编写 
三、代码测试 
小结 前言 
1. 针对商品信息管理项目进行测试商品信息管理项目主要有商品列表页、部门列表页、员工列表页主要功能对商品信息的增删改查的功能。对于商品信息管理的测试主要就是对主要功能进行测试按照页面以及测试用例的思维导图进行自动化脚本的编写及测试。 
2.自动化测试一般步骤 
1使用Xmind编写web自动化测试用例 
2创建自动化项目根据测试用例实现脚本的编写及测试 
一、思维导图 
web自动化测试用例思维导图 二、代码编写 
根据思维导图进行测试用例的代码编写每个页面一个测试类然后在各个测试类中进行测试用例的编写。注意公共属性需要单独放一个类方便进行代码复用。创建启动以及截图会频繁进行复用所以创建方法进行封装。注意添加隐式等待为了确保页面正确加载显示 1.在pom.xml文件中添加相关依赖 
!--引入驱动管理依赖--
dependencygroupIdio.github.bonigarcia/groupIdartifactIdwebdrivermanager/artifactIdversion5.8.0/versionscopetest/scope/dependency
!--引入selenium依赖--
dependencygroupIdorg.seleniumhq.selenium/groupIdartifactIdselenium-java/artifactIdversion4.0.0/version
/dependency
!--引入屏幕截图依赖--
dependencygroupIdcommons-io/groupIdartifactIdcommons-io/artifactIdversion2.6/version
/dependency 
2.自动化代码编写 
代码只展示主要部分 
1.创建驱动对象和截屏会频繁使用将其封装成方法 // 创建驱动对象
void createDriver() {if (driver  null) {// 1. 使用驱动管理程序打开谷歌浏览器驱动;WebDriverManager.chromedriver().setup();//  添加浏览器配置-创建的驱动对象允许浏览器访问所有链接ChromeOptions options  new ChromeOptions();options.addArguments(--remote-allow-origins*);driver  new ChromeDriver(options);}
}/*** 截屏并保存到指定目录下* 文件名格式./src/test/images/2025-01-29/FirstTest_130725.png*/
private void getScreenshot(String str) throws IOException {SimpleDateFormat sim1  new SimpleDateFormat(yyyy-MM-dd);// 日期 2025-01-29SimpleDateFormat sim2  new SimpleDateFormat(HHmmssSS);// 时间戳 13时07分25秒25毫秒String dirTime  sim1.format(System.currentTimeMillis());// 日期目录 2025-01-29String fileTime  sim2.format(System.currentTimeMillis());// 时间戳 13时07分25秒25毫秒
//     ./src/test/images/2025-01-29/FirstTest_130725.pngString fileName  ./src/test/images/dirTime  /str  _ fileTime  .png;// 文件名System.out.println(截图文件名fileName  fileName);//    拍截屏文件并保存到指定目录下File srcFile  ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);FileUtils.copyFile(srcFile, new File(fileName));
} 
2. 测试商品搜索功能 
测试页面能否正常打开测试能否依据名字查询商品信息测试能否依据品牌查询商品信息 
/*** 测试 商品根据名字进行搜索的功能* throws IOException*/
void retrieveProduct() throws IOException, InterruptedException {createDriver();driver.get(http://localhost:90/#/product);// 获取商品页面中的输入框元素WebElement element  driver.findElement(By.cssSelector(body  div  section  section  main  form  div:nth-child(1)  div  div  input));// 输入框输入内容 床上桌element.sendKeys(床上桌);// 点击搜索按钮driver.findElement(By.cssSelector(body  div  section  section  main  form  div:nth-child(2)  div  button)).click();Thread.sleep(1000);// 截屏并保存到指定目录下getScreenshot(ProductPageTest);//显示商品的详细信息点击确定按钮driver.findElement(By.cssSelector(body  div:nth-child(2)  section  section  main  div:nth-child(2)  div  div.el-dialog__footer  div  button.el-button.el-button--primary)).click();// 删除输入框中的内容 床上桌element.clear();driver.quit();
} 
3.测试新增商品功能 
测试新增商品按钮功能能否正常使用测试填写新增商品的所有信息能否新增成功测试填写部分新增商品的信息能否新增成功测试不填写新增商品信息能否新增成功 
/*** 测试 新增商品* throws IOException* throws InterruptedException*/
void createProduct() throws IOException, InterruptedException {createDriver();driver.get(http://localhost:90/#/product);// 点击新增按钮driver.findElement(By.cssSelector(body  div  section  section  main  div.el-row  button)).click();//     获取 名字输入框元素WebElement nameInput  driver.findElement(By.cssSelector(body  div:nth-child(2)  section  section  main  div:nth-child(4)  div  div.el-dialog__body  form  div:nth-child(1)  div  div  input));// 输入内容 插头nameInput.clear();nameInput.sendKeys(插头);//  获取 价格输入框元素WebElement priceInput  driver.findElement(By.cssSelector(body  div:nth-child(2)  section  section  main  div:nth-child(4)  div  div.el-dialog__body  form  div:nth-child(2)  div  div  input));// 输入内容 100priceInput.clear();priceInput.sendKeys(100);// 获取 品牌输入框元素WebElement descInput  driver.findElement(By.cssSelector(body  div:nth-child(2)  section  section  main  div:nth-child(4)  div  div.el-dialog__body  form  div:nth-child(3)  div  div  input));// 输入内容descInput.clear();descInput.sendKeys(公牛);// 获取库存输入框元素WebElement stockInput  driver.findElement(By.cssSelector(body  div:nth-child(2)  section  section  main  div:nth-child(4)  div  div.el-dialog__body  form  div:nth-child(4)  div  div  input));// 输入内容 100stockInput.clear();stockInput.sendKeys(100);// 点击确定按钮driver.findElement(By.cssSelector(body  div:nth-child(2)  section  section  main  div:nth-child(4)  div  div.el-dialog__footer  div  button.el-button.el-button--primary)).click();// 显示等待1秒直到确定按钮被点击然后刷新页面WebDriverWait wait  new WebDriverWait(driver, Duration.ofSeconds(1));wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(body  div:nth-child(2)  section  section  main  div:nth-child(4)  div  div.el-dialog__footer  div  button.el-button.el-button--primary)));// 刷新页面driver.navigate().refresh();
//     Thread.sleep(1000);// 截屏并保存到指定目录下getScreenshot(ProductPageTest);// 断言新增的商品是否存在
//        WebElement product  driver.findElement(By.xpath(//td[contains(text(),插头)]));
//     assert product ! null;driver.quit();
} 
4.测试修改商品信息功能 
测试编辑按钮功能能否正常使用测试修改商品的所有信息能否修改成功测试修改商品的部分信息能否修改成功 
/*** 测试 修改商品的价格* throws IOException* throws InterruptedException*/
void updateProduct() throws IOException, InterruptedException {createDriver();driver.get(http://localhost:90/#/product);
//     Thread.sleep(1000);
//     隐式等待1秒driver.manage().timeouts().implicitlyWait(Duration.ofMillis(1000));// 点击编辑按钮driver.findElement(By.xpath(/html/body/div/section/section/main/div[4]/div[3]/table/tbody/tr[1]/td[5]/div/button[1])).click();// 获取 价格输入框元素WebElement priceInput  driver.findElement(By.cssSelector(body  div:nth-child(2)  section  section  main  div:nth-child(7)  div  div.el-dialog__body  form  div:nth-child(2)  div  div  input));// 修改价格为 20priceInput.clear();priceInput.sendKeys(20);// 点击确定按钮driver.findElement(By.cssSelector(body  div:nth-child(2)  section  section  main  div:nth-child(7)  div  div.el-dialog__footer  div  button.el-button.el-button--primary)).click();// 显示等待1秒直到确定按钮被点击然后刷新页面WebDriverWait wait  new WebDriverWait(driver, Duration.ofSeconds(1));wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(body  div:nth-child(2)  section  section  main  div:nth-child(7)  div  div.el-dialog__footer  div  button.el-button.el-button--primary)));// 刷新页面driver.navigate().refresh();// 截屏并保存到指定目录下getScreenshot(ProductPageTest);// 断言修改后的价格是否正确
//     WebElement product  driver.findElement(By.xpath(//td[contains(text(),20)]));
//     assert product ! null;driver.quit();
} 
5.测试删除商品功能 
测试删除按钮是否能够正常使用测试点击删除按钮再确认删除能否删除成功测试点击删除按钮再取消删除能否取消删除成功测试删除成功后刷新页面是否能够显示非删除数据 
/*** 测试 删除商品* throws IOException* throws InterruptedException*/
void deleteProduct() throws IOException, InterruptedException {createDriver();driver.get(http://localhost:90/#/product);// 点击删除按钮driver.findElement(By.xpath(/html/body/div/section/section/main/div[4]/div[3]/table/tbody/tr[1]/td[5]/div/button[2])).click();// 点击确定按钮
//     driver.findElement(By.cssSelector(body  div:nth-child(2)  section  section  main  div:nth-child(6)  div  div.el-dialog__footer  div  button.el-button--primary)).click();// 显示等待1秒直到确定按钮被点击然后刷新页面WebDriverWait wait  new WebDriverWait(driver, Duration.ofSeconds(1));wait.until(ExpectedConditions.elementToBeClickable(By.xpath(/html/body/div/section/section/main/div[4]/div[3]/table/tbody/tr[1]/td[5]/div/button[2])));// 刷新页面driver.navigate().refresh();// 截屏并保存到指定目录下getScreenshot(ProductPageTest);// 断言删除后的商品是否不存在
//     WebElement product  driver.findElement(By.xpath(//td[contains(text(),头)]));
//     assert product  null;driver.quit();
} 
三、代码测试 所有测试用例通过但发现测试耗时有些长说明性能还有优化的空间。 
小结 
一定要关注测试用例的执行顺序问题对于页面的检查一定要到位如检查元素是否存在确保页面的正确性驱动关闭的位置要注意只有最后一个用例结束之后才进行关闭为了把所有的用例的执行结果保存下来方便后续查错或查看此时就需要进行该方法的定义即封装一个屏幕截图的方法注意屏幕截图保存的方式动态时间戳并进行时间格式化然后期望按照某种维度天、周以文件夹的方式进行保存在定位元素时当复制的cssSelector的值比较长时建议复制xpath因为cssSelector的值比较长就可能会导致定位元素失败可以适当关注用例执行时间如果时间过长就需要考虑是我们自己写的测试用例的问题还是程序真的有性能问题 文章转载自: http://www.morning.qmtzq.cn.gov.cn.qmtzq.cn http://www.morning.jfsbs.cn.gov.cn.jfsbs.cn http://www.morning.fykrm.cn.gov.cn.fykrm.cn http://www.morning.ldqzz.cn.gov.cn.ldqzz.cn http://www.morning.rwjtf.cn.gov.cn.rwjtf.cn http://www.morning.svtxeu.com.gov.cn.svtxeu.com http://www.morning.rkyw.cn.gov.cn.rkyw.cn http://www.morning.rqlqd.cn.gov.cn.rqlqd.cn http://www.morning.mwpcp.cn.gov.cn.mwpcp.cn http://www.morning.redhoma.com.gov.cn.redhoma.com http://www.morning.hcgbm.cn.gov.cn.hcgbm.cn http://www.morning.mkxxk.cn.gov.cn.mkxxk.cn http://www.morning.rnyhx.cn.gov.cn.rnyhx.cn http://www.morning.tyhfz.cn.gov.cn.tyhfz.cn http://www.morning.dqzcf.cn.gov.cn.dqzcf.cn http://www.morning.zlrsy.cn.gov.cn.zlrsy.cn http://www.morning.qpnb.cn.gov.cn.qpnb.cn http://www.morning.ylqpp.cn.gov.cn.ylqpp.cn http://www.morning.fjkkx.cn.gov.cn.fjkkx.cn http://www.morning.lbxhy.cn.gov.cn.lbxhy.cn http://www.morning.hjwzpt.com.gov.cn.hjwzpt.com http://www.morning.wqmyh.cn.gov.cn.wqmyh.cn http://www.morning.knrgb.cn.gov.cn.knrgb.cn http://www.morning.fwnyz.cn.gov.cn.fwnyz.cn http://www.morning.ltqzq.cn.gov.cn.ltqzq.cn http://www.morning.xqkcs.cn.gov.cn.xqkcs.cn http://www.morning.txkrc.cn.gov.cn.txkrc.cn http://www.morning.ynlbj.cn.gov.cn.ynlbj.cn http://www.morning.rchsr.cn.gov.cn.rchsr.cn http://www.morning.tsxg.cn.gov.cn.tsxg.cn http://www.morning.rrxmm.cn.gov.cn.rrxmm.cn http://www.morning.yxdrf.cn.gov.cn.yxdrf.cn http://www.morning.hypng.cn.gov.cn.hypng.cn http://www.morning.nnmnz.cn.gov.cn.nnmnz.cn http://www.morning.dzfwb.cn.gov.cn.dzfwb.cn http://www.morning.nlryq.cn.gov.cn.nlryq.cn http://www.morning.fmswb.cn.gov.cn.fmswb.cn http://www.morning.wqcbr.cn.gov.cn.wqcbr.cn http://www.morning.mqldj.cn.gov.cn.mqldj.cn http://www.morning.jfxth.cn.gov.cn.jfxth.cn http://www.morning.yyzgl.cn.gov.cn.yyzgl.cn http://www.morning.lmbm.cn.gov.cn.lmbm.cn http://www.morning.nxrgl.cn.gov.cn.nxrgl.cn http://www.morning.hxgly.cn.gov.cn.hxgly.cn http://www.morning.rlhjg.cn.gov.cn.rlhjg.cn http://www.morning.yhglt.cn.gov.cn.yhglt.cn http://www.morning.zdtfr.cn.gov.cn.zdtfr.cn http://www.morning.xsfny.cn.gov.cn.xsfny.cn http://www.morning.c7624.cn.gov.cn.c7624.cn http://www.morning.mrcpy.cn.gov.cn.mrcpy.cn http://www.morning.ybhjs.cn.gov.cn.ybhjs.cn http://www.morning.yfrbn.cn.gov.cn.yfrbn.cn http://www.morning.yrbp.cn.gov.cn.yrbp.cn http://www.morning.wschl.cn.gov.cn.wschl.cn http://www.morning.mrgby.cn.gov.cn.mrgby.cn http://www.morning.hwnqg.cn.gov.cn.hwnqg.cn http://www.morning.ngqty.cn.gov.cn.ngqty.cn http://www.morning.jxtbr.cn.gov.cn.jxtbr.cn http://www.morning.dbnpz.cn.gov.cn.dbnpz.cn http://www.morning.jwefry.cn.gov.cn.jwefry.cn http://www.morning.rpkg.cn.gov.cn.rpkg.cn http://www.morning.drywd.cn.gov.cn.drywd.cn http://www.morning.fplqh.cn.gov.cn.fplqh.cn http://www.morning.yrmpr.cn.gov.cn.yrmpr.cn http://www.morning.ghlyy.cn.gov.cn.ghlyy.cn http://www.morning.dsmwy.cn.gov.cn.dsmwy.cn http://www.morning.rfycj.cn.gov.cn.rfycj.cn http://www.morning.kldtf.cn.gov.cn.kldtf.cn http://www.morning.pwdrc.cn.gov.cn.pwdrc.cn http://www.morning.htbsk.cn.gov.cn.htbsk.cn http://www.morning.gppqf.cn.gov.cn.gppqf.cn http://www.morning.bctr.cn.gov.cn.bctr.cn http://www.morning.mxmzl.cn.gov.cn.mxmzl.cn http://www.morning.ldspj.cn.gov.cn.ldspj.cn http://www.morning.wkxsy.cn.gov.cn.wkxsy.cn http://www.morning.qmfhh.cn.gov.cn.qmfhh.cn http://www.morning.gynkr.cn.gov.cn.gynkr.cn http://www.morning.jiuyungps.com.gov.cn.jiuyungps.com http://www.morning.etsaf.com.gov.cn.etsaf.com http://www.morning.kspfq.cn.gov.cn.kspfq.cn