[Currently: 2017/05/12] Selenium 3.4.0 Describes the process of reading an xlsx file in a Java environment.
Specifies the table title and tab name in the xlsx file.
TestSheet.java
import java.util.List;
import net.java.amateras.xlsbeans.annotation.HorizontalRecords;
import net.java.amateras.xlsbeans.annotation.Sheet;
@Sheet(name="test") //Tab name
public class TestSheet {
@HorizontalRecords(tableLabel="List", recordClass=TestData.class) //Table title
public List<TestData> testDataList;
}
Assign table column names to variables
TestData.java
import net.java.amateras.xlsbeans.annotation.Column;
public class TestData {
@Column(columnName="No")
public String no;
@Column(columnName="TestCase")
public String test_case;
}
Call and execute each class
GetXlsxData.java
@RunWith(Parameterized.class)
public class GetXlsxData{
private TestData testData; //Test parameter Corresponds to one record of Excel
//constructor
public GetXlsxData(TestData testData){
this.testData = testData;
}
@Parameters
//Test case generation from excel
public static List<TestData[]> data() throws Exception {
//Read Excel file
TestSheet sheet = new XLSBeans().load(new FileInputStream("./testCase/selenium_testlist.xlsx"), TestSheet.class, WorkbookFinder.TYPE_XSSF);
//Parameters settings
List<TestData[]> list = new ArrayList<TestData[]>();
for (TestData testData : sheet.testDataList) {
list.add(new TestData[] { testData });
}
return list; //Return to constructor: Set(TestData testData)
}
}
I wrote it quite a bit. There are no @Before, @Rule, @After, @Test, etc., so please add them yourself.
that's all.
Recommended Posts