zoukankan      html  css  js  c++  java
  • 第四次博客园作业(2)

    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="zhuo" type="text" name="username"><br><br>
                密 码:<input id="wx" type="text" name="password"><br><br>
                <input type="submit" id="zwx" value="登录">
                </div>
            </form>
        </body>
    </html>

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

    insert into user values(34,'zhuowenxiang','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", "D:火狐1firefox.exe");
      
            //打开火狐浏览器
            WebDriver driver = new FirefoxDriver();


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

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

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

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

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

  • 相关阅读:
    pymongo中的连接操作:Connection()与MongoClient()
    Dynamics CRM2016 新功能之从CRM APP通过电子邮件发送页面链接
    [开发工具]_[Sublime Text 2]_[配置C++编译执行环境]
    struts2 全局拦截器,显示请求方法和參数
    A. Polo the Penguin and Strings
    linux驱动之LED驱动_1
    dbgrid控件如何能在左边显示行号?
    软件提示“没有活动事务”原因以及解决办法
    刷新dbgrid 而不失去当前行位置
    用ClientDataSet更新数据表,怎样自动生成行号? [问题点数:40分]
  • 原文地址:https://www.cnblogs.com/wx163/p/5545119.html
Copyright © 2011-2022 走看看