6- IVS SELENIUM ADVANCED
Potato, Tomato, Onion
package day1;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
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.DataProvider;
import org.testng.annotations.Test;
public class mock {
WebDriver driver;
@BeforeClass
public void setup() {
System.setProperty("webdriver.gecko.driver","/home/user/Desktop/geckodriver");
driver=new FirefoxDriver();
driver.get(http://localhost:8080/application/);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
@DataProvider(name="data")
public Object[][] getData()
{
Object[][] a=new Object[3][2];
a[0][0] =abc@gmail.com;
a[0][1]="password1";
a[1][0]=xyz@ymail.com;
a[1][1]="password2";
a[2][0]=sap@rediff.com;
a[2][1]="password3";
return a;
}
@test(dataProvider="data",dependsOnMethods= {"setup"})
public void Test0l (String email, String password) {
driver.findElement(By.id("emailLogin")).sendKeys(email);
driver.findElement(By.id("passwordLogin")).sendKeys (password);
driver.findElement(By.id("login")).click();
}
@test (dependsOnMethods= {"Test01"})
public void Test02() throws IOException {
int num=driver.getWindowHandles().size();
System.out.println("the number of windows:"+num);
String title = driver.getTitle();
System.out.println(title);
WebElement table=driver.findElement(By.xpath("/html/body/div[1]/div[1]/table"));
List rows=table.findElements(By.tagName("tr"));
for(int i=0;i<=1;i++) {
List cols=rows.get(i).findElements(By.tagName("td"));
for(int j=0;j<3;j++) {
String value=cols.get(j).getText();
System.out.print(value+"");
}
System.out.println();
}
WebElement c=driver.findElement(By.id("contentDD"));
Select e=new Select(c);
List list=e.getOptions();
int size=list.size();
for(int i=0;i
String option =list.get(i).getText();
System.out.println(option);
}
WebElement d=driver.findElement(By.id("quantityDD"));
Select f=new Select(d);
e.selectByVisibleText("Potato");
f.selectByVisibleText("2" );
driver.findElement(By.id("addItem")).click();
e.selectByVisibleText("Tomato");
f.selectByVisibleText("2");
driver.findElement(By.id("addItem")).click();
e.selectByVisibleText("Onion");
f.selectByVisibleText("2");
driver.findElement(By.id("addItem")).click();
e.selectByVisibleText("Beans");
f.selectByVisibleText("2");
driver.findElement(By.id("addItem")).click();
FileInputStream file=new FileInputStream("/home/user/Desktop/user_repo/To_Participant/Additional Supplied File ");
XSSFWorkbook book = new HSSFWorkbook (file);
XSSFSheet sheet=book.getSheet("Sheet1");
WebElement table1=driver.findElement(By.id("myCart"));
List row=table1.findElements (By.tagName ("tr"));
for(int g=1;g<=4;g++) {
XSSFRow e_row=sheet.getRow(g);
List t_cols=row.get(g).findElements(By.tagName("td"));
for(int l=0;l<=2;l++) {
XSSFCell cells=e_row.createCell(l);
String cart=t_cols.get(1).getText();
cells.setCellValue(cart);
}
}
FileOutputStream fos=new FileOutputStream("/home/user/Desktop/user_repo/To Participant/Additional suppliedFil.FILE");
book.write(fos);
book.close();
driver.findElement(By.id("calculateTotal")).click();
String msg=driver.switchTo().alert().getText();
System.out.println(msg);
driver.switchTo().alert().accept();
}
@test(dependsOnMethods= {"Test02"})
public void Test03() {
driver.findElement(By.linkText("Logout")).click();
}
@AfterClass (dependsOnMethods={"Test03"})
public void teardown() {
driver.close();
driver.quit();
}
}
Top comments (0)