Skip to content

Commit f722d27

Browse files
committed
ApachePoiExcelFeat
1 parent f556390 commit f722d27

5 files changed

Lines changed: 35 additions & 0 deletions

File tree

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@
6161
<version>1.18.22</version>
6262
</dependency>
6363

64+
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
65+
<dependency>
66+
<groupId>org.apache.poi</groupId>
67+
<artifactId>poi</artifactId>
68+
<version>5.2.3</version>
69+
</dependency>
70+
6471
</dependencies>
6572

6673
<build>

src/main/java/utils/WebActions.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package utils;
22

33
import com.microsoft.playwright.Locator;
4+
import org.apache.poi.ss.usermodel.Sheet;
5+
import org.apache.poi.ss.usermodel.Workbook;
6+
import org.apache.poi.ss.usermodel.WorkbookFactory;
47

8+
import java.io.File;
9+
import java.io.IOException;
510
import java.util.Base64;
611
import java.util.Properties;
712

@@ -51,4 +56,16 @@ public static String decrypt(String passwordField) {
5156
}
5257
return decodedString;
5358
}
59+
60+
public static String getRowColValue(String filePath, String sheetName, int rowNum, int colNum) {
61+
String fileName = System.getProperty("user.dir") + "\\src\\main\\java\\utils\\functional\\" + filePath + ".xlsx";
62+
Workbook workbook = null;
63+
try {
64+
workbook = WorkbookFactory.create(new File(fileName));
65+
} catch (IOException e) {
66+
throw new RuntimeException(e);
67+
}
68+
Sheet sheet = workbook.getSheet(sheetName);
69+
return sheet.getRow(rowNum).getCell(colNum).getStringCellValue();
70+
}
5471
}
8.09 KB
Binary file not shown.

src/test/java/stepdefinitions/LoginSteps.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.cucumber.java.en.When;
77
import org.junit.Assert;
88
import pages.LoginPage;
9+
import utils.WebActions;
910

1011
public class LoginSteps {
1112
LoginPage loginPage = new LoginPage(DriverFactory.getPage());
@@ -39,4 +40,10 @@ public void clickOnIcon(String iconName) {
3940
public void verifyProfilePage() {
4041
Assert.assertTrue(loginPage.verifyProfilePage());
4142
}
43+
44+
@Then("^user verifies data as \"([^\"]*)\" in \"([^\"]*)\" row and \"([^\"]*)\" column from \"([^\"]*)\" sheet in \"([^\"]*)\" file")
45+
public void clickOnIcon(String expectedValue, int rowNum, int colNum, String sheetName, String fileName) {
46+
String actualValue = WebActions.getRowColValue(fileName, sheetName, rowNum, colNum);
47+
Assert.assertEquals(expectedValue, actualValue);
48+
}
4249
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Feature: Read from Excel File
2+
3+
Scenario: Get value from specified Row and Column from xlsx file
4+
Then user verifies data as "John" in "1" row and "1" column from "Sheet1" sheet in "Students" file

0 commit comments

Comments
 (0)