I am trying to write a code in which, i am reading the contents of an excel and i have to use the values from the excel and pass it to my Robotium test case.
Here's my code :
The ReadExcel class : // reads the value of the 3rd column 2nd row and also the 4th column and the 2nd row
public class ReadExcel {
private String user,pass;
public void read() throws BiffException, IOException
{
Workbook wrk1 = Workbook.getWorkbook(new File("D:/Robo/Book1.xls"));
Sheet sheet1 = wrk1.getSheet(0);
Cell username = sheet1.getCell(2,1); // the username from the excel
Cell password = sheet1.getCell(3,1); // the password from the excel
setUser(username.getContents());
setPass(password.getContents());
}
public void setUser(String user) {
this.user = user;
}
public String getUser() {
return user;
}
public void setPass(String pass) {
this.pass = pass;
}
public String getPass() {
return pass;
}
}
Here's the test script using Robotium
import android.test.ActivityInstrumentationTestCase2;
import com.ifs.banking.fiid5015.test.ReadExcel;
import com.robotium.solo.Solo;
@SuppressWarnings("rawtypes")
public class FSBTest extends ActivityInstrumentationTestCase2 {
private Solo solo;
private String user,pass;
private static final String TARGET_PACKAGE_ID = "com.ifs.banking.fiid5015";
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.banking.activities.LoginActivity";
private static Class<?> launcherActivityClass;
static {
try {
launcherActivityClass = Class
.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@SuppressWarnings({ "deprecation", "unchecked" })
public FSBTest() throws ClassNotFoundException {
super(TARGET_PACKAGE_ID, launcherActivityClass);
}
@Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
public void testApp() {
ReadExcel rd= new ReadExcel(); // creating the object for Read excel class
rd.read();
user = rd.getUser(); //passing the username
pass = rd.getPass(); //passing the password
// Login to the application
solo.enterText(0,user); // Enter user name
solo.sleep(1000);
solo.enterText(1, "dsf");
solo.sleep(1000);
solo.clickOnButton(1); // Try Login! (bad login)
solo.sleep(10000);
solo.clickOnButton("OK");
solo.sleep(5000);
solo.enterText(1,pass); // Enter Password (authentic password)
solo.sleep(5000);
solo.clickOnButton(1); // Try Login! (Valid login)
solo.sleep(10000);
// MFA
solo.clickOnButton(0); // choose Text Me (xxx-xxx-3576)
solo.sleep(20000);
solo.clickOnButton(0);
solo.sleep(20000);
}
@Override
public void tearDown() throws Exception {
try {
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}
When i try to run my project, I encounter a java.lang.FileNotFoundExceptionand it seems that i am unable to fetch the values from the excel. Basically i am stuck here. Kindly help!
Thanks!