当前位置 博文首页 > 无限迭代中......:功能测试——房屋租赁系统(Selenium IDE)

    无限迭代中......:功能测试——房屋租赁系统(Selenium IDE)

    作者:[db:作者] 时间:2021-07-06 09:40

    源代码:https://gitee.com/shentuzhigang/mini-project/tree/master/test-house-rental

    测试需求

    1. 打开浏览器(请用 Google 或 者 Firefox ,其他浏览器会产生样式不适配) 输入:http://114.215.176.95:60513/text2/ ,以管理员身份登录账号 admin,密码 123456

    管理员:账号 admin,密码 123456
    租客:账号 空格,密码 空格

    在这里插入图片描述

    1. 点击左侧菜单栏查看房源列表,任意选择一个房屋点击修改按钮
      在这里插入图片描述

    2. 修改房源信息: 修改租赁价格为 700.0,完成后点击提交
      在这里插入图片描述

    3. 在上面同一位置,添加房源信息
      在这里插入图片描述

    4. 合理化输入房屋 ID、地址、面积、租金、状态选择未租赁,点击提交
      在这里插入图片描述

    5. 点击左侧菜单栏租赁及合同信息选项下的在租列表,选择任一一个合同,点击查看合同,进入合同详情页面
      在这里插入图片描述
      在这里插入图片描述

    6. 修改合同,每月交租日改为 2,点击修改按钮提交。
      在这里插入图片描述

    7. 点击租金信息下的我要收租选项,选择任一房屋,点击收租查看详情
      在这里插入图片描述
      在这里插入图片描述

    8. 点击菜单栏租客已缴租金,输入姓名李四,查询租客信息
      在这里插入图片描述

    9. 点击退出登录按钮,测试结束

    测试步骤

    1. Selenium 脚本录制
    2. 导出Junit测试
    3. 完善脚本
    // 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(