功能测试——房屋租赁系统(Selenium IDE)
Posted Starzkg
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了功能测试——房屋租赁系统(Selenium IDE)相关的知识,希望对你有一定的参考价值。
源代码:https://gitee.com/shentuzhigang/mini-project/tree/master/test-house-rental
测试需求
- 打开浏览器(请用 Google 或 者 Firefox ,其他浏览器会产生样式不适配) 输入:http://114.215.176.95:60513/text2/ ,以管理员身份登录账号 admin,密码 123456
管理员:账号 admin,密码 123456
租客:账号 空格,密码 空格
-
点击左侧菜单栏查看房源列表,任意选择一个房屋点击修改按钮
-
修改房源信息: 修改租赁价格为 700.0,完成后点击提交
-
在上面同一位置,添加房源信息
-
合理化输入房屋 ID、地址、面积、租金、状态选择未租赁,点击提交
-
点击左侧菜单栏租赁及合同信息选项下的在租列表,选择任一一个合同,点击查看合同,进入合同详情页面
-
修改合同,每月交租日改为 2,点击修改按钮提交。
-
点击租金信息下的我要收租选项,选择任一房屋,点击收租查看详情
-
点击菜单栏租客已缴租金,输入姓名李四,查询租客信息
-
点击退出登录按钮,测试结束
测试步骤
- Selenium 脚本录制
- 导出Junit测试
- 完善脚本
// Generated by Selenium IDE
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsNot.not;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.javascriptExecutor;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
import java.util.*;
import java.net.MalformedURLException;
import java.net.URL;
public class Test1Test {
private WebDriver driver;
private Map<String, Object> vars;
JavascriptExecutor js;
@Before
public void setUp() {
driver = new ChromeDriver();
js = (JavascriptExecutor) driver;
vars = new HashMap<String, Object>();
}
@After
public void tearDown() {
driver.quit();
}
@Test
public void test1() {
driver.get("http://114.215.176.95:60513/text2/");
driver.manage().window().setSize(new Dimension(1552, 840));
driver.findElement(By.name("username")).click();
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("123456");
driver.findElement(By.id("login-button")).click();
driver.findElement(By.cssSelector(".container")).click();
driver.findElement(By.linkText("房源列表")).click();
driver.findElement(By.cssSelector("tr:nth-child(3) .link-update")).click();
driver.findElement(By.id("price")).click();
driver.findElement(By.id("price")).sendKeys("700.0");
driver.findElement(By.cssSelector(".btn-primary")).click();
driver.findElement(By.linkText("添加房源")).click();
driver.findElement(By.id("houseid")).click();
driver.findElement(By.id("houseid"))..sendKeys("a10086");
driver.findElement(By.id("address")).click();
driver.findElement(By.id("address")).sendKeys("615黄记煌三汁焖锅");
driver.findElement(By.id("area")).click();
driver.findElement(By.id("area")).sendKeys("1000000000000000000000000000000000000000000000000000000000000");
driver.findElement(By.id("price")).click();
driver.findElement(By.id("price")).sendKeys("700.0");
driver.findElement(By.cssSelector("tr:nth-child(5) > td")).click();
driver.findElement(By.id("status")).click();
{
WebElement dropdown = driver.findElement(By.id("status"));
dropdown.findElement(By.xpath("//option[. = '未租赁']")).click();
}
driver.findElement(By.id("status")).click();
driver.findElement(By.cssSelector(".btn-primary")).click();
driver.findElement(By.linkText("在租列表")).click();
driver.findElement(By.linkText("查看合同")).click();
driver.findElement(By.name("hetong")).click();
driver.findElement(By.cssSelector(".btn-primary")).click();
driver.findElement(By.cssSelector("tr:nth-child(10)")).click();
driver.findElement(By.id("payday")).sendKeys("2");
driver.findElement(By.cssSelector(".btn-primary")).click();
driver.findElement(By.linkText("我要收租")).click();
driver.findElement(By.linkText("收租")).click();
driver.findElement(By.cssSelector("tr:nth-child(2) > td")).click();
driver.findElement(By.id("address")).click();
driver.findElement(By.id("address")).click();
driver.findElement(By.id("date")).click();
driver.findElement(By.linkText("11")).click();
driver.findElement(By.id("zuke")).click();
driver.findElement(By.id("zuke")).sendKeys("700.0");
driver.findElement(By.cssSelector(".btn-primary")).click();
}
}
- 移除Junit并优化
package io.shentuzhigang.test.houserental;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
/**
* @author ShenTuZhiGang
* @version 1.0.0
* @email 1600337300@qq.com
* @date 2021-06-20 15:00
*/
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://114.215.176.95:60513/text2/");
driver.manage().window().setSize(new Dimension(1552, 840));
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("123456");
driver.findElement(By.id("login-button")).click();
driver.findElement(By.cssSelector(".container")).click();
driver.findElement(By.linkText("房源列表")).click();
driver.findElement(By.linkText("修改")).click();
driver.findElement(By.id("price")).clear();
driver.findElement(By.id("price")).sendKeys("700");
driver.findElement(By.cssSelector(".btn-primary")).click();
driver.findElement(By.linkText("添加房源")).click();
driver.findElement(By.id("houseid")).sendKeys("a100861");
driver.findElement(By.id("address")).sendKeys("615黄记煌三汁焖锅");
driver.findElement(By.id("area")).sendKeys("1000");
driver.findElement(By.id("price")).sendKeys("700.0");
{
WebElement dropdown = driver.findElement(By.id("status"));
dropdown.findElement(By.xpath("//option[. = '未租赁']")).click();
}
driver.findElement(By.id("status")).click();
driver.findElement(By.cssSelector(".btn-primary")).click();
driver.findElement(By.linkText("租赁及合同信息")).click();
driver.findElement(By.linkText("在租列表")).click();
driver.findElement(By.linkText("查看合同")).click();
driver.findElement(By.name("hetong")).click();
driver.findElement(By.cssSelector(".btn-primary")).click();
driver.findElement(By.cssSelector("tr:nth-child(10)")).click();
driver.findElement(By.id("payday")).clear();
driver.findElement(By.id("payday")).sendKeys("2");
driver.findElement(By.cssSelector(".btn-primary")).click();
driver.findElement(By.linkText("租客已缴租金")).click();
driver.findElement(By.id("zuname")).sendKeys("cwy");
driver.findElement(By.name("sub")).click();
driver.findElement(By.linkText("我要收租")).click();
driver.findElement以上是关于功能测试——房屋租赁系统(Selenium IDE)的主要内容,如果未能解决你的问题,请参考以下文章