QTP/UFT was dominant in automation tool market for almost a decade. In your view, how long Selenium+appium+testNG+etc can stay relevant in the Testing job market?
Hi Jayita, good question, with the current trends it looks like Selenium Appium will stay for some time for sure as they form the core and basis or UI and Mobile automation. Also used as the backend of several other tools and platforms. Having said that, as we are moving towards, RPA (Robotic Process Automation), AI (Artificial Intelligence) and ML (Machine Learning), I will suggest that people should also start looking and learning these to be better prepared for future.
Hello, Raghav. Thanks again for all those knowledges. As a beginner I'm just getting started on my coding journey. It would be awesome if you upload some videos about basic concepts of coding in order to understand your lessons better.
Hi Raghav...the video is very useful for begineers like me.. So can we simultaneously learn selenium and Devops tools????as i am a fresher for automation testing but having experience in manual and want to switch to automation
hi Pooja, great to know that it helped you. Yes, you can learn selenium and DevOps together. Do not worry if you have no experience in Automation Testing. Start today go step by step. You can explore the playlist and start learning - ruclips.net/channel/UCTt7pyY-o0eltq14glaG5dgplaylists
Hello Raghav, greetings from Birmingham, UK. I have been watching and closely following your channel from last few days. Your videos are very well structured, thought out and beautifully illustrated and like your style of teaching. Do you have plans to do videos on BDD-Cucumber-Gherkin for Selenium-Java? It would tremendously benefit anyone looking to understand Selenium Test Automation from Behaviour Driver Development using selenium with Java all the way to continuous Integration and version controlling. I believe that you have covered Jenkins and Git in depth already. Again, your work is just incredible.
Hi Mayur, thanks a lot for you message. BDD-Cucumber-Gherkin for Selenium-Java is in my To Do list and i will take it up soon. Keep watching and learning.
im new to java and learning automation. How to develop coding skills in Java like you do? its easy to watch but without watching it, I don't know what classes to invoke and files to use and data to pass in and out of the files.
Hi, Raghav. I had a queries and confusions in using properties file as well as POM class. How do we use both the classes in a Test. It threw error while calling the methods from the POM class but it worked when I used driver.findElement methods for locating the WebElement in my Test class
Hi Papun To use both properties file and POM class in a Test class in Selenium Java, you can follow the below steps: Create a Properties file: First, create a Properties file to store the web element locators or any other configurations. You can create this file under the resources folder of your project. Load the Properties file: In your Test class, you can load the Properties file using the following code: Properties prop = new Properties(); InputStream input = new FileInputStream("src/test/resources/config.properties"); prop.load(input); Here, the config.properties is the name of your Properties file. Create an object of your POM class: Once the Properties file is loaded, you can create an object of your POM class in the Test class using the below code: HomePage homePage = new HomePage(driver); Here, driver is an instance of WebDriver, which should be initialized before using it in the Test class. Use WebElement locators from Properties file: To use WebElement locators from the Properties file in your POM class, you can use the below code: @FindBy(id = prop.getProperty("username")) private WebElement usernameInput; Here, username is the id of the input field in your application, and usernameInput is the WebElement object created in your POM class. Call the methods from the POM class: Once the WebElement objects are created in your POM class, you can call the methods from the POM class in your Test class as shown below: homePage.enterUsername(prop.getProperty("username")); Here, enterUsername is the method created in your POM class to enter the username in the input field.
Hi Gulam, so are you able to get the value from properties file in the code. If yes then you can directly use it. Can check this - ruclips.net/video/1GeVbi1uj_8/видео.html
Very helpful video Raghav......Now suppose I'm defining my TestData excel name in my property files and fetching that excel name in my Class.......but here i'm confused that where will I define the excel path? Can u help me for that or can u plz create another video and upload?
Hi Priyanka. you can definitely define the path in your config and in your code refer it from here. I will soon be creating a more detailed series on selenium framework with java.
Hi Raghav, I am follower of your videos. I have 2 questions - 1 ) In this video you showed us how to read data from properties file and how to write in the same file. But when you write in the same file, it deleted everything what it read before. How can i read from the file and write another line in the file not deleting anything from it. 2 ) I see that you have JOIN button in your video, what is it and what is benefit for it . can you please explain , how it works if I join Thanks a lot
Hi Mohammad Bhuiyan, 1) You can append instead of overwrite. stackoverflow.com/questions/17401385/how-to-append-new-data-to-existing-data-in-properties-file 2) There are some extra perks available to the members of the channel who Join. When you click on Join, you can see all the perks
Hi Amrutha, adv here is that you can update values from outside the framework and code. So you do not have to open framework or code and can just open the file on your system update and can then run
Hi Raghav, Thanks for the tutorial, when I ran this exercise using properties file, and put browser = chrome in config.properties, it loads the chrome browser, but opens the website in firefox, could you shed your thoughts on this? Thanks.
Hi Raghav, thanks for this exciting work, I have a question, every time we call the write mth- it deletes previous records and write new strings, is there any way that we can keep older string and add new objects? Thanks in advance.
Hi Raghav, your way of explanation was quite easy and understandable.everything was working fine,while exporting runnable jar files something happened, now my code is showing error as" Exception in thread "main" java.lang.Error: Unresolved compilation problem:",please help me out.
Hi Raghav Sir While trying to get values from config.properties file using InputStream object , at compilation getting error despite following same steps "InputStream cannot be resolved to a type" , Kindly guide . thanks
Here's a consolidated approach to troubleshoot and resolve the issue: 1. Import the InputStream Class: - Ensure you've added the necessary import statement at the beginning of your Java file: ```java import java.io.InputStream; ``` 2. Verify Classpath Configuration: - IDE: - Right-click your project and go to Properties (or Build Path) to check if the JRE System Library is correctly referenced. - If not, add or re-add it. - Command Line: - Use `javac -cp ` to specify the classpath during compilation. 3. Review Code for Typos: - Double-check that you've spelled `InputStream` correctly throughout your code. - Ensure there are no capitalization errors or other typos. 4. Check for Conflicting Names: - If you have a variable or method named `InputStream` in the same scope, it might conflict with the class. - Rename any conflicting identifiers. 5. Consider IDE-Specific Issues: - Project Configuration: Sometimes, IDEs have project-specific settings that might affect compilation. - Review your project settings and ensure they're configured correctly for Java development. - Clean and Rebuild: Try cleaning and rebuilding your project to refresh any cached information. 6. Inspect External Libraries: - If you're using external libraries that also use `InputStream`, ensure they're included correctly in your classpath. - Check for any compatibility issues or version conflicts. Additional Tips: - Use a Code Analysis Tool: Employ a tool to detect potential errors or code quality issues. - Consult Documentation and Examples: Refer to the Java API documentation or online examples for proper usage of `InputStream`. - Utilize IDE Troubleshooting Features: IDEs often provide error messages and hints that can guide you towards a solution.
Hi Raghav, thanks for share your knowledge. I need of you support, I have a mobile project built in serenity bdd-cucumber-java. I have two property files, android.properties and ios.properties with the capabilities for two devices located in Kobiton. I have a test case with two scenarios, the first scenario must take android.properties and the second scenario must take ios.properties. I need to know how I can read each file of those in run time. It doesn´t work for me to read both file for command line.
Hi Raghav , thanks for the video well and clear explanation but i am having this trouble with writePropertiesFile and this is what i am getting after" The metthod writePropertiesFile() is unidentified for the type of propteiesFile and if i clicked on the Create method writePropertiesFile() i will get a response in the r private static void writePropertiesFile() {, therefore if i run as Java Application , the result will still be "Firefox" instead of "Chrome"
@@RaghavPal Thanks so much i got that after following the steps but on config Properties linked with( FirstSeleniumTest )the console response is this below (Chrome Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpRequestBase at test.FirstSeleniumTest.setBrowserConfig(FirstSeleniumTest.java:43) at test.FirstSeleniumTest.main(FirstSeleniumTest.java:20) Caused by: java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpRequestBase at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ... 2 more) Kind Regards Many Thanks
In my case the read properties file is read and printing the data in the config file at the console but remaining two methods i.e; main method(), runtest() in FirstSeleniumTest.Java are not happening...Saying that exception in thread main..Java.lang.NullpointerException. at test.FirstSeleniumTest.runtest at test.FirstSeleniumTest.main....
Hi Raghav. I follow your step to edit and run the code. But I cannot see the result to display "Firefox". It displays error message as following "Error: Could not find or load main class config.PropertiesFile. Caused by: java.lang.ClassNotFoundException: config.PropertiesFile" I follow all the exact steps as you did but I can't debug successfully.
Hi. I got the second issue. When I execute the "FirstSeleniumTest.java" by using the data of browser in the file of "config.properties", the result is different with yours. The Chrome of Firefox browser is not opened. It displays that "Exception in thread "main" java.lang.NullPointerException at test.FirstSeleniumTest.runTest(FirstSeleniumTest.java:48) & at test.FirstSeleniumTest.main(FirstSeleniumTest.java:18)". The Line 48 is "driver.get("seleniumhq.org/");" and Line 18 is "runTest();". No idea what happened.
With Properties File, when I switch from Firefox(which is working OK) to Chrome I always get "Exception in thread "main" java.lang.NullPointerException" when run the program. But when I change from "PropertiesFile.readPropertiesFile();" to be "setBrowserConfig();" to use Chrome, it is working fine. I did try some research but couldn't solve this issue.
Hi Werayut, For now, you can put this code in a condition like if(browser.equalsIgnoreCase("chrome")){ setBrowserConfig(); } else if(browser.equalsIgnoreCase("firefox")){ PropertiesFile.readPropertiesFile(); }
@@RaghavPal It's working now, May I understand whey .contain won't work with Chrome but Firefox. And I just would like to say thank you and I'll be spreading the knowledge I know as well. Thank you for your contribution. Is there any way I could contact you if I have questions - such as e-mail?
Hey, I was getting the same error while switching between the browser (from firefox to chrome and vice versa). I did hit and trials and I found that each time while giving the browser name in the config file, I was writing the first letter of firefox (F) and chrome (C) in the capital letters while in my main class I have put the conditions as if(browser.contains("firefox")) { //set browsers } if(browser.contains("chrome")) { //set browsers } I tried by giving the small characters in my browser name in the config file and it worked for me(with .contains). You can also try. If that works for you. Cheers :)
hi, I didnt understand how it is printing the result in the properties file. In writePropertiesFile fxn i have commented the result line,still it is printing. Can you explain me, please
Hi Raghav.. I am not able create config.properties file ,i am not getting the option for file when i m trying to create a new file from config package,even i tried by other(Ctrl+N) what can i do?
Hi Sana, this is strange, I hope you are using Eclipse, if you do a right click and select New, do you see others options, Try going there and type file to search for the option.
Hi Raghav ,i am using Eclipse ,till selenium beginners 10 tutorial i have followed the same steps as you,when i select config package and click right and select new ,their i wont see file option ,but when i click others option , it open the select Wizard pop up.
Okay, properties file is a file where we can store key value pairs like name=Kuldeep And we can read and write values to properties file as shown in the video. setProperty and getProperty are the functions with which we can write and read data
Hi Raghav, thanks for your videos! I'm facing the strange issue, namely when I run FirstSelenuimTest.java with setBrowser(); setBrowserConfig(); runTest(); functions it's runnig well and browser opens, but if I use PropertiesFile.readPropertiesFile(); setBrowserConfig(); runTest(); PropertiesFile.writePropertiesFile(); nothing happens besides the fact it displays the current value of browser from properties file (correctly), which means it can read it, and also my System.out.println("Executed") which I put to writePropertiesFile method. But then I'm wondering why other commands 2 commands in between are not executed :/ Did exactly like you did the rest. Thanks for your help!
Hi Vadym, looks like issue fetching from properties file. It will be difficult to troubleshoot without logs. You can put breakpoints and check in debug mode.
Hi Raghav, Unfortunately, still no luck, debug mode didn't return any error. The strange thing is that when I put writePropertiesFile at first in main of FirstSelenuimTest and then setBrowserConfig(); and runTest(); as 2nd and 3rd respectively, it works, but if I'm trying to put first PropertiesFile.readPropertiesFile(); in order to actually read the value tiped in prop file and put it to variable "browser", it reads but doesn't run Firefox or Chrome. Look, I even put it to display if it actually reading correctly the value "browser" from Prop file and if it actually writes it to my browser variable: if (PropertiesFile.prop.getProperty("browser") == "Firefox") { System.setProperty("webdriver.gecko.driver", "/Users/admin/Documents/workspace/Selenium test/lib/geckodriver/geckodriver"); System.setProperty("webdriver.firefox.bin", "/Applications/Firefox.app/Contents/MacOS/firefox-bin"); driverFirefox = new FirefoxDriver(); System.out.println("OKFirefox"); } else {System.out.println(browser);} //it always returns me this value as "Firefox" but then this "if" is not being executed inside setBrowserConfig() Would you mind if I send you my code just to test on your machine? Because I tried to modify it in so many ways just to make sure that each and every step works but if I want to set the vlue in prop file and run the test accordingly it doesn't work though. Thanks in advance!
When I run the same... Output came Exception in thread "main" Chrome Java. Lang. NullpointerException at projectconnect. Demo. runTest(Demo.java:55) at projectconnect. Demo. runTest(demo.java.26) Please help me
Hi Raghav, I'm trying to get property value from config.properties but getting NullPointerException . Created one constructor in the same class where have intialized property,Inputfilestream..etc then in the same class have one method in which trying to call prop.getproperty("browser") but getting nullpointerexception.Please help, if possible please share your email Id want to share the code.Thanks.
Hi Suhanini, look for the following 1. the path you are referring is correct? 2. The name of the file is correct? 3. Name (spelling + cases) of the property is correct
Hi James, pls let me know the issues you faced. Also this is a video from a playlist. I hope you have watched the earlier videos. Here is the link ruclips.net/p/PLhW3qG5bs-L_s9HdC5zNshE5Ti8jABwlU ruclips.net/p/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa
getting two errors. my code is package config; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; public class Properties { public static void main(String[] args) { read(); } public static void read() { Properties prop = new Properties(); try { InputStream input = new FileInputStream("/Users/a-4600/eclipse-workspace/SeleniumJavaProject/src/config/config.properties"); prop.load(input); System.out.println(prop.getProperty("browser")); } catch (Exception e) { e.printStackTrace(); } } } // here prop.load(input) throws error 'The main load(InputStream) is undefined for the type Properties // getProperty("browser") also throws same error. Can you please help me?
@@RaghavPal oh OK. I changed the class name from Properties to PropertiesFile as you done in your video and code worked fine. Thanks :-) Meanwhile, what is the technical issue in creating a class named 'Properties' ? was there any conflict with any inbuilt function?
Hi Raghav, I am unable to run properies files , in connsole it showing blank, please once look int this package config; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Properties; public class ProportiesFile { public static void main(String[] args) { readpropertiesfile(); } public static void readpropertiesfile(){ } Properties prop = new Properties();{ try { FileInputStream input = new FileInputStream("Users/ajayk/eclipse-workspace/SeleniumAutomation/src/config/config.proporties"); prop.load(input); System.out.println(prop.getProperty("browser")); } catch (Exception e) { e.printStackTrace(); } } }
Ajay The issue with the provided code is that the `Properties` object is being instantiated within an initializer block, which is causing the `prop.getProperty("browser")` statement to print a blank value. This is because the initializer block is executed before the `readpropertiesfile()` method is called, and the `FileInputStream` object is not created until the `try-catch` block inside the `readpropertiesfile()` method. To fix this issue, you need to move the code to create the `FileInputStream` object and load the properties into the `prop` object inside the `readpropertiesfile()` method. Here's the corrected code: ```java package config; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Properties; public class PropertiesFile { public static void main(String[] args) { readPropertiesFile(); } public static void readPropertiesFile() { Properties prop = new Properties(); try { FileInputStream input = new FileInputStream("Users/ajayk/eclipse-workspace/SeleniumAutomation/src/config/config.properties"); prop.load(input); System.out.println(prop.getProperty("browser")); } catch (Exception e) { e.printStackTrace(); } } } ``` In this corrected code, the `Properties` object is created and initialized inside the `readPropertiesFile()` method, ensuring that the `prop.getProperty("browser")` statement has access to the loaded properties.
Hi @@RaghavPal I am Unable to find the properties file location, Already I am created propertiesfile but still I am getting this Issue . java.io.FileNotFoundException: Users\ajayk\eclipse-workspace\SeleniumAutomation\src\config\config.properties (The system cannot find the path specified) at java.base/java.io.FileInputStream.open0(Native Method) at java.base/java.io.FileInputStream.open(FileInputStream.java:216) at java.base/java.io.FileInputStream.(FileInputStream.java:157) at java.base/java.io.FileInputStream.(FileInputStream.java:111) at config.PropertiesFile.readPropertiesFile(PropertiesFile.java:17) at config.PropertiesFile.main(PropertiesFile.java:10)
The error message indicates that the Selenium Java code is trying to load a properties file from the location `Users\ajayk\eclipse-workspace\SeleniumAutomation\src\config\config.properties`, but the file cannot be found. There are a few possible reasons why this might happen: * The properties file does not exist at that location. * The properties file exists, but the Selenium Java code does not have permission to read it. * The path to the properties file is incorrect. To troubleshoot the issue, you can try the following: 1. Make sure that the properties file exists at the location `Users\ajayk\eclipse-workspace\SeleniumAutomation\src\config\config.properties`. If the file does not exist, you will need to create it. 2. Make sure that the Selenium Java code has permission to read the properties file. You can do this by checking the file permissions. 3. Check the path to the properties file in the Selenium Java code to make sure that it is correct. If you are still unable to resolve the issue, you can try the following: * Try running the Selenium Java code from the command line. This can help to rule out any problems with your Eclipse workspace. * Try using a different properties file. This can help to rule out any problems with the properties file itself. * Try using a different version of Selenium Java. This can help to rule out any problems with the Selenium Java library itself. If you are still unable to resolve the issue, you can post a question on Stack Overflow or another Selenium forum. Here are some additional tips for working with properties files in Selenium Java: * Make sure that the properties file is in the classpath. This means that it should be in the same directory as your Selenium Java code, or in a subdirectory of the classpath. * Use the `Properties` class to load the properties file. This class provides a number of methods for reading and writing properties files. * Use the `System.getProperty()` method to get the value of a property. This method takes the name of the property as a parameter and returns the value of the property, or `null` if the property does not exist. Here is an example of how to load a properties file in Selenium Java: ```java import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; public class PropertiesExample { public static void main(String[] args) throws IOException { // Load the properties file Properties properties = new Properties(); properties.load(new FileInputStream("config.properties")); // Get the value of a property String username = properties.getProperty("username"); // Do something with the username System.out.println("Username is: " + username); } } ``` I hope this helps
Hello ..after 9 yrs I have decided to returnback to work....I have just started learning selenium.....your channel is big help...excellent work.
So happy to know this Seema. All the best
Your videos have been excellent so far for me as a brand-new-to-Selenium person, thank you for all your work!
You're welcome Jesse
Super boss, i am a beginner and learning by watching your videos...good job..and thank you.
You're welcome. Keep learning.
I never loose my interest in the topic while watching ur learning sessions..Thanks Raghav
So nice of you Sonika, humbled
Why we use config. Properties file?we can use selenium,testing.
Testng
Excellent bro, very happy that u explained all possible scenarios, was looking for such quality content on youtube.
Thanks for watching.
hellow Mr Raghaf ,the way that you explain the tutorial is most marvelous, i can say it is so easy as it is so preventive , many thanks
So nice of you Hazim
Covered all the details...hats off...
your videos are best in the field.....thanks for uploading...
You're welcome Nayan
Hello, Raghav. This video is excellent as others. Thank you.
Most welcome Erhan
Many Many thanks from Germany.
Most welcome Rishikesh
QTP/UFT was dominant in automation tool market for almost a decade. In your view, how long Selenium+appium+testNG+etc can stay relevant in the Testing job market?
Hi Jayita, good question, with the current trends it looks like Selenium Appium will stay for some time for sure as they form the core and basis or UI and Mobile automation. Also used as the backend of several other tools and platforms. Having said that, as we are moving towards, RPA (Robotic Process Automation), AI (Artificial Intelligence) and ML (Machine Learning), I will suggest that people should also start looking and learning these to be better prepared for future.
Hello, Raghav. Thanks again for all those knowledges. As a beginner I'm just getting started on my coding journey. It would be awesome if you upload some videos about basic concepts of coding in order to understand your lessons better.
Sure JB, you can find some basic Java here - automationstepbystep.com/online-courses/
Wish you all the best
Very useful. I like your way teaching
Thanks
Thanks sir for made this video.
Most welcome
Brilliant! Thanks
You're welcome!
it was easy to understand.thnku sir
Most welcome Aparna
Hi Raghav...the video is very useful for begineers like me..
So can we simultaneously learn selenium and Devops tools????as i am a fresher for automation testing but having experience in manual and want to switch to automation
hi Pooja, great to know that it helped you. Yes, you can learn selenium and DevOps together. Do not worry if you have no experience in Automation Testing. Start today go step by step. You can explore the playlist and start learning - ruclips.net/channel/UCTt7pyY-o0eltq14glaG5dgplaylists
Thank a lot Raghav,..will be following you for devops tools also..
Thank you for such great tutorials.. :)
I am glad, you liked it. Keep Learning.
Hello Raghav, greetings from Birmingham, UK. I have been watching and closely following your channel from last few days. Your videos are very well structured, thought out and beautifully illustrated and like your style of teaching. Do you have plans to do videos on BDD-Cucumber-Gherkin for Selenium-Java? It would tremendously benefit anyone looking to understand Selenium Test Automation from Behaviour Driver Development using selenium with Java all the way to continuous Integration and version controlling. I believe that you have covered Jenkins and Git in depth already. Again, your work is just incredible.
Hi Mayur, thanks a lot for you message.
BDD-Cucumber-Gherkin for Selenium-Java is in my To Do list and i will take it up soon.
Keep watching and learning.
Thanks for responding and great to know that these are in your to do list Raghav.... yeah off course i am totally subscribed
Raghav, do you also provide technical interview training ?
Hi Sheetal, I usually do training for corporates or groups
Ok Thanks
@raghav Why is execution from the config file required ? When we can achieve browser execution with steps from the previous tutorials
Hi, this is to cover the feature of config file as it is used in many projects. You can select the best way for you.
im new to java and learning automation. How to develop coding skills in Java like you do? its easy to watch but without watching it, I don't know what classes to invoke and files to use and data to pass in and out of the files.
you have to practice, take some program examples and try daily
Thank you for the video!
Glad it was helpful!
Hi, Raghav. I had a queries and confusions in using properties file as well as POM class. How do we use both the classes in a Test. It threw error while calling the methods from the POM class but it worked when I used driver.findElement methods for locating the WebElement in my Test class
Hi Papun
To use both properties file and POM class in a Test class in Selenium Java, you can follow the below steps:
Create a Properties file: First, create a Properties file to store the web element locators or any other configurations. You can create this file under the resources folder of your project.
Load the Properties file: In your Test class, you can load the Properties file using the following code:
Properties prop = new Properties();
InputStream input = new FileInputStream("src/test/resources/config.properties");
prop.load(input);
Here, the config.properties is the name of your Properties file.
Create an object of your POM class: Once the Properties file is loaded, you can create an object of your POM class in the Test class using the below code:
HomePage homePage = new HomePage(driver);
Here, driver is an instance of WebDriver, which should be initialized before using it in the Test class.
Use WebElement locators from Properties file: To use WebElement locators from the Properties file in your POM class, you can use the below code:
@FindBy(id = prop.getProperty("username"))
private WebElement usernameInput;
Here, username is the id of the input field in your application, and usernameInput is the WebElement object created in your POM class.
Call the methods from the POM class: Once the WebElement objects are created in your POM class, you can call the methods from the POM class in your Test class as shown below:
homePage.enterUsername(prop.getProperty("username"));
Here, enterUsername is the method created in your POM class to enter the username in the input field.
thank you for the beautiful explanations.. if I want to set the URL in the properties file, then how can I proceed for method runtest().
Hi Gulam, so are you able to get the value from properties file in the code. If yes then you can directly use it. Can check this - ruclips.net/video/1GeVbi1uj_8/видео.html
Very helpful video Raghav......Now suppose I'm defining my TestData excel name in my property files and fetching that excel name in my Class.......but here i'm confused that where will I define the excel path? Can u help me for that or can u plz create another video and upload?
Hi Priyanka. you can definitely define the path in your config and in your code refer it from here. I will soon be creating a more detailed series on selenium framework with java.
Hi Priyanka, I started Selenium Java Framework from scratch series ruclips.net/p/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa
thaaaaaaaank you really it saved me
Most welcome Baran
Hi Raghav, I am follower of your videos. I have 2 questions - 1 ) In this video you showed us how to read data from properties file and how to write in the same file. But when you write in the same file, it deleted everything what it read before. How can i read from the file and write another line in the file not deleting anything from it.
2 ) I see that you have JOIN button in your video, what is it and what is benefit for it . can you please explain , how it works if I join
Thanks a lot
Hi Mohammad Bhuiyan,
1) You can append instead of overwrite.
stackoverflow.com/questions/17401385/how-to-append-new-data-to-existing-data-in-properties-file
2) There are some extra perks available to the members of the channel who Join. When you click on Join, you can see all the perks
I don't understand who dislikes these videos
I just it helps millions. Thanks Jose for the message
Hi Raghav! Can you please tell me how to set path for the executable in a config file on macbook
Hi Sujatha, I will check on this, can take some online help too
Thanks For Make It Easy :) Keep
What is the advantage of run the test using properties file
Hi Amrutha, adv here is that you can update values from outside the framework and code. So you do not have to open framework or code and can just open the file on your system update and can then run
@@RaghavPal thank you
Hi Raghav,
Thanks for the tutorial, when I ran this exercise using properties file, and put browser = chrome in config.properties, it loads the chrome browser, but opens the website in firefox, could you shed your thoughts on this?
Thanks.
Hi Amitabh, Check your code, you must be having code to run firefox outside the conditional blocl
Hi Raghav, thanks for this exciting work, I have a question, every time we call the write mth- it deletes previous records and write new strings, is there any way that we can keep older string and add new objects? Thanks in advance.
Hi Mohammed, you can use
FileOutputStream output = new FileOutputStream(File file, true);
true is to append instead of overwrite
Great, thanks. I have some other things to share with you, can I have ur email address? Thanks again.
You can find the email in the about section of the channel.
Do you have any other video on property file as well??
I don't think so, you will find all in this Selenium Playlist
Hi Raghav, your way of explanation was quite easy and understandable.everything was working fine,while exporting runnable jar files something happened, now my code is showing error as" Exception in thread "main" java.lang.Error: Unresolved compilation problem:",please help me out.
Hi Sana, will have to see the compilation issues. Check this stackoverflow.com/questions/1124788/java-unresolved-compilation-problem
When we do getPropertyValue is it compulsory to setPropertyValue also
No it depends, if the value is already existing to fetch you can only do get and if you want to create or update you can do set
Hi Raghav , I tried to run this program but for me it’s printing null instead of giving me the name of the browser
Will have to see your programm
I have the same problem what did you do
Hi Raghav, i don't know why but i am getting class not found exception, tried so many solutions still nit able to find any resolution. Please help
HI Ranjana, will need to see the logs to troubleshoot
Hi Raghav Sir
While trying to get values from config.properties file using InputStream object , at compilation getting error despite following same steps "InputStream cannot be resolved to a type" , Kindly guide . thanks
Here's a consolidated approach to troubleshoot and resolve the issue:
1. Import the InputStream Class:
- Ensure you've added the necessary import statement at the beginning of your Java file:
```java
import java.io.InputStream;
```
2. Verify Classpath Configuration:
- IDE:
- Right-click your project and go to Properties (or Build Path) to check if the JRE System Library is correctly referenced.
- If not, add or re-add it.
- Command Line:
- Use `javac -cp ` to specify the classpath during compilation.
3. Review Code for Typos:
- Double-check that you've spelled `InputStream` correctly throughout your code.
- Ensure there are no capitalization errors or other typos.
4. Check for Conflicting Names:
- If you have a variable or method named `InputStream` in the same scope, it might conflict with the class.
- Rename any conflicting identifiers.
5. Consider IDE-Specific Issues:
- Project Configuration: Sometimes, IDEs have project-specific settings that might affect compilation.
- Review your project settings and ensure they're configured correctly for Java development.
- Clean and Rebuild: Try cleaning and rebuilding your project to refresh any cached information.
6. Inspect External Libraries:
- If you're using external libraries that also use `InputStream`, ensure they're included correctly in your classpath.
- Check for any compatibility issues or version conflicts.
Additional Tips:
- Use a Code Analysis Tool: Employ a tool to detect potential errors or code quality issues.
- Consult Documentation and Examples: Refer to the Java API documentation or online examples for proper usage of `InputStream`.
- Utilize IDE Troubleshooting Features: IDEs often provide error messages and hints that can guide you towards a solution.
Thank you sir , I used ctrl + space for suggestions and it imported the " import java.io.InputStream"
@@RaghavPal
Voice is very low even after increasing the volume, please improve this.
Sure Sumant, I will take care of audio in future videos. For now, pls see if headphones can help
Hi Raghav I am not getting auto suggestion try catch block and if I try to write manual try block I am getting error So can you help me out .
Hi Subrat, what is the error, pls check the syntax
Hi Raghav, thanks for share your knowledge. I need of you support, I have a mobile project built in serenity bdd-cucumber-java. I have two property files, android.properties and ios.properties with the capabilities for two devices located in Kobiton. I have a test case with two scenarios, the first scenario must take android.properties and the second scenario must take ios.properties. I need to know how I can read each file of those in run time. It doesn´t work for me to read both file for command line.
Hi, I am not much aware on this, will need to get some online help
How to create separate diversetup class and call in main method
Hi, I will try to add a session, can check some online examples meanwhile
Hi Raghav , thanks for the video well and clear explanation but i am having this trouble with writePropertiesFile and this is what i am getting after" The metthod writePropertiesFile() is unidentified for the type of propteiesFile and if i clicked on the Create method writePropertiesFile() i will get a response in the r private static void writePropertiesFile() {, therefore if i run as Java Application , the result will still be "Firefox" instead of "Chrome"
Hi Imo, I believe there is something missing. Can you pls recheck all the steps with the video
@@RaghavPal
Thanks so much i got that after following the steps
but on config Properties linked with( FirstSeleniumTest )the console response is this below
(Chrome
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpRequestBase
at test.FirstSeleniumTest.setBrowserConfig(FirstSeleniumTest.java:43)
at test.FirstSeleniumTest.main(FirstSeleniumTest.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpRequestBase
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 2 more)
Kind Regards
Many Thanks
The logs are not complete, Do you have caused by section in logs
In my case the read properties file is read and printing the data in the config file at the console but remaining two methods i.e; main method(), runtest() in FirstSeleniumTest.Java are not happening...Saying that exception in thread main..Java.lang.NullpointerException. at test.FirstSeleniumTest.runtest
at test.FirstSeleniumTest.main....
Hi Sriram, will need to see more logs to troubleshoot, check if you find caused by section in logs
@@RaghavPal i don't know how to check logs sir ...But one thing is clear...The runtest() method is throwing an nullpointerexception .
Just check in your console window,
@@RaghavPal done sir...😁
Getting same exception java.lang.nullpointerexeption....from runtest () method... How to solve??
Raghav can you please share some real time interview questions please.
I will do very soon. Thanks for watching
Hi Raghav. I follow your step to edit and run the code. But I cannot see the result to display "Firefox".
It displays error message as following "Error: Could not find or load main class config.PropertiesFile. Caused by: java.lang.ClassNotFoundException: config.PropertiesFile"
I follow all the exact steps as you did but I can't debug successfully.
Hi Jian, looks like some error in your code. Can you put your code and your file name to debug.
Yes. Already fixed it. Thanks.
Hi. I got the second issue. When I execute the "FirstSeleniumTest.java" by using the data of browser in the file of "config.properties", the result is different with yours. The Chrome of Firefox browser is not opened. It displays that "Exception in thread "main" java.lang.NullPointerException at test.FirstSeleniumTest.runTest(FirstSeleniumTest.java:48) & at test.FirstSeleniumTest.main(FirstSeleniumTest.java:18)".
The Line 48 is "driver.get("seleniumhq.org/");" and Line 18 is "runTest();".
No idea what happened.
With Properties File, when I switch from Firefox(which is working OK) to Chrome I always get "Exception in thread "main" java.lang.NullPointerException" when run the program.
But when I change from "PropertiesFile.readPropertiesFile();" to be "setBrowserConfig();" to use Chrome, it is working fine.
I did try some research but couldn't solve this issue.
Hi Werayut, For now, you can put this code in a condition like
if(browser.equalsIgnoreCase("chrome")){
setBrowserConfig();
}
else if(browser.equalsIgnoreCase("firefox")){
PropertiesFile.readPropertiesFile();
}
@@RaghavPal It's working now, May I understand whey .contain won't work with Chrome but Firefox.
And I just would like to say thank you and I'll be spreading the knowledge I know as well.
Thank you for your contribution.
Is there any way I could contact you if I have questions - such as e-mail?
Glad to know it is resolved. I will update if I get more info. RUclips comments is the best place for queries, You will get faster replies here
Hey, I was getting the same error while switching between the browser (from firefox to chrome and vice versa). I did hit and trials and I found that each time while giving the browser name in the config file, I was writing the first letter of firefox (F) and chrome (C) in the capital letters while in my main class I have put the conditions as
if(browser.contains("firefox")) {
//set browsers
}
if(browser.contains("chrome")) {
//set browsers
}
I tried by giving the small characters in my browser name in the config file and it worked for me(with .contains). You can also try. If that works for you. Cheers :)
hi, I didnt understand how it is printing the result in the properties file. In writePropertiesFile fxn i have commented the result line,still it is printing. Can you explain me, please
There must be some code doing it. Check it. You can check step by step in debug mode.
Hi Raghav.. I am not able create config.properties file ,i am not getting the option for file when i m trying to create a new file from config package,even i tried by other(Ctrl+N) what can i do?
Hi Sana, this is strange, I hope you are using Eclipse, if you do a right click and select New, do you see others options, Try going there and type file to search for the option.
Hi Raghav ,i am using Eclipse ,till selenium beginners 10 tutorial i have followed the same steps as you,when i select config package and click right and select new ,their i wont see file option ,but when i click others option , it open the select Wizard pop up.
Yes here you can type file in search box and see if you get the option
is it my laptop , the volume is too low. "Never stop learning" by Raghav.
Guzara, It may be with this video, can try using headphones with full volume on device and player
I will take care in future
Thanks Raghav!
How this property file read in TestNG program?
Please explain it.
Thanks!
Hi Sachin, you should be able to use similar steps. Let me know if there is something specific you need to do.
Hi raghav, need your help how do you just validate with mozilla firefox when you set writeproperties file is for chrome? Please answer.
Hi Kuldeep, did not get you exactly, which part of the video are you referring to.
Automation Step by Step - Raghav Pal you just changed the config.properties and make browser = firefox for validating ?
So I don't understand how does it work ?
Okay, properties file is a file where we can store key value pairs like name=Kuldeep
And we can read and write values to properties file as shown in the video.
setProperty and getProperty are the functions with which we can write and read data
Hi Raghav, i need to automate a login page so how do i do ? do you have any video related to that !
Sir is properties file created automatically when java is installed
Hi Rupasi, no, we need to create as per our needs
Thank u sir
Sir what is keys file
where exactly is this referred to in the video
Hi Raghav, thanks for your videos! I'm facing the strange issue, namely when I run FirstSelenuimTest.java with
setBrowser();
setBrowserConfig();
runTest();
functions it's runnig well and browser opens, but if I use
PropertiesFile.readPropertiesFile();
setBrowserConfig();
runTest();
PropertiesFile.writePropertiesFile();
nothing happens besides the fact it displays the current value of browser from properties file (correctly), which means it can read it, and also my System.out.println("Executed") which I put to writePropertiesFile method. But then I'm wondering why other commands 2 commands in between are not executed :/ Did exactly like you did the rest. Thanks for your help!
Hi Vadym, looks like issue fetching from properties file. It will be difficult to troubleshoot without logs. You can put breakpoints and check in debug mode.
Hi Raghav,
Unfortunately, still no luck, debug mode didn't return any error. The strange thing is that when I put writePropertiesFile at first in main of FirstSelenuimTest and then setBrowserConfig(); and runTest(); as 2nd and 3rd respectively, it works, but if I'm trying to put first PropertiesFile.readPropertiesFile(); in order to actually read the value tiped in prop file and put it to variable "browser", it reads but doesn't run Firefox or Chrome. Look, I even put it to display if it actually reading correctly the value "browser" from Prop file and if it actually writes it to my browser variable:
if (PropertiesFile.prop.getProperty("browser") == "Firefox") {
System.setProperty("webdriver.gecko.driver", "/Users/admin/Documents/workspace/Selenium test/lib/geckodriver/geckodriver");
System.setProperty("webdriver.firefox.bin", "/Applications/Firefox.app/Contents/MacOS/firefox-bin");
driverFirefox = new FirefoxDriver();
System.out.println("OKFirefox");
}
else {System.out.println(browser);} //it always returns me this value as "Firefox" but then this "if" is not being
executed inside setBrowserConfig()
Would you mind if I send you my code just to test on your machine? Because I tried to modify it in so many ways just to make sure that each and every step works but if I want to set the vlue in prop file and run the test accordingly it doesn't work though. Thanks in advance!
I know it's a little late for this, but I think it's because you need to use .equals("Firefox") instead of == on your if statement.
Hello! )) Please, could you please make video to upload the file with Jmeter?
will do it soon
Do you conduct online courses?
Hi Roopali, yes I do on need basis
Can you please send your email address so I can communicate further. Thanks.
sure, raghav.qna@gmail.com
When I run the same... Output came Exception in thread "main" Chrome
Java. Lang. NullpointerException
at projectconnect. Demo. runTest(Demo.java:55)
at projectconnect. Demo. runTest(demo.java.26)
Please help me
Hi Abhi, can you check the code line where this error is thrown and show the same
SUPERLIKE
Thanks for watching Rashmi.
What is the meaning of input stream class ?
Hi Helly, This class helps to read data or get any inputs. You can find more examples online
Hi Raghav, I'm trying to get property value from config.properties but getting NullPointerException .
Created one constructor in the same class where have intialized property,Inputfilestream..etc then in the same class have one method in which trying to call prop.getproperty("browser") but getting nullpointerexception.Please help, if possible please share your email Id want to share the code.Thanks.
Hi Suhanini, look for the following
1. the path you are referring is correct?
2. The name of the file is correct?
3. Name (spelling + cases) of the property is correct
This was a great video fore sure, but it wasn't that easy to understand. It's challenging and confusing at the same time.
Hi James, pls let me know the issues you faced. Also this is a video from a playlist. I hope you have watched the earlier videos. Here is the link
ruclips.net/p/PLhW3qG5bs-L_s9HdC5zNshE5Ti8jABwlU
ruclips.net/p/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa
Same here. I also took long to understand it. But finally made it. Thanks Raghav.
getting two errors. my code is
package config;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
public class Properties {
public static void main(String[] args) {
read();
}
public static void read() {
Properties prop = new Properties();
try {
InputStream input = new FileInputStream("/Users/a-4600/eclipse-workspace/SeleniumJavaProject/src/config/config.properties");
prop.load(input);
System.out.println(prop.getProperty("browser"));
}
catch (Exception e) {
e.printStackTrace();
}
}
}
// here prop.load(input) throws error 'The main load(InputStream) is undefined for the type Properties
// getProperty("browser") also throws same error.
Can you please help me?
Hi Shaji, can you recheck from the video did I create a class called Properties as you have done. I doubt this. Pls recheck
@@RaghavPal oh OK. I changed the class name from Properties to PropertiesFile as you done in your video and code worked fine. Thanks :-)
Meanwhile, what is the technical issue in creating a class named 'Properties' ? was there any conflict with any inbuilt function?
Properties is already a class in the library
Hi Raghav,
I am unable to run properies files , in connsole it showing blank, please once look int this
package config;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Properties;
public class ProportiesFile {
public static void main(String[] args) {
readpropertiesfile();
}
public static void readpropertiesfile(){
}
Properties prop = new Properties();{
try {
FileInputStream input = new FileInputStream("Users/ajayk/eclipse-workspace/SeleniumAutomation/src/config/config.proporties");
prop.load(input);
System.out.println(prop.getProperty("browser"));
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Ajay
The issue with the provided code is that the `Properties` object is being instantiated within an initializer block, which is causing the `prop.getProperty("browser")` statement to print a blank value. This is because the initializer block is executed before the `readpropertiesfile()` method is called, and the `FileInputStream` object is not created until the `try-catch` block inside the `readpropertiesfile()` method.
To fix this issue, you need to move the code to create the `FileInputStream` object and load the properties into the `prop` object inside the `readpropertiesfile()` method. Here's the corrected code:
```java
package config;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Properties;
public class PropertiesFile {
public static void main(String[] args) {
readPropertiesFile();
}
public static void readPropertiesFile() {
Properties prop = new Properties();
try {
FileInputStream input = new FileInputStream("Users/ajayk/eclipse-workspace/SeleniumAutomation/src/config/config.properties");
prop.load(input);
System.out.println(prop.getProperty("browser"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
In this corrected code, the `Properties` object is created and initialized inside the `readPropertiesFile()` method, ensuring that the `prop.getProperty("browser")` statement has access to the loaded properties.
Hi @@RaghavPal
I am Unable to find the properties file location, Already I am created propertiesfile but still I am getting this Issue .
java.io.FileNotFoundException: Users\ajayk\eclipse-workspace\SeleniumAutomation\src\config\config.properties (The system cannot find the path specified)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:216)
at java.base/java.io.FileInputStream.(FileInputStream.java:157)
at java.base/java.io.FileInputStream.(FileInputStream.java:111)
at config.PropertiesFile.readPropertiesFile(PropertiesFile.java:17)
at config.PropertiesFile.main(PropertiesFile.java:10)
The error message indicates that the Selenium Java code is trying to load a properties file from the location `Users\ajayk\eclipse-workspace\SeleniumAutomation\src\config\config.properties`, but the file cannot be found.
There are a few possible reasons why this might happen:
* The properties file does not exist at that location.
* The properties file exists, but the Selenium Java code does not have permission to read it.
* The path to the properties file is incorrect.
To troubleshoot the issue, you can try the following:
1. Make sure that the properties file exists at the location `Users\ajayk\eclipse-workspace\SeleniumAutomation\src\config\config.properties`. If the file does not exist, you will need to create it.
2. Make sure that the Selenium Java code has permission to read the properties file. You can do this by checking the file permissions.
3. Check the path to the properties file in the Selenium Java code to make sure that it is correct.
If you are still unable to resolve the issue, you can try the following:
* Try running the Selenium Java code from the command line. This can help to rule out any problems with your Eclipse workspace.
* Try using a different properties file. This can help to rule out any problems with the properties file itself.
* Try using a different version of Selenium Java. This can help to rule out any problems with the Selenium Java library itself.
If you are still unable to resolve the issue, you can post a question on Stack Overflow or another Selenium forum.
Here are some additional tips for working with properties files in Selenium Java:
* Make sure that the properties file is in the classpath. This means that it should be in the same directory as your Selenium Java code, or in a subdirectory of the classpath.
* Use the `Properties` class to load the properties file. This class provides a number of methods for reading and writing properties files.
* Use the `System.getProperty()` method to get the value of a property. This method takes the name of the property as a parameter and returns the value of the property, or `null` if the property does not exist.
Here is an example of how to load a properties file in Selenium Java:
```java
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class PropertiesExample {
public static void main(String[] args) throws IOException {
// Load the properties file
Properties properties = new Properties();
properties.load(new FileInputStream("config.properties"));
// Get the value of a property
String username = properties.getProperty("username");
// Do something with the username
System.out.println("Username is: " + username);
}
}
```
I hope this helps