zoukankan      html  css  js  c++  java
  • 实验5

    2、利用Selenium2为Lab05项目中的登录功能实现功能自动化测试。

    【注意】

    l         设计测试用例时需考虑登录成功和不成功两种情况;

    l         Lab05项目为实验5用到的项目,在大家的班级QQ群中,数据库采用MySQL,数据库文件在项目根目录下CreateDataBase.txt

    <html>
        <head><title>用户登录</title></head>
        <body>
            <form action="validate.jsp" method="post">
                <div align="center">
                用户登录<br><br>
                用户名:<input id="cai" type="text" name="username"><br><br>
                 码:<input id="yan" type="text" name="password"><br><br>
                <input type="submit" id="yy" value="登录">
                </div>
            </form>
        </body>
    </html>

    将自己的信息添加到数据库

    insert into user values(3,'caiyanqiong','123456');

    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 org.openqa.selenium.ie.InternetExplorerDriver;
    import org.openqa.selenium.support.ui.WebDriverWait;


    public class Test{

           @Test
     public void First(){

            System.setProperty("webdriver.firefox.bin", "E:火狐1firefox.exe");
      
            //打开火狐浏览器
            WebDriver driver = new FirefoxDriver();


            //打开要测试的页面
            driver.get("http://localhost:8080/Lab05/login.jsp");

            //设置等待超出的时间(100秒)
            WebDriverWait wait = new WebDriverWait(driver, 100);

          //找到用户名输入框,id为cai,并自动输入用户名
            WebElement txtSearchBox = driver.findElement(By.name("cai")).sendKeys("caiyanqiong");
        //找到密码输入框,id为yan,并自动输入密码
            WebElement txtSearchBox = driver.findElement(By.name("yan")).sendKeys("123456");

        //找到登录按钮,id为yy并点击它
            WebElement btn = driver.findElement(By.id("yy")).click();

            //关闭浏览器
            //driver.close();
            
        }
        
    }

  • 相关阅读:
    克服 iOS HTML5 音频的局限
    oracle__删除重复记录__三种方法及总结(转载百度文库)
    Oracle 字符集
    无法通过网页进入em
    Ubuntu 12.04(32位)安装Oracle 11g(32位)全过程以及几乎所有问题的解决办法
    正则表达式30分钟入门教程
    linux下安装jdk
    QTP相关书籍
    假的数论gcd,真的记忆化搜索(Codeforce 1070- A. Find a Number)
    搜索基础_HDU1312_dfs_递归+stack实现+bfs_queue实现
  • 原文地址:https://www.cnblogs.com/mydoc/p/5538367.html
Copyright © 2011-2022 走看看