package solution;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
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.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.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
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/Welcome.html");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
@test
public void test1() throws Exception {
System.out.println("Title of current page is"+ driver.getTitle());
File file=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File("/home/pg_user/Desktop/AdditionalSuppliedFiles/Screenshots/welcome.png"));
driver.findElement(By.id("npage2")).click();
driver.findElement(By.id("radioVariety2")).click();
driver.findElement(By.id("quantity23")).clear();
driver.findElement(By.id("quantity23")).sendKeys("3");
driver.findElement(By.id("check23")).click();
driver.findElement(By.id("orderButton")).click();
WebElement price=driver.findElement(By.id("para1"));
String b=price.getText().split(":")[1].trim();
SoftAssert sa=new SoftAssert();
sa.assertEquals(b, "190");
sa.assertAll();
System.out.println("Total price value calculated" +b);
}
@test
public void test2() throws Exception {
FileInputStream fis=new FileInputStream("/home/pg_user/Desktop/AdditionalSuppliedFiles/Data.xls");
HSSFWorkbook workbook=new HSSFWorkbook(fis);
HSSFSheet sheet=workbook.getSheet("Details");
int noofrows=sheet.getLastRowNum()-sheet.getFirstRowNum();
driver.findElement(By.id("npage3")).click();
for(int j=1;j<=noofrows;j++) {
WebElement table=driver.findElement(By.xpath("/html/body/table"));
List rows=table.findElements(By.tagName("tr"));
for(int i=1;i
List col=rows.get(i).findElements(By.tagName("td"));
String address=col.get(1).getText();
String sheetaddress=sheet.getRow(j).getCell(1).getStringCellValue();
if(sheetaddress.startsWith("C")||sheetaddress.startsWith("G")) {
sheet.getRow(j).createCell(3).setCellValue(address);
}
if(col.get(0).getText().contains("India")) {
System.out.println(col.get(1).getText());
}
}
}
FileOutputStream fos=new FileOutputStream("/home/pg_user/Desktop/AdditionalSuppliedFiles/Data.xls");
workbook.write(fos);
workbook.close();
fos.close();
}
@DataProvider(name="inputs")
public Object[][] data(){
return new Object[][] {
{"MrNinto","9","Good"},
{"MrNarine","8","Above Average"},
{"MrNev","6","Could be better"}
};
}
@test(dataProvider="inputs")
public void test3(String cname,String rating,String comments) {
driver.findElement(By.id("npage4")).click();
driver.findElement(By.id("chefNameBox")).sendKeys(cname);
driver.findElement(By.id("ratingBox")).sendKeys(rating);
driver.findElement(By.id("commentBox")).sendKeys(comments);
driver.findElement(By.id("finalButton")).click();
SoftAssert sa1=new SoftAssert();
sa1.assertTrue(driver.findElement(By.id("finalComment")).getText().contains("Visit Again"));
sa1.assertAll();
}
@AfterClass
public void afterClass() {
driver.quit();
driver.close();
}
}
Top comments (0)