全国大学生软件测试大赛web练习题答案
Wneosy 2024-10-24 08:03:01 阅读 57
2024全国大学生软件测试web赛道练习题答案
<code>import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
@SuppressWarnings("unused")
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"));
try {
driver.get("http://120.26.37.204:8088/marks/login");
driver.manage().window().maximize();
Thread.sleep(1500);
driver.findElement(By.name("userName")).sendKeys("admin");//账号
Thread.sleep(1500);
driver.findElement(By.name("passWord")).sendKeys("123456");//密码
Thread.sleep(1500);
driver.findElement(By.id("loginFormBtn")).click();//登录
Thread.sleep(1500);
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);
driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[1]/input")).sendKeys("111");
Thread.sleep(1500);
driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[2]/input")).sendKeys("111");
Thread.sleep(1500);
driver.findElement(By.name("name")).sendKeys("111");//用户名
Thread.sleep(1500);
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.name("phone")).sendKeys("111");
Thread.sleep(1500);
driver.findElement(By.name("address")).sendKeys("江苏南京");
Thread.sleep(1500);
driver.findElement(By.id("addFormBtn")).click();//提交
Thread.sleep(1500);
driver.findElement(By.xpath("/html/body/div[9]/div[2]/div[2]/button")).click();//知道了
Thread.sleep(1500);
driver.findElement(By.name("para2")).sendKeys("111");
Thread.sleep(1500);
driver.findElement(By.name("para3")).sendKeys("111");
Thread.sleep(1500);
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);
driver.findElement(By.linkText("会员等级设置")).click();
Thread.sleep(1500);
driver.findElement(By.xpath("/html/body/div[3]/div[2]/div[1]/button/span")).click();//+号
Thread.sleep(1500);
driver.findElement(By.name("name")).sendKeys("钻石");
Thread.sleep(1500);
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);
driver.findElement(By.xpath("/html/body/div[9]/div[2]/div[2]/button")).click();//知道了
Thread.sleep(1500);
driver.findElement(By.className("fater-user")).click();
Thread.sleep(1500);
driver.findElement(By.id("sessionExit")).click();
Thread.sleep(1500);
driver.findElement(By.xpath("/html/body/div[9]/div[2]/div[2]/button[1]")).click();
Thread.sleep(1500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// Run main function to test your script.
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
try { test(driver); }
catch(Exception e) { e.printStackTrace(); }
finally { driver.quit(); }
}
}
声明
本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。