针对网易邮箱页面、qq邮箱页面、搜狐邮箱页面、新浪邮箱页面的所有功能,例如注册、登陆、忘记密码等功能进行软件测试。针对注册功能,编写相应的测试用例;针对登陆功能,编写相应的测试用例;测试方法可以采用等价类、边界值的测试方法;执行测试用,发现Bug,编写Bug单;编写测试报告。
此处测试为网易邮箱,其他邮箱测试已做好,需要可私信。
一、下载idea推荐官网下载,安装完成打开。
二、准备需要的edge浏览器和对应版本的edgedriver
1.首先查看edge版本,笔者版本为125.0.2535.92
2.下载对应版本的web,下载网址Microsoft Edge WebDriver | Microsoft Edge Developer
选择对应版本下载
3.安装,建议放在c盘,笔者目录为C:\drivers,代码中有对应
4.新建环境变量,选选择path,双击
新建如下,复制目录位置
点击确定后退出。
三、打开ieda,创建新项目,
1. 选用Java和合适的jdk
添加框架技术,勾选maven
2.生成pom.xml,添加所需依赖,此处添加junit,selenium,Apache
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>web-test-project</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- Selenium WebDriver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0</version>
</dependency>
<!-- JUnit 4 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
3.在test目录下,新建你的源代码根目录
4.忘记密码,可替换为实际的网址,
https://id.163.com/mail/retrievepassword?pd=mail163&pkid=CvViHzl#/verifyAccount
package com.example.yourproject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
public class EmailForgotPasswordTest {
private WebDriver driver;
@Before
public void setUp() {
System.setProperty("webdriver.edge.driver", "C:/drivers/msedgedriver.exe");
driver = new EdgeDriver();
}
@Test
public void testForgotPassword() {
driver.get("https://id.163.com/mail/retrievepassword?pd=mail163&pkid=CvViHzl#/verifyAccount");
try {
// 等待页面加载
Thread.sleep(5000);
// 使用提供的XPath定位元素并输入用户名
WebElement username = driver.findElement(By.xpath("//*[@id='app']/div/div[2]/div/div[2]/form/div[1]/div[2]/div/div[1]/div[1]/div/input"));
username.sendKeys("@163.com");
// 定位到下一步按钮
WebElement nextButton = driver.findElement(By.xpath("//*[@id='app']/div/div[2]/div/div[2]/form/div[2]/button"));
nextButton.click();
// 这里可以添加更多的步骤和断言来验证密码找回流程是否成功
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// 保持浏览器窗口打开一段时间,以便查看结果
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
将此处替换为实际需要测试的邮箱
5.登录,看实际是否需要切换iframe,此处需要,如不能正常运行,删除切换iframe
https://mail.163.com/
package com.example.yourproject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import static org.junit.Assert.assertEquals;
public class EmailLoginTest {
private WebDriver driver;
@Before
public void setUp() {
// 设置EdgeDriver的路径
System.setProperty("webdriver.edge.driver", "C:/drivers/msedgedriver.exe");
driver = new EdgeDriver();
}
@Test
public void testLogin() {
driver.get("https://mail.163.com/");
try {
// 等待页面加载
Thread.sleep(5000); // 暂停5秒等待页面加载
// 切换到iframe
WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
// 查找并填写邮箱和密码
WebElement username = driver.findElement(By.name("email"));
WebElement password = driver.findElement(By.name("password"));
WebElement loginButton = driver.findElement(By.id("dologin"));
username.sendKeys("youremail");
password.sendKeys("yourpassword");
loginButton.click();
// 等待页面加载
Thread.sleep(5000); // 暂停5秒等待页面加载
// 验证登录是否成功
WebElement welcomeMessageElement = driver.findElement(By.id("welcomeMessage"));
String welcomeMessage = welcomeMessageElement.getText();
assertEquals("欢迎, shlzeei8028", welcomeMessage);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
// 保持浏览器窗口打开一段时间,以便查看结果
try {
Thread.sleep(10000); // 暂停10秒等待查看结果
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
此处同上,实际邮箱密码
6.注册
https://mail.163.com/register/index.htm?from=163mail&utm_source=163mail#/pn
package com.example.yourproject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertTrue;
public class EmailRegistrationTest {
private WebDriver driver;
@Before
public void setUp() {
// 设置EdgeDriver的路径
System.setProperty("webdriver.edge.driver", "C:/drivers/msedgedriver.exe");
driver = new EdgeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void testRegistration() {
driver.get("https://mail.163.com/register/index.htm?from=163mail&utm_source=163mail#/pn");
try {
// 等待页面加载
Thread.sleep(5000); // 暂停5秒等待页面加载
System.out.println("页面加载完成");
// 使用提供的XPath定位元素
WebElement phoneNumber = driver.findElement(By.xpath("//*[@id='root']/table/tbody/tr[3]/td/table/tbody/tr/td[3]/table/tbody/tr/td/div[3]/div[1]/div/div[1]/span/input"));
System.out.println("找到手机号输入框");
WebElement password = driver.findElement(By.xpath("//*[@id='root']/table/tbody/tr[3]/td/table/tbody/tr/td[3]/table/tbody/tr/td/div[3]/table/tbody/tr[1]/td[1]/label/span/input"));
System.out.println("找到密码输入框");
WebElement agreeCheckbox = driver.findElement(By.xpath("//*[@id='root']/table/tbody/tr[3]/td/table/tbody/tr/td[3]/table/tbody/tr/td/div[3]/div[2]/div/div[1]/span[1]/input"));
System.out.println("找到同意协议复选框");
WebElement submitButton = driver.findElement(By.xpath("//*[@id='root']/table/tbody/tr[3]/td/table/tbody/tr/td[3]/table/tbody/tr/td/div[3]/div[3]/button"));
System.out.println("找到注册按钮");
phoneNumber.sendKeys("18192093815");
password.sendKeys("123456");
agreeCheckbox.click(); // 点击同意协议复选框
submitButton.click(); // 点击注册按钮
System.out.println("填写并提交注册信息");
// 可以在这里添加一些断言来验证是否注册成功
// 例如,检查是否跳转到注册成功页面
Thread.sleep(5000); // 暂停5秒等待页面加载
WebElement successMessage = driver.findElement(By.xpath("//div[contains(text(),'注册成功')]")); // 根据实际情况修改
assertTrue(successMessage.getText().contains("注册成功"));
System.out.println("注册成功");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
// 保持浏览器窗口打开一段时间,以便查看结果
try {
Thread.sleep(10000); // 暂停10秒等待查看结果
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
实际手机号和密码,注意密码格式,为a-z/A-Z包含大小写和数字
测试网页