Raghav, your videos are very useful and you explain everything in detail. I have been watching all of your videos and they are extremely useful. Thanks for sharing your knowledge :)
You are such a awesome and great tutor and human as well... One request... Can you please put some real interviews question for those who have 2-3 years of exp in automation.... Please Raghav ji
Brother your way of explanation is as simple and easy to understand & you fully justified your channel name i.e Automation step by step- Raghav pal, it is step by step thanks a lot :)
hello Raghav, thanks for making this so easy for us beginners. I hope you are reading ur comments still. I have one question if the Excel sheet has around 5 sets of usernames and passwords how does this work. how can I use them in cucumber log in
To use multiple sets of usernames and passwords for data-driven testing in Selenium with Java and Cucumber, you can follow the below steps: Store the username and password in a data file (such as a CSV, Excel, or JSON file) with each set of credentials in a separate row or object. Read the data file in your Java code using a library such as Apache POI or OpenCSV. Use a loop to iterate through the rows or objects in the data file, and for each iteration, retrieve the username and password values and pass them as parameters to your login step in Cucumber. In your Cucumber feature file, use placeholders for the username and password parameters, such as and . Use the Cucumber Scenario Outline syntax to define the login scenario with placeholders for the username and password, and provide the values for the placeholders in a table underneath the Scenario Outline. In the step definition, retrieve the username and password values from the placeholders using the Cucumber DataTable API. Here is an example of how the Cucumber feature file, step definition, and data file could look like: *Login.feature* Feature: User login Scenario Outline: Login with valid credentials Given I am on the login page When I enter "" and "" And I click the login button Then I should be logged in Examples: | username | password | | user1 | pass1 | | user2 | pass2 | | user3 | pass3 | *LoginSteps.java* @When("I enter {string} and {string}") public void i_enter_username_and_password(String username, String password) { LoginPage loginPage = new LoginPage(driver); loginPage.enterUsername(username); loginPage.enterPassword(password); } @Then("I should be logged in") public void i_should_be_logged_in() { // Assertions to verify login success } *data.csv* username,password user1,pass1 user2,pass2 user3,pass3 In this example, we are using a CSV file as the data source. We read the CSV file in the Java code using the OpenCSV library, iterate through the rows, and pass the username and password values to the Cucumber step definitions. In the Cucumber feature file, we use the Scenario Outline syntax to define the login scenario with placeholders for the username and password, and provide the values for the placeholders in a table underneath the Examples keyword.
Thank you so much Raghav your detailed explanation, I appreciate your time and ur patience u have . Currently working on it , will get back to you with my results/ queries soon.Once again thank you@@RaghavPal
Tq Raghav it worked ... one more doubt..i want to read an empty row, that means i have 3 input fields and all are empty... is it possible? if so please comment the logic
Raghav it was a very helpful approach but please tell how to incorporate loop in this as in real time we have to read data from multiple cells at one go thanks in advance
Hi. This is an amazing video. Very detailed step by step explanation. Thank you! But if we have a huge database in Excel, it is inconvenient to add every time the number of row and column in getCellData to print the values. Can you please show how we can use the for loop here so we can get the whole set of values in one go as output?
Very usefull video ,tq so much .. but one doubt can u explain a generic mehtod for reading excel containing both string value numeric value and how to read an empty cell.My excel has all type of values.. please makw a video..
Tq Raghav it worked ... one more doubt..i want to read an empty row, that means i have 3 input fields and all are empty... is it possible? if so please comment the logic
as a beginner in selenium java, whether knowing all syntax, methods, classes like where and when which selenium syntax is used with java. But how to build a tricky program logic by merging selenium and java code fastly as a beginner? This makes conflicts to learn selenium java
Hi Nida, I will suggest that you do a basic Java course and can start with Selenium Java Framework. You will also learn more as you create the framework. Can take help from programming section here automationstepbystep.com/
hi, the OO in ooxml stands for Open Office. ooxml is a XML-based file format developed by Microsoft for representing spreadsheets, charts, presentations and word processing documents. so it is a Java API To Access Office Open XML documents To work with these docs you will need ooxml api
Hi Raghav, is it possible to compare two Excel sheets by using selenium webdriver or any other tools? I have scenario like I already have one excel file(sheet1) with some data in File Explorer and I need to open my application and download Excel file(sheet2) through browser. Later I need to compare sheet2 to sheet1 without read and write data.
Hi Raghav, Awesome teaching and thanks for this video and Could you please make video about how to read web table data's and write that data's into excel sheet so please this is one of the real time project concept asking at interviews.
Very nice tutorial indeed. i have learnt alot from you Raghav pal ji..keep up the good work.. (which in your case ,we can replace good keyword with Excellent) :)
Nice explanation, but you are writing and removing in between which is little challenging for beginner like me, can you please show the code after completion
Hi Ajay Sure, you can pass Excel data for some login credentials in Chrome using Selenium Java. Here are the steps on how to do it: 1. Create an Excel file and save it in a location that you can access from your Java program. 2. In the Excel file, create a sheet named "LoginCredentials" and add the following columns: * Username * Password 3. Save the Excel file. 4. In your Java program, create a `WebDriver` object and start a new instance of Chrome. 5. Import the `org.apache.poi.ss.usermodel.Workbook` class. 6. Create a `Workbook` object and load the Excel file that you created in Step 1. 7. Get the sheet named "LoginCredentials" from the `Workbook` object. 8. Get the cell values for the `Username` and `Password` columns. 9. Use the `WebDriver` object to login to the website using the credentials that you got from the Excel file. Here is an example of how to do this in Java: ```java import org.apache.poi.ss.usermodel.Workbook; import org.openqa.selenium.WebDriver; public class LoginWithExcelData { public static void main(String[] args) { WebDriver driver = new ChromeDriver(); // Load the Excel file Workbook workbook = WorkbookFactory.create(new File("login_credentials.xlsx")); // Get the sheet named "LoginCredentials" Sheet sheet = workbook.getSheet("LoginCredentials"); // Get the cell values for the "Username" and "Password" columns String username = sheet.getRow(0).getCell(0).getStringCellValue(); String password = sheet.getRow(0).getCell(1).getStringCellValue(); // Login to the website driver.get("www.example.com"); driver.findElementById("username").sendKeys(username); driver.findElementById("password").sendKeys(password); driver.findElementById("login").click(); } } ``` This code will load the Excel file named `login_credentials.xlsx` and get the cell values for the `Username` and `Password` columns. The code will then use the `WebDriver` object to login to the website using the credentials that it got from the Excel file
Hey Raghav :) , another awesome tutorial. Iam just wondering why we get "123.0" as ouput in the console. Is there any reason or way to remove this ".0" ? regards Mario
Hi Raghav have a doubt,if we have data driven(through excel) and POM in our framework, will.it be called as a hybrid framework or just data driven framework
Hi Jino, POM can be implemented in data-driven, keyword and hybrid framework as well. Do it does not always mean if you have POM and data driven, then it will be called hybrid always
Hello. The way of Ur teaching is good. I'm getting an error while performing to read the data from Excel by using while loop. i.e, Exception in thread "main" java.lang. error; unresolved compilation problem. CELL_TYPE_STRING Cannot be resolved or is not a field. Please help me to resolve this problem. I'm using selenium 3x .
Hi Gagan, this is due to the data type in your excel. you are either using numerical data in excel and trying to get a string in code or vice versa. Pls check. I believe I have also covered this in the video on numeric and string data type.
Hey pls help.. m getting an error.. null pointer exception and getting values as null.. There are two main methods one in excelutils and one in excelutilsdemo.. wen i remove excelutils main method, it works properly! Wat to do?
Hi raghav, I'm getting this error, Could you please help me on it. I have followed the same like how u showed in video. null java.lang.NullPointerException at utils.Excelutils.getRowCount(Excelutils.java:21) at utils.Excelutils.main(Excelutils.java:10)
Hi Sunil, this is not the complete logs. There is some code error at Excelutils.getRowCount(Excelutils.java:21) I will need full logs and your code to check
Thank you so much for the video. but please help me with this Exception : Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.apache.poi.xssf.usermodel.XSSFSheet.getPhysicalNumberOfRows()" because "sheet" is null at DataProvider.getRowCount(DataProvider.java:14) at DataProvider.main(DataProvider.java:8) when I am running the file above exception is coming in the console window.
Hello Raghav, Thank you very much for this informative video once again. I just want to know that while executing the program after calling the getCellDataNumber() function in the main method, I am getting nullPointerException with the message "Cannot invoke "org.apache.poi.xssf.usermodel.XSSFRow.getCell(int)" because the return value of "org.apache.poi.xssf.usermodel.XSSFSheet.getRow(int)" is null". Can you please reply how to handle them so that we don't get such exceptions further? Thanks,
Hi Papun The NullPointerException you are getting is because the `XSSFRow.getCell()` method is trying to access a cell that does not exist. This can happen if the `XSSFSheet.getRow()` method returns `null`. There are a few ways to handle this exception. One way is to add a null check before calling the `XSSFRow.getCell()` method. For example: ```java XSSFRow row = sheet.getRow(1); if (row != null) { int cellValue = row.getCell(0).getNumericCellValue(); } else { // Handle the case where the row is null } ``` Another way to handle this exception is to use the `try-catch` block. For example: ```java try { int cellValue = row.getCell(0).getNumericCellValue(); } catch (NullPointerException e) { // Handle the case where the row is null } ``` The `try-catch` block will catch the NullPointerException and you can handle it accordingly. Here are some other things you can do to prevent this exception: * Make sure that the `XSSFSheet.getRow()` method returns a valid row before calling the `XSSFRow.getCell()` method. * Use the `XSSFRow.getPhysicalNumberOfCells()` method to check the number of cells in a row before calling the `XSSFRow.getCell()` method
@@RaghavPal No such software installation is permitted on client machine. Only Google sheets are allowed. Can you suggest solution for this? "Reading/writing data in Google sheet in selenium with Java"
Hi Kshipra, I have not tried, can check this stackoverflow.com/questions/56321292/read-write-data-in-google-spreadsheet medium.com/appgambit/read-data-from-google-sheet-with-selenium-ans-google-sheets-api-c5d10595f781
Hi Raghav, I am getting error as - Exception in thread "main" java.lang.NullPointerException I have followed exact same steps as you showed, what I might have done wrong? Or how can I fix this error?
Hi Purvi, generally null pointer exception comes when you try to use a variable that is not pointing to any object. The most common way to handle it is create a try catch block around the code that is throwing this exception and in the catch block write *catch(Exception exp){ system.out.println (exp.getCause()); system.out.println (exp.getMessage()); system.out.println (exp.printStackTrace()); }* Take care of syntax, spelling, I am just writing directly. www.educative.io/edpresso/how-to-resolve-the-javalangnullpointerexception
Hi Gilson, Selenium does not have any function for this, will need java for this. stackoverflow.com/questions/38750780/how-to-open-and-save-excel-file-in-java
@@RaghavPal thank you very much. I saw so many videos and resources , i found this data provider concept is simple and best for me. WHat do you recommend me to look now?
Hi sir, In excel if it is a string we use getstringvalue and get data for numberic we use getnumbericcellvalu and get data if one row is empty and next row has data how to overcome that empty row and get next row value iam facing error with this can you help me on this
Hi Raghav, Im getting this error Exception in thread "main" org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open the specified file: 'C:\Users\ihrwell\Desktop\Automation Webdriver\Projects\Sample\E2EProject\testdata\data.xlsx'
Hi Ihrwell, there must be some more information in the logs, as to what exactly is the issue in the file, Check the path is correct and the file is saved and closed
i use isdisplay to check the presence of element means button On listing page of flight there is so many flight how can i check the presence of element(Button) for every flight
your tutorial seems clean but somehow I am getting class not found exception. I copied the same code as you showed. package AllExcel; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ExcelUtils { public static void main(String[] args) { getRowCount(); } public static void getRowCount() { try { // String projectPath = System.getProperty("user.dir"); // XSSFWorkbook workbook = new XSSFWorkbook(projectPath+"/testdata/AddDep.xlsx"); XSSFWorkbook workbook = new XSSFWorkbook("absolute path"); XSSFSheet sheet = workbook.getSheetAt(0); int rowCount = sheet.getPhysicalNumberOfRows(); System.out.println("Number of rows : "+rowCount); } catch(Exception e) { System.out.println(e.getMessage()); System.out.println(e.getCause()); e.printStackTrace(); } } } Error = Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/compress/archivers/zip/ZipFile at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:234) at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:167) at org.apache.poi.ooxml.POIXMLDocument.openPackage(POIXMLDocument.java:89) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:340) at AllExcel.ExcelUtils.getRowCount(ExcelUtils.java:17) at AllExcel.ExcelUtils.main(ExcelUtils.java:9) Caused by: java.lang.ClassNotFoundException: org.apache.commons.compress.archivers.zip.ZipFile at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source)
Hi Viki, the error logs complaining of some zip format. Caused by: java.lang.ClassNotFoundException: org.apache.commons.compress.archivers.zip.ZipFile Are you using a maven project. Not sure if you are referring to some zip file. Check this - stackoverflow.com/questions/28229095/apache-commons-compress-using-7zip
Hi Raghav, thanks for your response, I had also posted my error on stackoverflow and got the resolution, There was something missing in the latest Apache poi library as I am not using Maven, so had to download it and added to build path. Your tutorial worked for me, I am also looking to use excel data with Testng dataproviders using for loop, do you have any tutorial on that ? Again, appreciate you taking time for resolving public issues.
Hi Viki, you can see this ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-02ANy2pu_ZA.html And other selenium videos here - automationstepbystep.com/ui-testing/
how to read values from excel for "Dropdown". I wrote the below code but it's not working, It not showing any errors also. Please check the screenshot: drive.google.com/file/d/1cezdMCTauOoQOJJR2hl64kTHV__Aws_L/view?usp=drivesdk
This is a great session, Raghav. I learned a ton of really useful stuff. Incitentally, where you use a function to get "user.dir", I have found that a dot character does the same thing. So I used this path for my spreadsheet: "./excel/LoginCredentials.xlsx". Is there a particular reason you don't do that?
Hi..am getting below error..How can i fix it? I was following the exact steps mentioned on the video "Cannot invoke "org.apache.poi.xssf.usermodel.XSSFSheet.getPhysicalNumberOfRows()" because "Utils.ExcelUtils.sheet" is null java.lang.NullPointerException: Cannot invoke "org.apache.poi.xssf.usermodel.XSSFSheet.getRow(int)" because "Utils.ExcelUtils.sheet" is null Cannot invoke "org.apache.poi.xssf.usermodel.XSSFSheet.getRow(int)" because "Utils.ExcelUtils.sheet" is null at Utils.ExcelUtils.getCelldataString(ExcelUtils.java:47) at Utils.ExcelUtils.main(ExcelUtils.java:26) Cannot invoke "org.apache.poi.xssf.usermodel.XSSFSheet.getRow(int)" because "Utils.ExcelUtils.sheet" is null"
The error message "Cannot invoke "org.apache.poi.xssf.usermodel.XSSFSheet.getPhysicalNumberOfRows()" because "Utils.ExcelUtils.sheet" is null" means that the `sheet` variable is null. This can happen if you have not initialized the `sheet` variable, or if you have initialized it to a value of null. To fix this error, you need to initialize the `sheet` variable to a valid Excel sheet object. You can do this by opening the Excel sheet file and creating a new XSSFSheet object. Here is an example of how to initialize the `sheet` variable: ```java FileInputStream fis = new FileInputStream("my_excel_file.xlsx"); XSSFWorkbook workbook = new XSSFWorkbook(fis); XSSFSheet sheet = workbook.getSheet("Sheet1"); ``` Once you have initialized the `sheet` variable, you should be able to access the rows and cells in the Excel sheet without any errors. Here is an example of how to access the rows and cells in the Excel sheet: ```java int rowCount = sheet.getPhysicalNumberOfRows(); for (int i = 0; i < rowCount; i++) { XSSFRow row = sheet.getRow(i); int cellCount = row.getPhysicalNumberOfCells(); for (int j = 0; j < cellCount; j++) { Cell cell = row.getCell(j); String cellValue = cell.getStringCellValue(); System.out.println(cellValue); } } ``` This code will print the value of each cell in the Excel sheet to the console. I hope this helps