欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > 慕测官网——练习——超市管理系统

慕测官网——练习——超市管理系统

2024/10/26 0:31:14 来源:https://blog.csdn.net/2301_76876837/article/details/142903403  浏览:    关键词:慕测官网——练习——超市管理系统

一、赛前基础知识储备 

 

 

 

 

 

 

 

 

 

二、练习题对照答案 

 我的代码:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;public class Example {// Mooctest Selenium Example// <!> Check if selenium-standalone.jar is added to build path.// 测试方法public static void test(WebDriver driver) {// TODO Test script// eg:driver.get("https://www.baidu.com/")// eg:driver.findElement(By.id("wd"));// 打开网页driver.get("http://120.26.37.204:8088/marks/login/");// 最大化driver.manage().window().maximize();// 选择【账号输入框】并做【输入】操作,输入【admin】driver.findElement(By.name("userName")).sendKeys("admin");// driver.findElement(By.name("userName")).sendKeys("admin", Keys.TAB,// "123456");// . 选择【密码输入框】并做【输入】操作,输入【123456】driver.findElement(By.name("passWord")).sendKeys("123456");// 选择【登录】并做【点击】操作driver.findElement(By.id("loginFormBtn")).click();// 选择【系统用户管理】并做【点击】操作WebDriverWait wait = new WebDriverWait(driver, 10);WebElement XiTongYongHuGuanLi = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[2]/div[2]/div[2]/a")));XiTongYongHuGuanLi.click();// driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[2]/a")).click();// 选择【添加】并做【点击】操作WebElement TianJia = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[3]/div[2]/div[1]/button")));TianJia.click();// 输入账号密码(账号密码可任意输入、不可重复输入)// WebElement form = driver.findElement(By.tagName("form"));// form.findElement(B)WebElement username = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[4]/div[2]/form/div[1]/input")));username.sendKeys("187");driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[2]/input")).sendKeys("2004");// 选择【用户姓名输入框】并做【输入】操作,输入任意内容(不可重复输入)driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[3]/input")).sendKeys("李聪聪");// 选择【用户年龄】并做【输入】操作,输入内容为【20】driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[4]/input")).sendKeys("20");// 选择【用户性别栏】,选择【女】并做【点击】操作driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[5]/input[2]")).click();// 选择【用户类型】,选择【采购员】并做【点击】操作driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[6]/input[2]")).click();// 选择【联系电话】并做【输入】操作,输入内容为任意手机号。driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[7]/input")).sendKeys("15909299073");// 选择【联系地址】并做【输入】操作,输入内容为【江苏南京】driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[8]/input")).sendKeys("江苏南京");// 选择【提交】并做【点击】操作driver.findElement(By.id("addFormBtn")).click();// 选择【我知道】并做【点击】操作WebElement WoZhiDao = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[9]/div[2]/div[2]/button")));WoZhiDao.click();// 选择【用户名输出框】并做【输入】操作,输入内容为所添加用户时创建的用户名driver.findElement(By.xpath("/html/body/div[3]/div[1]/div[2]/div[2]/input")).sendKeys("李聪聪");// 选择【联系电话输入框】并做【输入】操作,输入内容为添加用户时所填写的号码driver.findElement(By.xpath("/html/body/div[3]/div[1]/div[2]/div[3]/input")).sendKeys("15909299073");// 选择【搜索】并做【点击】操作driver.findElement(By.xpath("//button[@type=\"button\" and @class=\"fater-btn fater-btn-form-qry\"]")).click();// 选择【删除】并做【点击】操作driver.findElement(By.xpath("//button[@type=\"button\" and @event=\"del\" and @class=\"fater-btn fater-btn-danger fater-btn-sm\"]")).click();// 选择【确认】并做【点击】操作(此处不做评分点)WebElement QueRenSanChu = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@event=\"ok\" and @type=\"button\" and @class=\"fater-btn fater-btn-primary fater-btn-sm\"]")));QueRenSanChu.click();// 选择【会员等级设置】并做【点击】操作driver.findElement(By.linkText("会员等级设置")).click();// 选择【添加】并做【点击】操作driver.findElement(By.xpath("//button[@event=\"add\" and @type=\"button\" and @class=\"fater-btn fater-btn-primary\"]")).click();// 选择【级别名称】并做【输入】操作,输入内容为【钻石】(此处不做评分点)WebElement JiBieMingCheng = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[4]/div[2]/form/div[1]/input")));JiBieMingCheng.sendKeys("钻石");// 选择【消费额度】并做【输入】操作,输入内容为【1000】driver.findElement(By.xpath("//input[@type=\"text\" and @name=\"total\" and @placeholder=\"请输入消费额度\" ]")).sendKeys("1000");// 选择【折扣优惠】并做【输入】操作,输入内容为【0.5】driver.findElement(By.xpath("//input[@type=\"text\" and @name=\"discount\" and @placeholder=\"请输入折扣优惠\"]")).sendKeys("0.5");;// 选择【提交】并做【点击】操作(此处不设得分点)driver.findElement(By.id("addFormBtn")).click();// 选择【知道了】并做【点击】操作(此处不做评分点)WebElement ZhiDaoLe = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@event='ok' and @type='button' and @class='fater-btn fater-btn-primary fater-btn-sm']")));ZhiDaoLe.click();// 选择【个人中心】并做【点击】操作driver.findElement(By.xpath("//div[@class='fater-user']")).click();// 选择【退出系统】并做【点击】操作WebElement TuiChuXiTong = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@id='sessionExit']")));TuiChuXiTong.click();}public static void main(String[] args) throws InterruptedException {// Run main function to test your script.// 设置 ChromeDriver 可执行文件的路径System.setProperty("webdriver.chrome.driver","C:\\Users\\27743\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe");// 加载浏览器WebDriver driver = new ChromeDriver();try {// 调用测试方法并传入drivertest(driver);} catch (Exception e) {// 如果发生异常,打印堆栈跟踪e.printStackTrace();} finally {// 关闭浏览器// Thread.sleep(3000);// driver.quit();}}}

 

 2

 

 

 

 

 

 

 

 

 

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;public class Example {// Mooctest Selenium Example// <!> Check if selenium-standalone.jar is added to build path.// 测试方法public static void test(WebDriver driver) throws InterruptedException {// TODO Test script// eg:driver.get("https://www.baidu.com/")// eg:driver.findElement(By.id("wd"));// 打开网页driver.get("http://120.26.37.204:8088/marks/login");// 最大化driver.manage().window().maximize();// 选择【账号输入框】并做【输入】操作,输入【admin】driver.findElement(By.name("userName")).sendKeys("admin");Thread.sleep(1500);// driver.findElement(By.name("userName")).sendKeys("admin", Keys.TAB,// "123456");// . 选择【密码输入框】并做【输入】操作,输入【123456】driver.findElement(By.name("passWord")).sendKeys("123456");Thread.sleep(1500);// 选择【登录】并做【点击】操作driver.findElement(By.id("loginFormBtn")).click();Thread.sleep(1500);// 选择【系统用户管理】并做【点击】操作// WebDriverWait wait = new WebDriverWait(driver, 10);// WebElement XiTongYongHuGuanLi = wait// .until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[2]/div[2]/div[2]/a")));// XiTongYongHuGuanLi.click();driver.findElement(By.linkText("系统用户管理")).click();Thread.sleep(1500);// 选择【添加】并做【点击】操作WebDriverWait wait = new WebDriverWait(driver, 10);Thread.sleep(1500);// WebDriverWait wait = new WebDriverWait(driver, 10);// WebElement TianJia = wait// .until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[3]/div[2]/div[1]/button")));// TianJia.click();driver.findElement(By.xpath("/html/body/div[3]/div[2]/div[1]/button")).click();Thread.sleep(1500);// 输入账号密码(账号密码可任意输入、不可重复输入)// WebElement username = wait// .until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[4]/div[2]/form/div[1]/input")));// username.sendKeys("187");driver.findElement(By.name("userName")).sendKeys("187");Thread.sleep(1500);// driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[2]/input")).sendKeys("2004");driver.findElement(By.name("passWord")).sendKeys("2004");Thread.sleep(1500);// 选择【用户姓名输入框】并做【输入】操作,输入任意内容(不可重复输入)// driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[3]/input")).sendKeys("李聪聪");driver.findElement(By.name("name")).sendKeys("李聪聪");Thread.sleep(1500);// 选择【用户年龄】并做【输入】操作,输入内容为【20】// driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[4]/input")).sendKeys("20");driver.findElement(By.name("age")).sendKeys("20");Thread.sleep(1500);// 选择【用户性别栏】,选择【女】并做【点击】操作driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[5]/input[2]")).click();Thread.sleep(1500);// 选择【用户类型】,选择【采购员】并做【点击】操作driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[6]/input[2]")).click();Thread.sleep(1500);// 选择【联系电话】并做【输入】操作,输入内容为任意手机号。/// driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[7]/input")).sendKeys("15909299073");Thread.sleep(1500);driver.findElement(By.name("phone")).sendKeys("15909299073");Thread.sleep(1500);// 选择【联系地址】并做【输入】操作,输入内容为【江苏南京】// driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[8]/input")).sendKeys("江苏南京");driver.findElement(By.name("address")).sendKeys("江苏南京");Thread.sleep(1500);// 选择【提交】并做【点击】操作driver.findElement(By.id("addFormBtn")).click();Thread.sleep(1500);// // 选择【我知道】并做【点击】操作// WebElement WoZhiDao = wait// .until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[9]/div[2]/div[2]/button")));// WoZhiDao.click();driver.findElement(By.xpath("/html/body/div[9]/div[2]/div[2]/button")).click();Thread.sleep(1500);// 选择【用户名输出框】并做【输入】操作,输入内容为所添加用户时创建的用户名driver.findElement(By.name("para2")).sendKeys("李聪聪");Thread.sleep(1500);// 选择【联系电话输入框】并做【输入】操作,输入内容为添加用户时所填写的号码driver.findElement(By.name("para3")).sendKeys("15909299073");Thread.sleep(1500);// 选择【搜索】并做【点击】操作// driver.findElement(By.xpath("//button[@type=\"button\" and @class=\"fater-btn// fater-btn-form-qry\"]")).click();// // 选择【删除】并做【点击】操作// driver.findElement(By.xpath(// "//button[@type=\"button\" and @event=\"del\" and @class=\"fater-btn// fater-btn-danger fater-btn-sm\"]"))// .click();// // 选择【确认】并做【点击】操作(此处不做评分点)// WebElement QueRenSanChu =// wait.until(ExpectedConditions.elementToBeClickable(By.xpath(// "//button[@event=\"ok\" and @type=\"button\" and @class=\"fater-btn// fater-btn-primary fater-btn-sm\"]")));driver.findElement(By.xpath("/html/body/div[3]/div[1]/div[2]/div[4]/button")).click();Thread.sleep(1500);driver.findElement(By.xpath("//*[@id=\"tableShow\"]/table/tbody/tr[1]/td[9]/button[2]")).click();Thread.sleep(1500);driver.findElement(By.xpath("/html/body/div[9]/div[2]/div[2]/button[1]")).click();Thread.sleep(1500);// QueRenSanChu.click();// 选择【会员等级设置】并做【点击】操作driver.findElement(By.linkText("会员等级设置")).click();Thread.sleep(1500);// 选择【添加】并做【点击】操作driver.findElement(By.xpath("/html/body/div[3]/div[2]/div[1]/button")).click();Thread.sleep(1500);// 选择【级别名称】并做【输入】操作,输入内容为【钻石】(此处不做评分点)// WebElement JiBieMingCheng = wait// .until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[4]/div[2]/form/div[1]/input")));// JiBieMingCheng.sendKeys("钻石");driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[1]/input")).sendKeys("钻石");Thread.sleep(1500);// // 选择【消费额度】并做【输入】操作,输入内容为【1000】// driver.findElement(By.xpath("//input[@type=\"text\" and @name=\"total\" and// @placeholder=\"请输入消费额度\" ]"))// .sendKeys("1000");// // 选择【折扣优惠】并做【输入】操作,输入内容为【0.5】// driver.findElement(By.xpath("//input[@type=\"text\" and @name=\"discount\"// and @placeholder=\"请输入折扣优惠\"]"))// .sendKeys("0.5");driver.findElement(By.name("total")).sendKeys("1000");Thread.sleep(1500);driver.findElement(By.name("discount")).sendKeys("0.5");Thread.sleep(1500);// 选择【提交】并做【点击】操作(此处不设得分点)driver.findElement(By.id("addFormBtn")).click();Thread.sleep(1500);// // 选择【知道了】并做【点击】操作(此处不做评分点)// WebElement ZhiDaoLe =// wait.until(ExpectedConditions.elementToBeClickable(By.xpath(// "//button[@event='ok' and @type='button' and @class='fater-btn// fater-btn-primary fater-btn-sm']")));// ZhiDaoLe.click();driver.findElement(By.xpath("/html/body/div[9]/div[2]/div[2]/button")).click();Thread.sleep(1500);// // 选择【个人中心】并做【点击】操作// driver.findElement(By.xpath("//div[@class='fater-user']")).click();driver.findElement(By.className("fater-user")).click();Thread.sleep(1500);// // 选择【退出系统】并做【点击】操作//// WebElement TuiChuXiTong = wait// .until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@id='sessionExit']")));// TuiChuXiTong.click();driver.findElement(By.id("sessionExit")).click();Thread.sleep(1500);}public static void main(String[] args) throws InterruptedException {// Run main function to test your script.// 设置 ChromeDriver 可执行文件的路径System.setProperty("webdriver.chrome.driver","C:\\Users\\27743\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe");// 加载浏览器WebDriver driver = new ChromeDriver();try {// 调用测试方法并传入drivertest(driver);} catch (Exception e) {// 如果发生异常,打印堆栈跟踪e.printStackTrace();} finally {// 关闭浏览器driver.quit();}}}

 

三、超市管理系统Selenium自动化测试实战 

 

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com