@12:52 If you can't find TestNG, MAKE SURE you are adding @Test, @BeforeTest, and @Aftertest ANNOTATIONS. I accidentally added JUnit of which TestNG didn't show when I wanted to run. -,- So simple yet so annoying and time consuming. Also if you have an issue with maven, go to the project, right click maven and Update the project. Make sure to include the snapshots as well
Hi Raghav Thanks for your videos,, Great explanation, All of your courses really helps the beginners. Your time, patience and dedication in making this videos really deserve a salute from me from NZ.
Hello Raghav, Many Many CONGRATULATIONS for Silver Play Button Award.. you deserve it man ! Proud moment, You are really an inspirational. your videos helped me and many others in up scaling. Take care and stay healthy :) I have a request for Playlist for cucumber framework in selenium. Pls invest some time in creating it. THANK YOU !
Hi Raghav, How to run the java file using TestNG after adding Jar files in my project. I don't have configured Maven in my project and I don't have any POM.XML file. I'm not getting any option in "Run As"
Hi Pritish, I will suggest you to create a maven project and use pom.xml. Else its going to be difficult to maintain and enhance your project. You can get the playlist here - ua-cam.com/play/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa.html
Hello Raghav, Yours videos are really very helpful. Can you please arrange in sequence i.e. numbering as you did from 1 to 8. After 8 there is no sequence in "Selenium Java Framework Step by Step" video series. Thanks for your kind effort.
Hi Samdani, testNG library enables to use the testng functionalities, annotations in your project and TestNG plugin on eclipse enables to run our scripts as TestNG
Hello Sir, plz make video on framework level work that is being implemented in companies. Plz try to show it with small project on automation....so that we will be clear about how selenium webdriver with java works in actual.
Hi Raghav Sir, I m using java project instead of maven project for all your examples and I didn't get any problem during TestNG installation and execution, but at point 13:54 I followed all steps Refresh project-> test_output folder-> clicked on "index.html" as per your instruction it open up like BELOW HTML DOC instead of proper test report like yours and I also tried to open test results html in default text editor but the result was same as below. Please Help. --------------------------------------------------------------------
TestNG reports
google.load('visualization', '1', {packages:['table']}); google.setOnLoadCallback(drawTable); var suiteTableInitFunctions = new Array(); var suiteTableData = new Array();
Hi, that's okay, May be your eclipse does not have an in built browser. You can get one from Help > Eclipse marketplace Or just right click and open with system editor (i.e. your system's default browser)
Hi Sanket, you can use some encoding libraries like base64 - www.quora.com/How-do-I-encrypt-the-password-while-programming-in-Java-for-automating-an-application-in-Selenium
Hi Sreelatha, you can check this playlist. I will add more videos soon to this SELENIUM JAVA FRAMEWORK BEGINNERSua-cam.com/play/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa.html
Hi Raghav, I followed the steps in the video but the test did not run. I am getting this error: java.lang.NoSuchMethodError: org.testng.TestRunner.addListener(Ljava/lang/Object;) How to solve this? Please help
Hi Nirmala, I tried with below solution and it worked for me in Eclipse : Go to Project -> Properties -> Java Build path -> Libraries -> Click on Add Library and select TestNG -> Next and Finish
@@RaghavPal Thanks Raghav for replying.... I am a very beginner at this point of time. actually I wanted to understand that code part through video if you have created for it. Because what you have shared is git, I am not sure what to look. Please share a video link if you have.
Okay, using github repo url you can actually clone the project and see my complete code. You can also find tutorials on how to clone project from github. In case you want to understand the coding, I will suggest that you see the Java Beginners playlist here - automationstepbystep.com/
Hi Sathish, if you have some url where it can be accessed and data can be retrieved, it will work. I have not used it so will need to check more online
Your videos are very helpful for beginners like us thank you so much :) for uploading such kind of useful videos...Please also upload videos for cracking interview questions for automation QAs in ( Selenium + C#) or (Selenium +Java).
It is possible to just add the TestNG dependency in your pom.xml file for IntelliJ IDEA, and it should work as expected. There's no need for any additional configuration unless you have specific customizations in mind. Here's a breakdown of the process: 1. Open your project's `pom.xml` file. 2. Navigate to the `dependencies` section. 3. Add the following dependency snippet: ```xml org.testng testng 7.4.0 test ``` 4. Save the `pom.xml` file. 5. Refresh your project dependencies in IntelliJ IDEA (usually by right-clicking on the project in the Project tool window and selecting "Maven -> Reimport"). After these steps, TestNG should be recognized and ready for use in your project. You can create TestNG test classes with the `@Test` annotation and run them directly within IntelliJ IDEA.
Hi Raghav, If I am running LoginPageTest Class that has testCase, I have no issues. As I create another class (MaintenanceClass) within the same package and call loginPageTest class I get NullPointerException. Any thoughts ?
@@RaghavPal I extended BasePage class yet I was getting NullPointerException. So I have accessed test case method by making it static and access using Class name rather than creating class object. I still don't understand but I was able to achieve. Thanks though!
Hi Raghav, For some reason I have the same Test_GoogleSearch.java file word for word. When I run it the browser opens but nothing happens. I checked it many times but it's the same. Message reads "No tests found. Nothing was run", but there is a test.
Hi raghav Thanks for explaining.just one doubt. If i create a maven project and added testng dependency without adding testng plugin. I am able to see testng annoations but run as tetng is not visible.For sure i have to add testng plugin in my eclipse Ide?can you please explain on this?
Hi Dheeraj, when you add testng maven dependency, you can use TestNG annotations in your test, but to run your tests as TestNG you will need testng plugin in Eclipse
hi sir- i could see a folder name drivers below maven dependencies- can you please tell how to add that- because it throws an error on my code on webelement and driver( i tried importing- it still shows error) And also i have followed all the steps you have mentioned- but not getting run as - testng option can you assist please
Hi Priyanka, Sure, I can help you with that. Adding drivers folder in Maven project: You can add the drivers folder to your Maven project by following these steps: Create a new folder named drivers in the root directory of your project. Inside the drivers folder, create subfolders for the different drivers you want to use, for example, chromedriver, geckodriver, etc. Download the corresponding driver executable files and save them in their respective subfolders. You can download the latest driver versions from the official websites of the browser vendors. In your Maven project, open the pom.xml file and add the following code:
Hi raghav, I have searched for TestNG in the marketplace, but not listed there in the result section. When I tried through Install New Software options, it doesn't display testNG icon in the list. Is there any solution for this or any alternate way to install?
Hi Amanuel, As of now there are no personal classes planned. You can follow and ask your queries here. Can see all courses here automationstepbystep.com/online-courses/
Hello Raghav, Thanks so much for making these videos. They are super helpful! In this video we are installing TestNG separately, could you please explain why adding the dependency in pom.xml not be enough.
Hi Radhika, by adding TestNG dependency, you can use testng annotations in your functions, However to run your scripts as TestNG tests in Eclipse, you will need to add the extension.
Hey, I followed your all the steps from start, no error and exception in the run. But it is giving me the option "Run as -> Junit Test". i have added all the TestNG dependencies and they can be seen in Maven dependcies but its is not giving me thr Run option with TestNG why?
Hello Raghav sir, To add TestNG libraries, you are using POM.xml which I don't have. I have watched your other video and installed maven on my machine but I am not sure how to create dependencies and create this pom.xml. I did not find it under Maven folder either (it only has up to installation). Do you have a video that describes how we can create pom.xml and add maven dependencies? Appreciate your efforts and response. Thank you
Hello Raghav, When i am downloading TestNG in my mac for eclipse IDE, i'm getting error "An error occurred while collecting items to be installed" . Can you help in identifying the issue?
Hi Raghav, i followed all the steps as mentioned. But when i try to run it doesn't display Run as : Test NG case. I have installed the plugin as well as dependencies. but still nothing is working for me. Can you please suggest what could be the possible reason? Thanks in advance
Sir , i am facing one problem, after converting test scripts into convert to testNG , Convert Refactoring wizard is not opening. AND testng.xml is not generated.
@@RaghavPal It was my bad. i had given annotations of Junit instead of TestNG. Thanks for replying back. I will reach out to you if i face any issues. Thank you.
@@RaghavPal Sir, thank you for the wonderful tutorials. I had a similar issue and it showed up a Run as JUnit Test - I found it had imported import org.junit.Test instead of import org.testng.annotations.Test. After the change, the test worked as expected. Thank you once again!
Hi Asif, pls confirm if the null pointer exception is thrown from annotation or some other statement. Check if the annotations are imported from testng and not any other library. Error details with logs will help.
@@RaghavPal Yeah Error logs does help to make a sense of what went wrong and all that. Exception was thrown from the annotated section of the code. I actually solved it. it was quite straight forward really. I was trying to call the @BeforeTest webDriver but was calling the class variable with null pointer. Rookie mistake. Thank you for responding.
Hello Raghav, Thanks for tutorials. i have installed Testng on eclipse and dependencies but when i excute code the browser is open but tests are not excuted. code : package TEST; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class TestNG_Demo { WebDriver driver = null;
// should run before test
@BeforeTest public void setUpTest(){
String projectPath = System.getProperty("user.dir"); System.setProperty("webdriver.chrome.driver",projectPath+"\\drivers\\chromedriver\\chromedriver.exe"); WebDriver driver = new ChromeDriver();
}
// current test @Test public void googleSearch(){
// goto google.com driver.get("google.com");
// enter text in search text box
driver.findElement(By.name("q")).sendKeys("automation step by step");
} Error: Starting ChromeDriver 2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91) on port 36672 Only local connections are allowed. oct. 05, 2020 1:35:51 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFOS: Detected dialect: OSS can you help me please
@@RaghavPal @Automation Step by Step - Raghav Pal i had changed the version of testNG to the version which work in your tutorial but the same error appear: [RemoteTestNG] detected TestNG version 6.14.3 Starting ChromeDriver 2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91) on port 42775 Only local connections are allowed. oct. 06, 2020 4:23:33 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFOS: Detected dialect: OSS FAILED CONFIGURATION: @AfterTest tearDownTest java.lang.NullPointerException at TEST.TestNG_Demo.tearDownTest(TestNG_Demo.java:56) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142) at org.testng.TestRunner.afterRun(TestRunner.java:725) at org.testng.TestRunner.run(TestRunner.java:509) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) FAILED: googleSearch java.lang.NullPointerException at TEST.TestNG_Demo.googleSearch(TestNG_Demo.java:35) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.Invoker.invokeMethod(Invoker.java:583) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:648) at org.testng.TestRunner.run(TestRunner.java:505) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) =============================================== Default test Tests run: 1, Failures: 1, Skips: 0 Configuration Failures: 1, Skips: 0 =============================================== =============================================== Default suite Total tests run: 1, Failures: 1, Skips: 0 Configuration Failures: 1, Skips: 0 ===============================================
Hi Raghav, Thanks for your videos. These are really helpful and easy to follow. In this video you are opening index.html to see the results from inside eclipse. However when I open index.html from inside eclipse, it is displaying html code only. I can only see the page when i open it using system editor. How do I display the page from inside eclipse as well ?
Hi Jobin, you can either right click on the file and open as system editor, this will use your default browser to open the file. You can also add a browser extension in eclipse stackoverflow.com/questions/8528454/how-do-you-open-the-eclipse-web-browser
Hello Sir, When I run exactly the same code, I am getting the error "[TestNG] No tests found. Nothing was run " I have installed TestNG plugin & Libraries correctly and I have also added annotation @Test before the method.
Hi Sanket, pls check your import statments. The @Test annotation should be imported from import org.testng.annotations.Test; and not junit or any other lib. check this too - stackoverflow.com/questions/56769978/testng-no-tests-found-nothing-was-run-while-executing-automated-tests-using-s
how to take screenshot of failed test cases and how to make method in utility package to capture screenshot in tesNG. Sir is there any video please let me know.
Pankaj Capturing screenshots of failed test cases in Selenium with TestNG in Java is a valuable practice for debugging and reporting. You can create a utility method to take screenshots when a test case fails. Below are the steps to achieve this: 1. **Create a Utility Class:** - Start by creating a utility class that will contain the screenshot capture method. You can name it something like `ScreenshotUtility.java`. 2. **Add Dependencies:** - Make sure you have the necessary dependencies in your project. You need Selenium WebDriver, TestNG, and any required image manipulation libraries (e.g., Apache Commons Imaging). 3. **Capture Screenshots in the Utility Class:** - In your utility class, create a method to capture a screenshot. Here's an example: ```java import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.testng.ITestResult; import org.apache.commons.io.FileUtils; public class ScreenshotUtility { public static void captureScreenshot(WebDriver driver, ITestResult result) { if (result.getStatus() == ITestResult.FAILURE) { try { // Capture the screenshot as a file File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); // Define the destination path for the screenshot String destination = "path/to/save/screenshots/" + result.getName() + ".png"; // Copy the screenshot file to the specified location FileUtils.copyFile(screenshot, new File(destination)); System.out.println("Screenshot taken at: " + destination); } catch (Exception e) { e.printStackTrace(); } } } } ``` Replace `"path/to/save/screenshots/"` with the actual path where you want to save the screenshots. 4. **Use the Utility Method in TestNG Listener:** - To automatically capture screenshots on test failures, you can use a TestNG listener. Create a listener class (e.g., `ScreenshotListener.java`) that implements the `ITestListener` interface and calls the `captureScreenshot` method when a test fails. ```java import org.testng.ITestListener; import org.testng.ITestResult; import org.openqa.selenium.WebDriver; public class ScreenshotListener implements ITestListener { @Override public void onTestFailure(ITestResult result) { Object currentClass = result.getInstance(); WebDriver driver = ((YourTestClass) currentClass).getDriver(); // Replace YourTestClass with your test class name ScreenshotUtility.captureScreenshot(driver, result); } // Implement other ITestListener methods as needed } ``` Ensure that you replace `YourTestClass` with the name of your test class that has the WebDriver instance. 5. **Configure TestNG XML:** - In your TestNG XML file, configure the listener to use the `ScreenshotListener`: ```xml
``` Replace `"your.package.name"` with the actual package name where your `ScreenshotListener` class is located. With these steps, TestNG will automatically trigger the `captureScreenshot` method when a test case fails, and the screenshot will be saved to the specified location. You can then include the captured screenshots in your test reports or use them for debugging. For video tutorials, I recommend searching on platforms like UA-cam or online course platforms for "Selenium TestNG screenshot capture" or similar keywords to find relevant tutorials that demonstrate this process visually.
Thank you dear Raghav. i have a question if you don't mind, i am using java intelij version 14 and maven 3.6.3 and also add testNg dependencies, after running my project i get this error message Error:java: error: release version 5 not supported could you please help me by this? @raghav
Pankaj It is not compulsory to use @AfterMethod or @AfterClass for TestNG CrossBrowser Testing class, if you have used @BeforeClass and @BeforeMethods. However, it is generally considered to be best practice to use @AfterMethod and @AfterClass to clean up after your tests. @AfterMethod is executed after each test method, and @AfterClass is executed after all of the test methods in a class have been executed. This gives you an opportunity to close any open resources, such as web browsers or database connections. For example, the following test class uses @BeforeClass to set up a web browser, and @AfterClass to close the web browser: ``` @Test public class CrossBrowserTest { private WebDriver driver; @BeforeClass public void setUp() { driver = new ChromeDriver(); } @Test public void test1() { // ... } @Test public void test2() { // ... } @AfterClass public void tearDown() { driver.quit(); } } ``` It is important to note that @AfterMethod and @AfterClass are executed even if a test fails. This ensures that your resources are always cleaned up, regardless of the outcome of your tests. Whether or not to use @AfterMethod and @AfterClass is a matter of personal preference. However, using @AfterMethod and @AfterClass can help to make your test code more robust and maintainable
@@RaghavPal thankyou sir for your helpful & valuable response. But there is a test case for login functionality with wrong credentials, as we know if we enter wrong credentials so we should not to be on Home Page. If i use login in @BeforeMethod and @AfterMethod there will be Only option i have that is close the browser and @Test i will Only apply assertion actual results= expected result that means we should get same page URL. In case of login with correct credentials I did not faced any issue and test case result is pass. So what approach i can follow to pass the test case. If you can refer me a video login with wrong credentials in testNG class it will be very helpful and I will be thankful to you. If you create video on it it will definitely helpful to all of us. Thankyou so much sir❤️
To pass the test case for login functionality with wrong credentials in Selenium Java, you can follow the following approach: 1. In the `@BeforeMethod`, create a new WebDriver instance and navigate to the login page. 2. In the `@Test`, enter the wrong credentials and click the login button. 3. Assert that the user is not logged in by checking the current URL. The user should not be able to navigate to the home page with wrong credentials. 4. In the `@AfterMethod`, close the WebDriver instance. Here is an example of a test case for login functionality with wrong credentials in Selenium Java: ```java import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; public class LoginTest { private WebDriver driver; @BeforeMethod public void setUp() { driver = new ChromeDriver(); driver.get("example.com/login"); } @Test public void testLoginWithWrongCredentials() { // Enter the wrong credentials driver.findElement(By.id("username")).sendKeys("invalid_username"); driver.findElement(By.id("password")).sendKeys("invalid_password"); driver.findElement(By.id("login_button")).click(); // Assert that the user is not logged in String currentUrl = driver.getCurrentUrl(); assertEquals(currentUrl, "example.com/login"); } @AfterMethod public void tearDown() { driver.quit(); } } ``` This test case will first create a new Chrome WebDriver instance and navigate to the login page. Then, it will enter the wrong credentials and click the login button. Finally, it will assert that the user is not logged in by checking the current URL. The user should not be able to navigate to the home page with wrong credentials. If the test case passes, it means that the login functionality is working correctly. If the test case fails, it means that there is a bug in the login functionality
@@RaghavPal once again thankyou for your valuable response. I will try and add no of possible @Test with wrong credentials in same testNG crossBrowser class & i will let you know. Thankyou❤
Hi Raghav could you please let us know difference between Before Suite Before Test After Suite After Test annotations.I know it's executed only once but I need to know exactly how and when it's used. Thanks in advance
FAILED CONFIGURATION: @AfterTest tearDownTest org.openqa.selenium.NoSuchSessionException: Tried to run command without establishing a connection Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'DESKTOP-CO6P907', ip: '192.168.1.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191' Driver info: org.openqa.selenium.firefox.FirefoxDriver sir TestNG use krta huoa ya error ahta han Teaddown ma test pass ho jata han but ya error ku ahta han sir kindly bata ga
Hi Faizan, If you are on windows, you can create a bat file for your commands and then schedule using Task Scheduler - www.computerhope.com/jargon/t/tasksced.htm You can also use a CI tool like Jenkins. There are videos on this in the playlist - ua-cam.com/play/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa.html
@@RaghavPal Thanks for your reply on behalf of all the learner I would request you to make a video on "How to run my Java Selenium program automatically every hour " because the link you mentioned I don't find the exact way how to do this I'm new in automation also I really appreciate your work towards automation.
Sorry to hear this. I tried to keep the 1st video like a basic intro. I hope next videos in this series will be more helpful. Pls watch and let me know
Sir i do all same process just like you but "java.lang.NoSuchMethodError: org.testng.remote.AbstractRemoteTestNG.addListener(Lorg/testng/ISuiteListener;)V at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:128) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)" This problem occur please sir give mi solution for this
Hi Raghav, when I run the code in TestNG I'm getting following erros: Error-1) org.testng.TestNGException: TestNG by default disables loading DTD from unsecured Urls. If you need to explicitly load the DTD from a http url, please do so by using the JVM argument [-Dtestng.dtd.http=true] Error-2) [TestNGContentHandler] [WARN] It is strongly recommended to add "" at the top of your file, otherwise TestNG may fail or not work as expected. java.lang.NoSuchMethodError: org.testng.remote.AbstractRemoteTestNG.addListener(Lorg/testng/ISuiteListener;)V But in my Xml file "" is already there. Plz advice me. Thanks
@@RaghavPal Hi Raghav, On yesterdays meeting, my company said, we will not run Selenium Test on Jenkins. We will run on AWS. Please let me know, what tools do we need to run Selenium on AWS? which Tutorial I will start to learn?
@12:52 If you can't find TestNG, MAKE SURE you are adding @Test, @BeforeTest, and @Aftertest ANNOTATIONS. I accidentally added JUnit of which TestNG didn't show when I wanted to run. -,- So simple yet so annoying and time consuming.
Also if you have an issue with maven, go to the project, right click maven and Update the project. Make sure to include the snapshots as well
Thanks for the information
Hi Raghav Thanks for your videos,, Great explanation, All of your courses really helps the beginners. Your time, patience and dedication in making this videos really deserve a salute from me from NZ.
So happy and humbled to see your message Ayyub
Hello Raghav,
Many Many CONGRATULATIONS for Silver Play Button Award.. you deserve it man !
Proud moment, You are really an inspirational. your videos helped me and many others in up scaling.
Take care and stay healthy :)
I have a request for Playlist for cucumber framework in selenium. Pls invest some time in creating it. THANK YOU !
Thanks a lot Rakesh, I will definitely do Selenium with Cucumber soon
I have been told about this sites by one of my friends and I am extremely happy to watch and implement the frame work.Thanks so much.
You are most welcome Rishita
God bless you Sir ! Thanks for the lesson. I've been struggling with selenium learning and now I've found my go-to place
Happy to know this Akida, you will find all here automationstepbystep.com/
This is the best Selenium tutorial i have ever seen so far!
Glad it was helpful!
Thank you very much for this kind of video... it is very easy to understand & learn very quickly. I wish Mr.Raghav Pal keep in good health
Thanks for your message and wishes
Hi Raghav thanks for the videos, I am beginner for these it is grate helpful to me.
Most welcome Umesh
TestNG plugin download link is updated.
New Link: dl.bintray.com/testng-team/testng-eclipse-release
Thanks Ramiz
Thank you for introducing TestNG in such a well prepared and easy to understand manner Raghav!
Glad you liked it Prachi
Thanks, Ragav, you are just amazing!!!! Thank you for all these videos!!!!
Glad you like them Zarko
Hi Raghav...... Thank you for all videos. It is very helpful to me. Thanks alotzz 😇
Most welcome Bhagyashree
Nice Video and the concept is welll explained.
Glad you liked it
testNG have new links now. :) Thanks raghav!
Yes, I will try to update soon
Hi Raghav,
How to run the java file using TestNG after adding Jar files in my project.
I don't have configured Maven in my project and I don't have any POM.XML file.
I'm not getting any option in "Run As"
Hi Pritish, I will suggest you to create a maven project and use pom.xml. Else its going to be difficult to maintain and enhance your project. You can get the playlist here - ua-cam.com/play/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa.html
Hello Raghav, Yours videos are really very helpful. Can you please arrange in sequence i.e. numbering as you did from 1 to 8. After 8 there is no sequence in "Selenium Java Framework Step by Step" video series. Thanks for your kind effort.
Hi Prince, I have updated this . Please check - ua-cam.com/play/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa.html
@@RaghavPal Hi Raghav. Now I believe all videos are logically correct with respect to sequence. Thanks for your kind effort.
You're welcome Prince
TestNG - installation url
dl.bintray.com/testng-team/testng-eclipse-release/
Thanks for adding
Hi good morning!I have a dought Why we need testNG Plugin and libraries both . I am thinking those act like client and server is it correct
Hi Samdani, testNG library enables to use the testng functionalities, annotations in your project and TestNG plugin on eclipse enables to run our scripts as TestNG
This video is really good and helpful
Most welcome Ashwini
Thank you so much... This saved my Day.
Thank you very much for the excellent course!
You're welcome Tasha
Very Helpful, Thank you Raghav.
Most welcome Mushfiqua
Very nice session well explained
Thanks Vipin
Really nice all your videos! Thanks for share! 😎👌
You're welcome Orlando
Hello Sir, plz make video on framework level work that is being implemented in companies. Plz try to show it with small project on automation....so that we will be clear about how selenium webdriver with java works in actual.
Hi Rajendra, I will do
@@RaghavPal Thank you Sir....
Sir please make video on keyword driven and data driven frame work
I will Ruchi, definitely
Hi Raghav Sir, I m using java project instead of maven project for all your examples and I didn't get any problem during TestNG installation and execution, but at point 13:54 I followed all steps Refresh project-> test_output folder-> clicked on "index.html" as per your instruction it open up like BELOW HTML DOC instead of proper test report like yours and I also tried to open test results html in default text editor but the result was same as below. Please Help.
--------------------------------------------------------------------
TestNG reports
google.load('visualization', '1', {packages:['table']});
google.setOnLoadCallback(drawTable);
var suiteTableInitFunctions = new Array();
var suiteTableData = new Array();
Hi, that's okay, May be your eclipse does not have an in built browser. You can get one from Help > Eclipse marketplace Or just right click and open with system editor (i.e. your system's default browser)
@@RaghavPal It is working fine with "System editor"..Thankyou :)
Hello Raghav, How can we use testNG in page object model ?
Yes, we can Sanket
@@RaghavPal Sir How can we test login page with encrypted password? . please help sir
Hi Sanket, you can use some encoding libraries like base64 - www.quora.com/How-do-I-encrypt-the-password-while-programming-in-Java-for-automating-an-application-in-Selenium
Thank you so much for the video. What ever we get the latest version....we have to download it right!!!
Yes Sajitha, can go with the latest stable ver
Hi Raghav, your explanation for all videos are very nice like Selenium,Log4j. If possible please share playlist url for TestNG.
Hi Sreelatha, you can check this playlist. I will add more videos soon to this
SELENIUM JAVA FRAMEWORK BEGINNERSua-cam.com/play/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa.html
Hi Raghav,
I followed the steps in the video but the test did not run.
I am getting this error: java.lang.NoSuchMethodError: org.testng.TestRunner.addListener(Ljava/lang/Object;)
How to solve this? Please help
Hi Nirmala, will have to see your code, In the logs pls check if you get more information like from which line in code is this error thrown etc.
Hi Nirmala, I tried with below solution and it worked for me in Eclipse :
Go to Project -> Properties -> Java Build path -> Libraries -> Click on Add Library and select TestNG -> Next and Finish
Hey Raghav... Thank you so much for sharing such knowledge. Can you pls provide a video link for code you mentioned in set up function
Thanks again
Hi Narendra, check this github.com/Raghav-Pal/SeleniumJavaFramework1
@@RaghavPal Thanks Raghav for replying.... I am a very beginner at this point of time. actually I wanted to understand that code part through video if you have created for it. Because what you have shared is git, I am not sure what to look. Please share a video link if you have.
Okay, using github repo url you can actually clone the project and see my complete code. You can also find tutorials on how to clone project from github.
In case you want to understand the coding, I will suggest that you see the Java Beginners playlist here - automationstepbystep.com/
Hi sir I am big fan of your.... Please make videos on docker also.... Thanks God bless you
Hi Arslan, thanks a lot. I am humbled. You can check Docker playlist here -
ua-cam.com/play/PLhW3qG5bs-L99pQsZ74f-LC-tOEsBp2rK.html
Sir can you please create two more classes with POM and create a testng suite?
I will plan in a new series Peter
Hi Raghav, I have used to Microsoft Online Excel Sheet. How to use online excel sheets at data-driven testing?
Hi Sathish, if you have some url where it can be accessed and data can be retrieved, it will work. I have not used it so will need to check more online
hello. i have a question why do we use maven project?
So we can manage dependency effectively
Can we say that TestNG is used for Generating test reports as well.
Yes testng can generate reports, You can use extent reports also, that is explained in later videos
Your videos are very helpful for beginners like us thank you so much :) for uploading such kind of useful videos...Please also upload videos for cracking interview questions for automation QAs in ( Selenium + C#) or (Selenium +Java).
I will do. Thanks for the message
Very helpful... Thank you so much sir
Most welcome Uday
Is it possible to just add dependency in pom? For IDEA IntelliJ? Because it works for me like that? :)
It is possible to just add the TestNG dependency in your pom.xml file for IntelliJ IDEA, and it should work as expected. There's no need for any additional configuration unless you have specific customizations in mind.
Here's a breakdown of the process:
1. Open your project's `pom.xml` file.
2. Navigate to the `dependencies` section.
3. Add the following dependency snippet:
```xml
org.testng
testng
7.4.0 test
```
4. Save the `pom.xml` file.
5. Refresh your project dependencies in IntelliJ IDEA (usually by right-clicking on the project in the Project tool window and selecting "Maven -> Reimport").
After these steps, TestNG should be recognized and ready for use in your project. You can create TestNG test classes with the `@Test` annotation and run them directly within IntelliJ IDEA.
Hi Raghav, If I am running LoginPageTest Class that has testCase, I have no issues.
As I create another class (MaintenanceClass) within the same package and call loginPageTest class I get NullPointerException. Any thoughts ?
Hi Sai, looks like you are referring an object that has null value, Some issue in your class and object creation, pls check again
@@RaghavPal I extended BasePage class yet I was getting NullPointerException. So I have accessed test case method by making it static and access using Class name rather than creating class object. I still don't understand but I was able to achieve. Thanks though!
Hi Raghav,
For some reason I have the same Test_GoogleSearch.java file word for word. When I run it the browser opens but nothing happens. I checked it many times but it's the same. Message reads "No tests found. Nothing was run", but there is a test.
Hi James, pls check if you have added the annotation @Test above your test method
Hi Raghav sir, i didnt understand how the pom xml came how to understand that.
Hi Trambak, Have you watched the earlier videos. Pls check the playlist automationstepbystep.com/
Hi raghav Thanks for explaining.just one doubt.
If i create a maven project and added testng dependency without adding testng plugin.
I am able to see testng annoations but run as tetng is not visible.For sure i have to add testng plugin in my eclipse Ide?can you please explain on this?
Hi Dheeraj, when you add testng maven dependency, you can use TestNG annotations in your test, but to run your tests as TestNG you will need testng plugin in Eclipse
This video was very useful. Thanks
You're welcome Shaji
hi sir- i could see a folder name drivers below maven dependencies- can you please tell how to add that- because it throws an error on my code on webelement and driver( i tried importing- it still shows error)
And also i have followed all the steps you have mentioned- but not getting run as - testng option
can you assist please
Hi Priyanka,
Sure, I can help you with that.
Adding drivers folder in Maven project:
You can add the drivers folder to your Maven project by following these steps:
Create a new folder named drivers in the root directory of your project.
Inside the drivers folder, create subfolders for the different drivers you want to use, for example, chromedriver, geckodriver, etc.
Download the corresponding driver executable files and save them in their respective subfolders. You can download the latest driver versions from the official websites of the browser vendors.
In your Maven project, open the pom.xml file and add the following code:
org.apache.maven.plugins
maven-resources-plugin
3.1.0
copy-resources
validate
copy-resources
${project.build.directory}/classes
${project.basedir}/drivers
@@RaghavPal thanks alot for your kind help
Hi raghav,
I have searched for TestNG in the marketplace, but not listed there in the result section. When I tried through Install New Software options, it doesn't display testNG icon in the list. Is there any solution for this or any alternate way to install?
Hi Albin, what is your eclipse ver. Maybe you can try searching for eclipse specific ver.
@@RaghavPal its eclipse 2018-12
@@RaghavPalI got it. I tried with install option again
is there any way i can take your class in person since i live in US
Hi Amanuel, As of now there are no personal classes planned. You can follow and ask your queries here. Can see all courses here automationstepbystep.com/online-courses/
Very Nice Sir...👍
Thanks for watching
Thank you for this series!!!! Very helpfull.
You're very welcome Vishvam
Videos on Intelli J selenium, please!
Sure, I will
Sir hindi me bhi banaya kijiye.
fast samajh me aata h.
Thank you.
Jai Hind!!
I will try
Whats is testng equivalent for python raghav?
This can help stackoverflow.com/questions/45323248/how-to-achieve-testng-like-feature-in-python-selenium-or-add-multiple-unit-test
Hello Raghav, Thanks so much for making these videos. They are super helpful! In this video we are installing TestNG separately, could you please explain why adding the dependency in pom.xml not be enough.
Hi Radhika, by adding TestNG dependency, you can use testng annotations in your functions, However to run your scripts as TestNG tests in Eclipse, you will need to add the extension.
Hey, I followed your all the steps from start, no error and exception in the run. But it is giving me the option "Run as -> Junit Test". i have added all the TestNG dependencies and they can be seen in Maven dependcies but its is not giving me thr Run option with TestNG why?
Hi Safia, just check the import statements. Pls make sure you import from testng and not from junit.
Hello Raghav sir,
To add TestNG libraries, you are using POM.xml which I don't have.
I have watched your other video and installed maven on my machine but I am not sure how to create dependencies and create this pom.xml.
I did not find it under Maven folder either (it only has up to installation).
Do you have a video that describes how we can create pom.xml and add maven dependencies?
Appreciate your efforts and response.
Thank you
Hi Amit, this is a complete series, not sure if you missed any video. Here is the playlist - ua-cam.com/play/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa.html
@@RaghavPal
Hi Raghav,
I am so sorry for bothering you for this
Thank you
sir base class creation and all was previously in this session I guess I am unable to see now
please help
Priyanka
I have not changed anything in this playlist. can check again from the Playlist here - automationstepbystep.com/
Hello, I have followed all your steps but I am not getting the TestNG option in the run configuration.
Hi Rupali,
Try to restart Eclipse after installing TestNG plugin
Hello Raghav, When i am downloading TestNG in my mac for eclipse IDE, i'm getting error "An error occurred while collecting items to be installed" . Can you help in identifying the issue?
Please ignore this i downloaded it from Eclipse marketplace
Great, thnx for posting Deepali
Hello
I had to change looking for the button by xpath because it wasn't working by name
do you know why ?
thanks
I will need to check logs
thanks for your lesson
You are welcome Pooja
Hi Raghav, i followed all the steps as mentioned. But when i try to run it doesn't display Run as : Test NG case. I have installed the plugin as well as dependencies. but still nothing is working for me. Can you please suggest what could be the possible reason?
Thanks in advance
Hi Aarti, did you restart eclipse after adding testng plugin, try to install again & also check ver compatibility
Sir , i am facing one problem, after converting test scripts into convert to testNG , Convert Refactoring wizard is not opening. AND testng.xml is not generated.
Hi Jeevan, have you added testng plugin
@@RaghavPal yes sir , script is also executed but TESTNG.XML is not generated.
Hi i am following ur channel for Selenium
I am stuck with an issue. Please let me know how can i reach you.
Sure Dilip, explain your issue here
@@RaghavPal It was my bad. i had given annotations of Junit instead of TestNG. Thanks for replying back.
I will reach out to you if i face any issues. Thank you.
Hi @Raghav Sir, I have followed the same steps, but while running the java, run as I can only see junit not TestNG. Kindly suggest.
Thanks.
Hi Animesh, that means you have not added TestNG PLUGIN in Eclipse or have not restarted after adding
@@RaghavPal Sir, thank you for the wonderful tutorials. I had a similar issue and it showed up a Run as JUnit Test - I found it had imported import org.junit.Test instead of import org.testng.annotations.Test. After the change, the test worked as expected. Thank you once again!
Thanks for this lesson, would be nice to make the same with IntelliJ Idea and the latest Selenium 4
Great suggestion André
Very helpful. 🙂
Glad it was helpful Nirmal
@Test and @AfterTest throws Null Pointer exception!! !! trying binding them with some referred jars still no better response!!
nullpointer exception on WebDriver object to be specific!!
Hi Asif, pls confirm if the null pointer exception is thrown from annotation or some other statement. Check if the annotations are imported from testng and not any other library. Error details with logs will help.
@@RaghavPal Yeah Error logs does help to make a sense of what went wrong and all that. Exception was thrown from the annotated section of the code. I actually solved it. it was quite straight forward really. I was trying to call the @BeforeTest webDriver but was calling the class variable with null pointer. Rookie mistake. Thank you for responding.
Glad to know its resolved. Keep learning.
Hello Raghav, Thanks for tutorials. i have installed Testng on eclipse and dependencies but when i excute code the browser is open but tests are not excuted.
code :
package TEST;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class TestNG_Demo {
WebDriver driver = null;
// should run before test
@BeforeTest
public void setUpTest(){
String projectPath = System.getProperty("user.dir");
System.setProperty("webdriver.chrome.driver",projectPath+"\\drivers\\chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
}
// current test
@Test
public void googleSearch(){
// goto google.com
driver.get("google.com");
// enter text in search text box
driver.findElement(By.name("q")).sendKeys("automation step by step");
// click on search button
//driver.findElement(By.name("btnK")).click();
driver.findElement(By.name("btnK")).sendKeys(Keys.RETURN);
}
// should run after test
@AfterTest
public void tearDownTest(){
//close browser
driver.close();
driver.quit();
System.out.println("test completed successfully");
}
}
Error:
Starting ChromeDriver 2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91) on port 36672
Only local connections are allowed.
oct. 05, 2020 1:35:51 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFOS: Detected dialect: OSS
can you help me please
Hi Zitouni, Pls check if the chromedriver.exe ver is same as the chrome ver on your system.
@@RaghavPal google chrome version Version 85.0.4183.121 et chromewebridver 2.36.540470. thanks for help
tests are excuted without problem but with TestNG the browser is open but test is not excuted
Will need to check the setup, Do you get any error in logs
@@RaghavPal @Automation Step by Step - Raghav Pal i had changed the version of testNG to the version which work in your tutorial but the same error appear:
[RemoteTestNG] detected TestNG version 6.14.3
Starting ChromeDriver 2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91) on port 42775
Only local connections are allowed.
oct. 06, 2020 4:23:33 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFOS: Detected dialect: OSS
FAILED CONFIGURATION: @AfterTest tearDownTest
java.lang.NullPointerException
at TEST.TestNG_Demo.tearDownTest(TestNG_Demo.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.TestRunner.afterRun(TestRunner.java:725)
at org.testng.TestRunner.run(TestRunner.java:509)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
FAILED: googleSearch
java.lang.NullPointerException
at TEST.TestNG_Demo.googleSearch(TestNG_Demo.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================
I have question can we use TestNG IN Project Object Model?
Because i tried but kept giving me error thats why
Hi Salim, you can use, What is the error you are getting
Hi Raghav, Thanks for your videos. These are really helpful and easy to follow.
In this video you are opening index.html to see the results from inside eclipse. However when I open index.html from inside eclipse, it is displaying html code only. I can only see the page when i open it using system editor. How do I display the page from inside eclipse as well ?
Hi Jobin, you can either right click on the file and open as system editor, this will use your default browser to open the file. You can also add a browser extension in eclipse stackoverflow.com/questions/8528454/how-do-you-open-the-eclipse-web-browser
Cannot perform operation computing alternate solutions may take a while nu varudhu correcta
Hi Raja, pls explain your issue in detail
Sir , firstly thank you for the tutorial.. Is there any tutorial for JBehave Selenium..? Our Project Using that
Hi Nasr, not yet on JBehave
Hello Sir, When I run exactly the same code, I am getting the error "[TestNG] No tests found. Nothing was run
" I have installed TestNG plugin & Libraries correctly and I have also added annotation @Test before the method.
Hi Sanket, pls check your import statments. The @Test annotation should be imported from import org.testng.annotations.Test;
and not junit or any other lib.
check this too - stackoverflow.com/questions/56769978/testng-no-tests-found-nothing-was-run-while-executing-automated-tests-using-s
@@RaghavPal Thank you so much Raghav sir. I was mistakenly imported from junit lib, by seeing this comment I can able to resolve my error.
how to take screenshot of failed test cases and how to make method in utility package to capture screenshot in tesNG. Sir is there any video please let me know.
Pankaj
Capturing screenshots of failed test cases in Selenium with TestNG in Java is a valuable practice for debugging and reporting. You can create a utility method to take screenshots when a test case fails. Below are the steps to achieve this:
1. **Create a Utility Class:**
- Start by creating a utility class that will contain the screenshot capture method. You can name it something like `ScreenshotUtility.java`.
2. **Add Dependencies:**
- Make sure you have the necessary dependencies in your project. You need Selenium WebDriver, TestNG, and any required image manipulation libraries (e.g., Apache Commons Imaging).
3. **Capture Screenshots in the Utility Class:**
- In your utility class, create a method to capture a screenshot. Here's an example:
```java
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.testng.ITestResult;
import org.apache.commons.io.FileUtils;
public class ScreenshotUtility {
public static void captureScreenshot(WebDriver driver, ITestResult result) {
if (result.getStatus() == ITestResult.FAILURE) {
try {
// Capture the screenshot as a file
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
// Define the destination path for the screenshot
String destination = "path/to/save/screenshots/" + result.getName() + ".png";
// Copy the screenshot file to the specified location
FileUtils.copyFile(screenshot, new File(destination));
System.out.println("Screenshot taken at: " + destination);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
```
Replace `"path/to/save/screenshots/"` with the actual path where you want to save the screenshots.
4. **Use the Utility Method in TestNG Listener:**
- To automatically capture screenshots on test failures, you can use a TestNG listener. Create a listener class (e.g., `ScreenshotListener.java`) that implements the `ITestListener` interface and calls the `captureScreenshot` method when a test fails.
```java
import org.testng.ITestListener;
import org.testng.ITestResult;
import org.openqa.selenium.WebDriver;
public class ScreenshotListener implements ITestListener {
@Override
public void onTestFailure(ITestResult result) {
Object currentClass = result.getInstance();
WebDriver driver = ((YourTestClass) currentClass).getDriver(); // Replace YourTestClass with your test class name
ScreenshotUtility.captureScreenshot(driver, result);
}
// Implement other ITestListener methods as needed
}
```
Ensure that you replace `YourTestClass` with the name of your test class that has the WebDriver instance.
5. **Configure TestNG XML:**
- In your TestNG XML file, configure the listener to use the `ScreenshotListener`:
```xml
```
Replace `"your.package.name"` with the actual package name where your `ScreenshotListener` class is located.
With these steps, TestNG will automatically trigger the `captureScreenshot` method when a test case fails, and the screenshot will be saved to the specified location. You can then include the captured screenshots in your test reports or use them for debugging.
For video tutorials, I recommend searching on platforms like UA-cam or online course platforms for "Selenium TestNG screenshot capture" or similar keywords to find relevant tutorials that demonstrate this process visually.
Thank you dear Raghav. i have a question if you don't mind, i am using java intelij version 14 and maven 3.6.3 and also add testNg dependencies, after running my project i get this error message Error:java: error: release version 5 not supported
could you please help me by this? @raghav
Hi, this can help stackoverflow.com/questions/59601077/intellij-errorjava-error-release-version-5-not-supported
Sir is it compulsory to use @AfterMethod or @AfterClass for TestNG CrossBrowser Testing class, if we have used @BeforeClass and @BeforeMethods..??
Pankaj
It is not compulsory to use @AfterMethod or @AfterClass for TestNG CrossBrowser Testing class, if you have used @BeforeClass and @BeforeMethods. However, it is generally considered to be best practice to use @AfterMethod and @AfterClass to clean up after your tests.
@AfterMethod is executed after each test method, and @AfterClass is executed after all of the test methods in a class have been executed. This gives you an opportunity to close any open resources, such as web browsers or database connections.
For example, the following test class uses @BeforeClass to set up a web browser, and @AfterClass to close the web browser:
```
@Test
public class CrossBrowserTest {
private WebDriver driver;
@BeforeClass
public void setUp() {
driver = new ChromeDriver();
}
@Test
public void test1() {
// ...
}
@Test
public void test2() {
// ...
}
@AfterClass
public void tearDown() {
driver.quit();
}
}
```
It is important to note that @AfterMethod and @AfterClass are executed even if a test fails. This ensures that your resources are always cleaned up, regardless of the outcome of your tests.
Whether or not to use @AfterMethod and @AfterClass is a matter of personal preference. However, using @AfterMethod and @AfterClass can help to make your test code more robust and maintainable
@@RaghavPal thankyou sir for your helpful & valuable response.
But there is a test case for login functionality with wrong credentials, as we know if we enter wrong credentials so we should not to be on Home Page. If i use login in @BeforeMethod and @AfterMethod there will be Only option i have that is close the browser and @Test i will Only apply assertion actual results= expected result that means we should get same page URL.
In case of login with correct credentials I did not faced any issue and test case result is pass.
So what approach i can follow to pass the test case.
If you can refer me a video login with wrong credentials in testNG class it will be very helpful and I will be thankful to you. If you create video on it it will definitely helpful to all of us.
Thankyou so much sir❤️
To pass the test case for login functionality with wrong credentials in Selenium Java, you can follow the following approach:
1. In the `@BeforeMethod`, create a new WebDriver instance and navigate to the login page.
2. In the `@Test`, enter the wrong credentials and click the login button.
3. Assert that the user is not logged in by checking the current URL. The user should not be able to navigate to the home page with wrong credentials.
4. In the `@AfterMethod`, close the WebDriver instance.
Here is an example of a test case for login functionality with wrong credentials in Selenium Java:
```java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class LoginTest {
private WebDriver driver;
@BeforeMethod
public void setUp() {
driver = new ChromeDriver();
driver.get("example.com/login");
}
@Test
public void testLoginWithWrongCredentials() {
// Enter the wrong credentials
driver.findElement(By.id("username")).sendKeys("invalid_username");
driver.findElement(By.id("password")).sendKeys("invalid_password");
driver.findElement(By.id("login_button")).click();
// Assert that the user is not logged in
String currentUrl = driver.getCurrentUrl();
assertEquals(currentUrl, "example.com/login");
}
@AfterMethod
public void tearDown() {
driver.quit();
}
}
```
This test case will first create a new Chrome WebDriver instance and navigate to the login page. Then, it will enter the wrong credentials and click the login button. Finally, it will assert that the user is not logged in by checking the current URL. The user should not be able to navigate to the home page with wrong credentials.
If the test case passes, it means that the login functionality is working correctly. If the test case fails, it means that there is a bug in the login functionality
@@RaghavPal once again thankyou for your valuable response. I will try and add no of possible @Test with wrong credentials in same testNG crossBrowser class & i will let you know. Thankyou❤
I’m unable to install testNG in eclipse as the url is not found,can you help?
Hi Vanitha, check if the url is changed, You can see documentation here github.com/cbeust/testng-eclipse/
I had to upgrade my eclipse from oxygen to latest version. I could then install testNG successfully.Thank you.
sir pls help , i am getting this error "java.nio.file.FileAlreadyExistsException"
Hi Shreyansh, pls check if the file mentioned is saved and closed
@@RaghavPal ok thank you ji
Hi Raghav could you please let us know difference between Before Suite Before Test After Suite After Test annotations.I know it's executed only once but I need to know exactly how and when it's used. Thanks in advance
Hi Rajesh, I will plan to add a session on that. For now this can help www.browserstack.com/guide/testng-listeners
Thank You Very much sir
Most welcome Bharat
Very useful...thanks
You're welcome Sathish
you are great that what i can say about all , thank youu so much for your help
Humbled to see your message.
Not able to click on hyperlink and select drop down values
Hi Mukta, what is the issue you are facing, You can check some online examples and try
@@RaghavPal I have try online example but not able to click on sidebar element
I will check this Mukta
pom.xml is missing
Hi Arjun, hope you created a maven project and followed all steps as shown in earlier videos
FAILED CONFIGURATION: @AfterTest tearDownTest
org.openqa.selenium.NoSuchSessionException: Tried to run command without establishing a connection
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-CO6P907', ip: '192.168.1.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
sir TestNG use krta huoa ya error ahta han Teaddown ma test pass ho jata han but ya error ku ahta han sir kindly bata ga
Looks like your driver is not visible to the script. Try to follow the same steps from the video.
Hi Shariff. Try only with close() . . it worked for me stackoverflow.com/questions/46902102/error-in-fire-fox-selenium-web-driver
Thanks raghav!
You're welcome Neil
Nice sir ji
Thanks Swapnil
Plzz help me that How to run my Java Selenium program automatically every hour
.
Hi Faizan, If you are on windows, you can create a bat file for your commands and then schedule using Task Scheduler -
www.computerhope.com/jargon/t/tasksced.htm
You can also use a CI tool like Jenkins. There are videos on this in the playlist - ua-cam.com/play/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa.html
@@RaghavPal Thanks for your reply on behalf of all the learner I would request you to make a video on "How to run my Java Selenium program automatically every hour
" because the link you mentioned I don't find the exact way how to do this I'm new in automation also I really appreciate your work towards automation.
Sure, I will plan Faizan
Thank you! 👍👍👍
You're welcome
Thank you
You're welcome Zheng
Sorry you did not give TestNG overview very well in the beginning part of video. Instead you were showing how to google it and read on wiki site.
Sorry to hear this. I tried to keep the 1st video like a basic intro. I hope next videos in this series will be more helpful. Pls watch and let me know
thank you very much
Most welcome Nawid
Sir i do all same process just like you but "java.lang.NoSuchMethodError: org.testng.remote.AbstractRemoteTestNG.addListener(Lorg/testng/ISuiteListener;)V
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:128)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)"
This problem occur please sir give mi solution for this
Hi Rohini, pls check the testng plugin is the latest and compatible with your eclipse github.com/cbeust/testng-eclipse/
Try to add TestNG jar files manually, refer to this video may be it will be helpful ua-cam.com/video/K9cqFsuTwtE/v-deo.html
Hi Raghav, when I run the code in TestNG I'm getting following erros:
Error-1) org.testng.TestNGException:
TestNG by default disables loading DTD from unsecured Urls. If you need to explicitly load the DTD from a http url, please do so by using the JVM argument [-Dtestng.dtd.http=true]
Error-2) [TestNGContentHandler] [WARN] It is strongly recommended to add "" at the top of your file, otherwise TestNG may fail or not work as expected.
java.lang.NoSuchMethodError: org.testng.remote.AbstractRemoteTestNG.addListener(Lorg/testng/ISuiteListener;)V
But in my Xml file "" is already there.
Plz advice me.
Thanks
Hi Rahul, pls check the syntax again in the xml file, just in case some typo or spaces etc. Can also try a diff ver
Thank you :)
You're welcome Natasa
Hi
Hi Mukta
:)
Very Helpful, Thank you Raghav
Most welcome Mushfiqua
@@RaghavPal Hi Raghav, On yesterdays meeting, my company said, we will not run Selenium Test on Jenkins. We will run on AWS. Please let me know, what tools do we need to run Selenium on AWS? which Tutorial I will start to learn?
Hi Mushfiqua, I believe they are referring to AWS ec2 machines, If that is true pls ask where exactly they plan to run on AWS, ec2
@@RaghavPal Hi Raghav, I haven't got that answer yet. But guessing, Yes.
@@RaghavPal Would you pleeeeease make a video/series on Running Selenium Tests on AWS.
thank you
You're welcome