zoukankan      html  css  js  c++  java
  • 软件测试第二次上机

    实验要求:

    1、安装SeleniumIDE插件

    2、学会使用SeleniumIDE录制脚本和导出脚本

    3、访问http://www.ncfxy.com使用学号登录系统(账户名为学号,密码为学号后6位),进入系统后可以看到该用户的邮箱。

    4、编写Selenium Java WebDriver程序,测试info.csv表格中的学号和邮箱的对应关系是否正确。

    代码如下:

    import static org.junit.Assert.*;

    import java.util.concurrent.TimeUnit;

    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.firefox.FirefoxDriver;

    import java.io.FileInputStream;

    import jxl.Cell;
    import jxl.Sheet;
    import jxl.Workbook;

    public class WebDriverDemo {

    private WebDriver driver;
    private String baseUrl;

    @Before
    public void setUp() throws Exception{
    System.setProperty("webdriver.firefox.bin","E:\Program Files (x86)\Mozilla Firefox\firefox.exe");
    driver = new FirefoxDriver();
    baseUrl = "http://www.ncfxy.com";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);


    }
    @Test
    public void test() throws Exception{

    FileInputStream fis = new FileInputStream("G:/test.xls");
    // InputStream fis = new FileInputStream("G:/info.xls");
    jxl.Workbook wb = Workbook.getWorkbook(fis);

    // Sheet[] sheet = wb.getSheets();
    Sheet rs = wb.getSheet(0);
    for(int i = 0; i < rs.getRows(); i++)
    {
    Cell cellNum = rs.getCell(0, i);
    String num = cellNum.getContents();
    Cell cellMail = rs.getCell(1, i);
    String mail = cellMail.getContents();
    String password = num.substring(4, 10);


    driver.get(baseUrl);
    WebElement name = driver.findElement(By.id("name"));
    name.sendKeys(num);
    WebElement pwd = driver.findElement(By.id("pwd"));
    pwd.sendKeys(password);
    WebElement submit = driver.findElement(By.id("submit"));
    submit.click();

    WebElement element = driver.findElement(By.xpath("//td[2]"));
    String mailByWeb = element.getText();
    assertEquals(mail,mailByWeb);

    }
    fis.close();
    driver.quit();

    }

    }

    运行结果:

  • 相关阅读:
    chrome书签插件
    Js箭头函数和lambda
    CSS水平或垂直居中技巧
    前端需要注意的SEO优化
    OpenCV图像识别初探-50行代码教机器玩2D游戏
    机器学习笔记(十一)----降维
    基于Docker搭建分布式消息队列Kafka
    一个经典面试题:如何保证缓存与数据库的双写一致性?
    Flask 蓝图机制及应用
    软件开发团队如何管理琐碎、突发性任务
  • 原文地址:https://www.cnblogs.com/czyhhxx/p/5402663.html
Copyright © 2011-2022 走看看