Read xlsx file in Java with Selenium

[Currently: 2017/05/12] Selenium 3.4.0 Describes the process of reading an xlsx file in a Java environment.

Rough overview

  1. Create a class with the xlsx table title and tab name
  2. Assign table column names to variables
  3. Call and execute each class

I will write it quickly

Specifies the table title and tab name in the xlsx file.

import java.util.List;


@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


public class TestData {
    public String no;

    public String test_case;

Call and execute each class

public class GetXlsxData{
	private TestData testData;        //Test parameter Corresponds to one record of Excel

	public GetXlsxData(TestData testData){
		this.testData = testData;

    //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

Read xlsx file in Java with Selenium
Read a string in a PDF file with Java
Read JSON in Java
[Java] Read the file in src / main / resources
Read binary files in Java 1
Include image in jar file with java static method
Read standard input in Java
[Java] Get the file path in the folder with List
Read binary files in Java 2
[Java] [Android] Read ini file
How to read your own YAML file (*****. Yml) in Java
Easily read text files in Java (Java 11 & Java 7)
Morphological analysis in Java with Kuromoji
[For beginners] Run Selenium in Java
Read CSV in Java (Super CSV Annotation)
Read dump file with Docker MySQL
Log output to file in Java
Follow the link with Selenium (Java)
EXCEL file update sample with JAVA
About file copy processing in Java
Play with Markdown in Java flexmark-java
Text file placed in resources in Java cannot be read when jarted
Read items containing commas in a CSV file without splitting (Java)
Sample to read and write LibreOffice Calc fods file in Java 2021
Concurrency Method in Java with basic example
Read Felica using RC-S380 (PaSoRi) in Java
Split a string with ". (Dot)" in Java
Working with huge JSON in Java Lambda
Sample to unzip gz file in Java
For the time being, run the war file delivered in Java with Docker
How to read log4j configuration file in Java project summarized in jar file Memo
Java that outputs vmg format file in eml format
Let's write Java file input / output with NIO
Create a CSR with extended information in Java
Refactored GUI tools made with Java8 + JavaFX in 2016
Partization in Java
Static code analysis with Checkstyle in Java + Gradle
Selenium sample (Java)
Read environment variables with ruby ​​file [Super beginner]
Changes in Java 11
Automate IE11 / Edge file downloads with Selenium WebDriver
Rock-paper-scissors in Java
Text extraction in Java from PDF with pdfbox-2.0.8
Build an E2E test environment with Selenium (Java)
Selenium x Java
Capture and save from selenium installation in Java
Add, read, and delete Excel comments in Java
java file creation
Practice working with Unicode surrogate pairs in Java
[JAVA] [Spring] [MyBatis] Use IN () with SQL Builder
Pi in Java
Encrypt / decrypt with AES256 in PHP and Java
FizzBuzz in Java
Programming with direct sum types in Java (Neta)
[Java] Convert and import file values with OpenCSV
Get along with Java containers in Cloud Run
[Java] Integer information of characters in a text file acquired by the read () method
How to save a file with the specified extension under the directory specified in Java to the list
<java> Read Zip file and convert directly to string
How to call functions in bulk with Java reflection
Read the packet capture obtained by tcpdump in Java