java 菲洛实施
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31497755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fillo Implementation
提问by Groax
I came across a really nice and simple xls and xlsx implementation API called Fillo. I've made a spread sheet with the following values as most people know the all caps sections are for category names to seac
我遇到了一个非常好的和简单的 xls 和 xlsx 实现 API,称为 Fillo。我制作了一个带有以下值的电子表格,因为大多数人都知道所有大写部分都是用于分类名称的
USERID PASS
joe bigjoe
jim bigjim
john bigjohn
Now here's the code:
现在这里是代码:
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();
}
}
The login function should go through the USERID column first and once it finds that it will check the corresponding PASS value. So if it found "jim" as the user it then check for "bigjim" as the password.
登录函数应该首先遍历USERID列,一旦发现它就会检查相应的PASS值。因此,如果它找到“jim”作为用户,则检查“bigjim”作为密码。
So the big question would be: How would I set something like this up?
所以最大的问题是:我将如何设置这样的东西?
Here's the Fillo Documentation.
这是Fillo 文档。
All the best,
一切顺利,
Groax
格罗克斯
回答by nitin dubey
you can try this... It's not completely customized but it will help...
你可以试试这个......它不是完全定制的,但它会有所帮助......
public static void selectData(String tcid,String fieldName) throws FilloException{
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();
}
回答by Nitin Dubey
You will have to arrange your table like database as fillo works like database. Put everything related to a test case in a row. as attached.
你将不得不像数据库一样安排你的表,因为fillo像数据库一样工作。将与测试用例相关的所有内容排成一行。如附件。
below is the code for reader and calling the login class.
下面是阅读器和调用登录类的代码。
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);
}
}
Now here is the code of login
现在这里是登录代码
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();
}
}
I hope it makes sense. Please ignore the commented code. sorry for that.
我希望这是有道理的。请忽略注释代码。对不起。
Thanks Nitin
谢谢尼丁