WebDriver Login 登录测试用例

来源:互联网 发布:js实现文件下载功能 编辑:程序博客网 时间:2024/05/23 20:23

//调用测试数据

//这里存放的是页面元素

    String elementsFeatureFile = "./src/elements.properties";

//这里存放的是网站地址

    String programConfigFile = "./src/config.properties";

//这里存放的是测试数据

    String testDataFile = "./src/data.properties";

//这里存放的是测试报告

    String resultRecordeFile = "./src/VerifyResult";

//调用 FileController此类主要用于记录文件

    FileController fct = new FileController();

//吧WebDriver设成为公共类防止重复调用起来麻烦

WebDriver webDriver = null;

//下面是登录代码

@Test
    public void GoLogin() throws Exception{
     
        ArrayList<String> recordeList = new ArrayList<String>();
        recordeList.add("<-------------------登录验证-------------->");
        driverFactory dv = new driverFactory();
        //寻找页面元素

         //elepathList立是占位符对应着data.properties里的数据
        String[] elePathList = {"ele_loginMobile" , "eke_loginVerifyCode","ele_loginVerifyCodeBtn","ele_loginBth"};
        String[] eleNameList = {"登录 - 电话输入","登录 -验证输入","登录-发送验证码按钮","登录-登录按钮"};
        //验证元素是否存在
        for(int i=0; i<elePathList.length; i++){
            if(dv.isElementExsit(webDriver, elePathList[i], eleNameList[i])){
            recordeList.add("goLogIn pass >>" + eleNameList[i]);
        }else{
                recordeList.add("goLogIn Fail >>" +eleNameList[i]);
            }
    }
        //提取页面的元素
        WebElement elementName = webDriver.findElement(By.xpath(fct.configgeter(elementsFeatureFile,"ele_loginMobile")));
        //提取测试数据
        String dataName = fct.configgeter(testDataFile, "LoginName");
        //吧测试数据提取到输入框中
        elementName.sendKeys(dataName);
        
        WebElement elementPassword = webDriver.findElement(By.xpath(fct.configgeter(elementsFeatureFile,"eke_loginVerifyCode")));
        String dataPassword = fct.configgeter(testDataFile, "LoginPassword");
        elementPassword.sendKeys(dataPassword);
        
        //点击登录按钮进项验证
        WebElement element = webDriver.findElement(By.xpath(fct.configgeter(elementsFeatureFile,"ele_loginBth")));
        element.click();
            
        Thread.sleep(100);
            //吧测试结果进项打印
        fct.recorder(resultRecordeFile, recordeList);
            
        Thread.sleep(10000);        
    }
@BeforeMethod
    public void beforeMethod() throws Exception{

//给webDriver输值

        driverFactory df = new driverFactory("firefox");
        webDriver = df.getWebDriver();

//吧网页的地址给WebDriver

        webDriver.get(fct.configgeter(programConfigFile, "LoginUrl"));
        Thread.sleep(5000);
    }


0 0