Posts

Showing posts with the label TestNG

Top 21 Selenium TestNG Framework Interview Questions and Answers

Image
TestNG is a popular testing framework for Java applications that enables developers to write automated tests for their code. It provides a rich set of features and annotations that help testers create efficient and comprehensive test suites.  If you are preparing for a TestNG interview, you may be asked a wide range of questions related to the framework. In this blog post, we will cover some of the most commonly asked TestNG interview questions along with their answers and coding examples. What is TestNG and what are its advantages? Answer: TestNG is a testing framework for Java that is designed to cover all categories of tests: unit, functional, end-to-end, integration, and more. TestNG offers several advantages over other testing frameworks, including: Flexible test configuration: TestNG allows testers to configure tests using XML files or Java code. This flexibility makes it easier to customize tests and run them in different environments.

How to Capture a Screenshot with Selenium and TestNG Listeners

Image
In my opinion, you should avoid the following: using static drivers  (because using static variables is a bad practice) using static methods for taking screenshots  (because using static methods is a bad practice) taking screenshots in the test methods  (because you will duplicate code in lots of tests) taking screenshots in the @After methods  (because you don't need to do this) I prefer to take the screenshots using a TestNG listener as follows. 1. Create a Class for taking the Screenshots Every time you need to take a screenshot, create an object for this class and use the capture method. The capture method will take the screenshot and save it in the screenshots folder. package framework ; import java . io . File ; import java . io . FileOutputStream ; import org . openqa . selenium . OutputType ; import org . openqa . selenium . TakesScreenshot ; import org . openqa . selenium . WebDriver ;   public class Screenshot { private WebDriver dr