A selenium/java rookie here. :)
Trying to understand everything about Test annotations and how to use an method (is it called that) in all classes.
I have this class below where i have a metod called in each @Test, but i would like to put as mush as possible in @BforeTest, or do it in another smart way.
Does you have any smart i de how to do this in a smart way?
Thanks in advance!
Kind regards, Fred
AS IS:
public class xlsxreadtest {
@BeforeTest
public void setup() throws Exception {
}
@Test (priority = 1)
public void Read_xslx1() throws IOException {
FileInputStream fis = new FileInputStream("./files/Test.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheetAt(0);
String text1 = sheet.getRow(2).getCell(1).toString();
System.out.println(text1);
}
@Test (priority = 2)
public void Read_xslx2() throws IOException {
FileInputStream fis = new FileInputStream("./files/Test.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheetAt(0);
String text2 = sheet.getRow(3).getCell(1).toString();
System.out.println(text2);
}
@AfterTest
public void afterTest() {
System.out.println("AfterTest : Driver close");
driver.close();
}
}
Would like something like this, where i only have to call the Excel-method, or any other, only once.
public class xlsxreadtest {
@BeforeTest
public void setup() throws Exception {
FileInputStream fis = new FileInputStream("./files/Test.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheetAt(0);
}
@Test (priority = 1)
public void Read_xslx1() throws IOException {
String text1 = sheet.getRow(2).getCell(1).toString();
System.out.println(text1);
}
@Test (priority = 2)
public void Read_xslx2() throws IOException {
String text2 = sheet.getRow(3).getCell(1).toString();
System.out.println(text2);
}
@AfterTest
public void afterTest() {
System.out.println("AfterTest : Driver close");
driver.close();
}
}
question from:
https://stackoverflow.com/questions/65901648/how-to-put-a-method-i-beforetest 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…