Fillo实施

时间:2015-07-19 03:34:33

标签: java authentication import-from-excel

我遇到了一个名为Fillo的非常简单的xls和xlsx实现API。我制作了一张带有以下数值的电子表格,因为大多数人都知道所有大写字母部分都是针对seac的类别名称

USERID    PASS
joe       bigjoe
jim       bigjim
john      bigjohn

现在这里是代码:

    import Exception.FilloException;
    import Fillo.*;


  public class CallBack {
    public static void main(String args[]) throws FilloException {
        testFillo();
    }

    private static void testFillo() throws FilloException {
        Fillo fillo=new Fillo();
        Connection connection=fillo.getConnection("logindatabase.xls");
        String strQuery="Select * from Sheet1 where USERID='*' and PASS='*'";
        Recordset recordset=connection.executeQuery(strQuery);

        /*
         * I'm wanting the login check to be right here
         */

        recordset.close();
        connection.close();

    }
}

登录功能应首先通过USERID列,一旦发现它将检查相应的PASS值。因此,如果它找到“jim”作为用户,则检查“bigjim”作为密码。

所以最大的问题是:我怎么设置这样的东西?

这是Fillo Documentation

一切顺利,

Groax

2 个答案:

答案 0 :(得分:0)

你可以尝试一下......它没有完全定制,但它会有所帮助......

public static void selectData(String tcid,String fieldName)抛出FilloException {

    Fillo fillo=new Fillo();
    Connection connection=fillo.getConnection("testdata//testcasedata.xlsx");
    String strQuery="Select * from data where TCID='"+tcid+"'";
    Recordset recordset=connection.executeQuery(strQuery);
    while(recordset.next()){
        ArrayList<String> dataColl=recordset.getFieldNames();
        //System.out.println(dataColl);
        Iterator<String> dataIterator=dataColl.iterator();
        //System.out.println(dataColl.size());  

        while(dataIterator.hasNext()){
            for (int i=0;i<=dataColl.size()-1;i++){
                //System.out.println(i);
                String data=dataIterator.next();
                String dataVal=recordset.getField(data);

                if (dataVal.equalsIgnoreCase(fieldName)){
                    //System.out.println("passed");
                    i=i+1;
                    //System.out.println(i);
                    String testData=dataColl.get(i);
                    System.out.println(recordset.getField(testData));   

                }

            }

            break;
        }
    }

    recordset.close();
    connection.close();

}

答案 1 :(得分:0)

你必须像数据库那样安排你的表,就像数据库一样。 将与测试用例相关的所有内容放在一行中。附上。

下面是读者的代码并调用登录类。

        package com.evs.vtiger.framework.util;

        import java.util.ArrayList;
import java.util.Iterator;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;

import com.evs.vtiger.framework.pages.home.myhomepage.HomePage;

import Exception.FilloException;
import Fillo.Connection;
import Fillo.Fillo;
import Fillo.Recordset;
import com.evs.vtiger.framework.pages.login.login.LoginPage;

public class TestingFillo {

    public static void main(String[] args) throws FilloException {

        WebDriver driver=new FirefoxDriver();
        driver.manage().window().maximize();
        driver.get("http://localhost:8080/NBOWeb");
        LoginPage lpObj=PageFactory.initElements(driver, LoginPage.class);
        lpObj.pg_ValidLogin("TC001");

    }

    public static String getTestValue(String TCID, String fieldName) throws FilloException{

        String testString=xlTesting(TCID, fieldName);
        return testString;

    }

    public static String xlTesting(String tcid,String fieldName) throws FilloException{
        String testval=null;
        Fillo fillo=new Fillo();
        Connection connection=fillo.getConnection("TestData//TestData.xlsx");
        String strQuery="Select * from data where TCID='"+tcid+"'";
        Recordset recordset=connection.executeQuery(strQuery);
        while(recordset.next()){
            ArrayList<String> dataColl=recordset.getFieldNames();
            //System.out.println(dataColl);
            Iterator<String> dataIterator=dataColl.iterator();
            //System.out.println(dataColl.size());  

            while(dataIterator.hasNext()){
                for (int i=0;i<=dataColl.size()-1;i++){
                    //System.out.println(i);
                    String data=dataIterator.next();
                    String dataVal=recordset.getField(data);

                    if (dataVal.equalsIgnoreCase(fieldName)){
                        //System.out.println("passed");
                        i=i+1;
                        //System.out.println(i);
                        String testData=dataColl.get(i);
                        //System.out.println(recordset.getField(testData));   
                        String testValue= recordset.getField(testData);
                        testval=testValue;
                    }

                }

                break;
            }
        }

        recordset.close();
        connection.close();
        return testval; 
    }


    public static void inputText(WebElement we, String fieldName, String TCID) throws FilloException{
        String fval=getTestValue(TCID, fieldName);
        we.sendKeys(fval);

    }


}

现在这里是登录代码

  package com.evs.vtiger.framework.pages.login.login;
    import org.openqa.selenium.WebElement;

import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import Exception.FilloException;

import com.evs.vtiger.framework.pages.home.myhomepage.HomePage;
import com.evs.vtiger.framework.util.TestingFillo;
import com.evs.vtiger.framework.util.UI;
import com.evs.vtiger.framework.util.XLReader;

public class LoginPage {

    @FindBy(name="username")
    public WebElement UserName_ED;

    @FindBy(xpath="//input[@type='password']")
    public WebElement Password_ED;

    @FindBy(xpath="//input[@value='login']")
    public WebElement Login_BT;



    public void pg_ValidLogin(String TCID) throws FilloException {
        /*UI.fn_Input(UserName_ED, "UserName_ED");
        UI.fn_Input(Password_ED, "Password_ED");
        UI.fn_Click(Login_BT);*/

        //UserName_ED.sendKeys("abc");


        TestingFillo.inputText(UserName_ED, "UserName_ED", TCID);
        TestingFillo.inputText(Password_ED, "Password_ED", TCID);
        Login_BT.click();

       // HomePage hpObj=PageFactory.initElements(UI.driver, HomePage.class);
       // return hpObj;
    }

    public void pg_InValidLogin() {
        UserName_ED.sendKeys("rahul");
        Password_ED.sendKeys("admin");
        Login_BT.click();
    }

}

我希望这是有道理的。请忽略评论的代码。对不起。

由于 尼丁