package solution;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
public class SubmitTest {
WebDriver driver;
@BeforeClass
public void beforeClass() {
System.setProperty("webdriver.gecko.driver","/home/pg_user/Desktop/geckodriver");
driver = new FirefoxDriver();
driver.get("http://localhost:8080/application/index.html");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
@test(priority = 1)
public void test1() throws IOException {
System.out.println("Title of current page is" + driver.getTitle());
File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File("/home/pg_user/Desktop/AdditionalSuppliedFiles/Screenshots/Image.PNG"));
}
@test(priority = 2)
public void test2() throws Exception {
FileInputStream fis = new FileInputStream("/home/pg_user/Desktop/AdditionalSuppliedFiles/Data.xls");
HSSFWorkbook wb=new HSSFWorkbook(fis);
HSSFSheet sheet=wb.getSheet("Sheet1");
int noofrows=sheet.getLastRowNum()-sheet.getFirstRowNum();
driver.findElement(By.id("indexF")).click();
driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/div[3]/label")).click();
driver.findElement(By.id("btn1")).click();
for (int i = 1; i <= noofrows; i++) {
Row row = sheet.getRow(i);
String name = row.getCell(0).getStringCellValue();
String email = row.getCell(1).getStringCellValue();
driver.findElement(By.id("name")).clear();
driver.findElement(By.id("name")).sendKeys(name);
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("email")).sendKeys(email);
driver.findElement(By.id("stuRadio")).click();
Select college = new Select( driver.findElement(By.id("pSelect1")));
college.selectByVisibleText("RTU");
Select yearofpassing = new Select( driver.findElement(By.id("pSelect2")));
yearofpassing.selectByVisibleText("2013");
driver.findElement(By.id("payNow")).click();
System.out.println(driver.findElement(By.id("successForm")).getText());
}
wb.close();
fis.close();
}
@test(priority = 3)
public void test3() {
SoftAssert softAssert = new SoftAssert();
driver.findElement(By.id("enrollS")).click();
WebElement table=driver.findElement(By.id("offerTable"));
List rows=table.findElements(By.tagName("tr"));
for(int i=1;i
List cols=rows.get(i).findElements(By.tagName("td"));
System.out.println(cols.get(0).getText()+cols.get(1).getText()+cols.get(2).getText());
}
softAssert.assertEquals(driver.getTitle(), "Learn Online:Offers");
softAssert.assertAll();
}
@AfterClass
public void afterClass() {
driver.close();
driver.quit();
}
}
Top comments (0)