大赛介绍以及准备

参考链接

全国大学生软件测试大赛 备赛准备

2024 web组软件测试

功能测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Duration;
import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;

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();
Thread.sleep(1500);
// 2
driver.findElement(By.xpath("/html/body/div[1]/div/div[2]/form/div[1]/input")).sendKeys("admin");;
driver.findElement(By.xpath("/html/body/div[1]/div/div[2]/form/div[2]/input")).sendKeys("123456");
Thread.sleep(1500);
driver.findElement(By.xpath("//*[@id=\"loginFormBtn\"]")).click();
Thread.sleep(1500);
driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[2]/a")).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.xpath("/html/body/div[4]/div[2]/form/div[1]/input")).sendKeys("test123");
driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[2]/input")).sendKeys("test");
driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[3]/input")).sendKeys("测试123");
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("18911112222");
driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[8]/input")).sendKeys("江苏南京");
Thread.sleep(1500);
driver.findElement(By.xpath("//*[@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.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("18911112222");
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/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.xpath("/html/body/div[2]/div[2]/div[3]/a")).click();
driver.findElement(By.xpath("/html/body/div[3]/div[2]/div[1]/button")).click();
driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[1]/input")).sendKeys("钻石");
driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[2]/input")).sendKeys("1000");
driver.findElement(By.xpath("/html/body/div[4]/div[2]/form/div[3]/input")).sendKeys("0.5");
Thread.sleep(1500);
driver.findElement(By.xpath("//*[@id=\"addFormBtn\"]")).click();
Thread.sleep(1500);
driver.findElement(By.xpath("/html/body/div[9]/div[2]/div[2]/button")).click();
//点击退出
driver.findElement(By.xpath("/html/body/div[1]/div")).click();
Thread.sleep(1500);
driver.findElement(By.xpath("//*[@id=\"sessionExit\"]")).click();
}

public static void main(String[] args) {
// Run main function to test your script.
WebDriver driver = new ChromeDriver();
try { test(driver); }
catch(Exception e) { e.printStackTrace(); }
finally { driver.quit(); }
}

}

用chrome浏览器测试就在chrome浏览器里找元素,因为一开始在edge浏览器找的元素,导致有一些元素定位对不上,找不到元素而出错。