java Fillo实施

k97glaaz  于 2023-06-28  发布在  Java
关注(0)|答案(2)|浏览(95)

我遇到了一个非常好和简单的xls和xlsx实现API称为Fillo。我做了一个电子表格与以下的价值观,因为大多数人都知道,所有的上限部分是类别名称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
一切顺利
格罗阿

6vl6ewon

6vl6ewon1#

你可以试试这个它不是完全定制的,但它会帮助...
public static void setName(String getName,String getName){

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();

}
guykilcj

guykilcj2#

你必须像数据库一样安排你的表,因为fillo像数据库一样工作。将与测试用例相关的所有内容放在一行中。附件。
下面是reader和调用login类的代码。

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();
    }

}

我希望这有意义。请忽略注解代码。对不起。
谢谢尼丁

相关问题