Export Result to Excel Either login pass of fail

import java.io.FileInputStream;
import java.io.FileOutputStream;

import com.thoughtworks.selenium.DefaultSelenium;

import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class Export_Login {
public static String status = "pass";
public static String export() throws Exception {
FileInputStream file = new FileInputStream(
"D:\\Framework\\TestData\\login_Data.xls");
Workbook w = Workbook.getWorkbook(file);
Sheet s = w.getSheet(0);
FileOutputStream fo = new FileOutputStream(
"D:\\Framework\\Results\\Loginout.xls");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("login", 0);
String a[][] = new String[s.getRows()][s.getColumns()];
DefaultSelenium selenium = new DefaultSelenium("localhost", 6666,
"*iehta", "http://");
selenium.start();
selenium.open("http://mail.in.com");
selenium.windowMaximize();

for (int i = 0; i < s.getRows(); i++) {
selenium.type("f_id", s.getCell(0, i).getContents());
selenium.type("f_pwd", s.getCell(1, i).getContents());
selenium.click("//input[@value='' and @type='submit']");
Thread.sleep(10000);
if (selenium.isElementPresent("link=Sign out")) {
selenium.click("link=Sign out");
Thread.sleep(6000);
status = "Pass";
System.out.println("if loop" + status);
} else {
status = "Fail";
System.out.println("else loop" + status);
}
for (int j = 0; j < s.getColumns(); j++) {

a[i][j] = s.getCell(j, i).getContents();
Label l = new Label(j, i, a[i][j]);
Label Res = new Label(2, 0, "Result");
Label rs = new Label(2, i, status);
ws.addCell(l);
ws.addCell(Res);
ws.addCell(rs);
System.out.println("The contents are" + a[i][j]);
}
selenium.open("http://mail.in.com");
}
wwb.write();
wwb.close();
return "pass";
}

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub

export();
}

}

1 comment: