public class Forum {
Sheet s1;
boolean visible;
Sheet s2;
WebDriver driver;
private String baseUrl;
//boolean present;
/** @param
$newColour
*/
@Test(dependsOnMethods={"testTwo","testThree"})
public void testOne()
throws Exception {
FileInputStream f1 = new
FileInputStream("D:\\ExcelWork\\TestDataForum.xls");
Workbook w = Workbook.getWorkbook(f1);
s1 =
w.getSheet(0);
s2=
w.getSheet(1);
File f2 = new File("D:\\ExcelWork\\TestData.xls");
WritableWorkbook writableWorkbook =
Workbook.createWorkbook(f2);
WritableSheet writableSheet =
writableWorkbook.createSheet("Login",0);
writableSheet.getSettings().setDefaultColumnWidth(27);
WritableFont redFont = new
WritableFont(WritableFont.TAHOMA);
redFont.setColour(Colour.RED);
WritableCellFormat cellFormat = new
WritableCellFormat(redFont);
WritableFont greenFont = new
WritableFont(WritableFont.COURIER);
greenFont.setColour(Colour.GREEN);
WritableCellFormat cellFormat1 = new
WritableCellFormat(greenFont);
String a[][] = new String[s1.getRows()][s1.getColumns()];
System.out.println("s1.getRows()
= " + s1.getRows());
for (int i = 0; i
< s1.getRows(); i++) {
System.out.println("s1.getColumns
= " + s1.getColumns());
for (int j = 0; j
< s1.getColumns(); j++) {
a[i][j] = s1.getCell(j,
i).getContents();
Label l = new Label(j,
i, a[i][j]);
Label l1 = new Label(4,
1, "Result");
writableSheet.addCell(l);
writableSheet.addCell(l1);
}
}
for(int row=2;
row <s1.getRows();row++)
{
/*System.setProperty("webdriver.Ie.driver","D:/Driver/IEDriverServer.exe");
WebDriver
driver = new InternetExplorerDriver();*/
System.setProperty("webdriver.firefox.driver", "C:/Users/prasanthi/AppData/Local/Mozilla
Firefox/firefox.exe");
driver = new
FirefoxDriver();
baseUrl = "http://w3schools.invisionzone.com";
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30,
TimeUnit.SECONDS);
driver.get(baseUrl + "/");
driver.findElement(By.id("sign_in")).click();
Thread.sleep(1000);
for (String
Handle : driver.getWindowHandles())
{
WebDriver popup= driver.switchTo().window(Handle);
popup.getTitle();
}
driver.findElement(By.id("ips_username")).clear();
String username = s1.getCell(2,
row).getContents();
System.out.println("Username
"+username);
driver.findElement(By.id("ips_username")).sendKeys(username);
driver.findElement(By.id("ips_password")).clear();
String password= s1.getCell(3,
row).getContents();
System.out.println("Password
"+password);
driver.findElement(By.id("ips_password")).sendKeys(password);
driver.findElement(By.cssSelector("input.ipsButton")).click();
driver.manage().timeouts().implicitlyWait(30,
TimeUnit.SECONDS);
boolean t = driver.findElement(By.tagName("body")).getText().contains("Username
or password incorrect.");
if(t)
{
Label l3 = new Label(4,
row, "Fail",cellFormat);
writableSheet.addCell(l3);
System.out.println("Login
Fail");
Thread.sleep(1000);
} else {
Label l2 = new Label(4,
row, "Pass",cellFormat1);
writableSheet.addCell(l2);
System.out.println("Login
Success");
driver.findElement(By.cssSelector(".ipsList_inline.right>li>a")).click();
Thread.sleep(1000);
}
driver.close();
}
writableWorkbook.write();
writableWorkbook.close();
Desktop.getDesktop().open(f2);
}
@Test
public void
testTwo(){
System.out.println("TestTwo
method");
}
@Test
public void
testThree(){
System.out.println("TestThree
method");
}
@AfterTest
public void
tearDown() throws Exception {
driver.quit();
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.