Tag: testng

Data Driven Testing in TestNG

Data Provider feature helps you to write data-driven tests, which essentially means that same test method can be run multiple times with different data-sets. It helps in providing complex parameters to the test methods as it is not possible to do this from testng.xml file. Please note that @DataProvider is the second way of passing parameters to test methods (first way we already discussed in @Parameters example). You can use it to handle a broad range of complex parameters like the following. Java objects. Objects read from a database. Data from Excel or property file etc. Facts about “@dataprovider”: This annotation has one string attribute which is its name. If you don’t specify a name, then the method’s name serves as the default name. A data provider method

Parallel Execution in TestNG

Parallel Execution of test methods in TestNG TestNG provides multiple ways to execute tests in separate threads. In testng.xml, if we set ‘parallel‘ attribute on the tag to ‘tests‘,  testNG will run all the ‘@Test’ methods in tag in the same thread, but each tag will be in a separate thread. If we want to run methods/classes in separate threads, we need to set ‘parallel‘ attribute on the tag to ‘methods‘ / ‘classes‘ TestNG provides an ability to run test methods, test classes and tests in parallel. By using parallel execution, we can reduce the ‘execution time‘ as tests are started and executed simultaneously in different threads. **A thread is an independent path of execution within a program. Every thread in Java is created and controlled by the java.lang.Thread class.

Optional Annotation in TestNG

Optional Annotation in TestNG As we know, we can pass parameter values to the test methods during run time from testng.xml file by specifying Parameters annotation to test method. To do this, we need to declare parameters tag in xml file using ‘name’ and ‘value’ attribute. Where the name attribute of the tag defines name of the parameter and the value attribute defines the value of the parameter. If defined parameter is not found in your testng.xml file, The test method will receive the default value which is specified inside the @Optional annotation. Syntax to define Parameter: <parameter name="param" value="Value of parameter" /> Syntax to define @Optional annotation @Parameters("browser") @Test public void method1(@Optional("Optional Value") String val

TestNG Assertions

TestNG Assertions: While using Selenium for automated testing of web applications, we need to add validations in our tests to report them as pass or fail. And assertions can let us do that within a single line of code. Here, you’ll learn how to use TestNG assertions and know the different methods to assert conditions. Assertions give you a way, other than If-Else blocks, to test conditions. They are not only easy to use but also eliminate the chances of making any error in forming test conditions. Hence, it’s always beneficial to use them in Selenium WebDriver projects. There are two types of assertions in Selenium that we can place in our test scripts using TestNG: Hard Assertion. Soft Assertion. 1- Hard Assertion: It is the default assert mechanism built into TestNG’

TestNG Groups

TESTNG – TEST GROUPS, META GROUP, DEFAULT GROUP   TestNG – Test Groups, Meta Group, Default Group  Grouping test methods is one of the most important features of TestNG. In TestNG users can group multiple test methods into a named group. You can also execute a particular set of test methods belonging to a group or multiple groups. This feature allows the test methods to be segregated into different sections or modules. For example, you can have a set of tests that belong to sanity test where as others may belong to regression tests. You can also segregate the tests based on the functionalities/features that the test method verifies. This helps in executing only a particular set of tests as and when required. Example: Group Test Let’s create a test class as G


Class level annotations in TestNG: TestNG has the feature to define annotations on a class instead of a each test method. Let’s say there are 20 test methods, where adding @Test on a class level is simpler than adding @Test for each method. When we make class level @Test annotation, all the public methods of this class will become test methods even if they are not annotated. We can still define @Test annotation on of the method if we want to add any attributes to particular test method. Example: @Test annotation at class level: package Annotations; import org.testng.annotations.Test;@Test public class ClassLevelAnnotations { public void Register() { System.out.println("===Register TestCase Executed==="); } public void Login() { System.out.println("==

@Test Attributes

HOW TO SKIP EXCEPTION TEST IN TESTNG Using TestNG, we have multiple ways to Skip a test based on our requirement. We can Skip complete test without executing it or we can Skip a test when a specific condition is not satisfied. Case 1: In TestNG, @Test(enabled=false) annotation is used to skip a test case if it is not ready to test. We don’t need to import any additional statements. As in JUnit, TestNG will not show you the other test method as Skipped or Ignored. It will not consider that case method at all when the annotation is mentioned as “@Test(enabled=false)”. Case 2: And We can Skip a test by using TestNG Skip Exception if we want to Skip a particular Test. Syntax: throw new SkipException(“message”); Case 3: we can also perform a CONDITIONALSkip, i.e. we can ha

Include & Exclude Tests in testng.xml

How to Include/Exclude Selected Test Methods Using testng.xml File In this Post I will explain you, how you can include/exclude selected test methods from execution. First of all configure your Project Structure as below. Step 1: Create package = “TestNGPack1” and under this package Create classes as Program1.java and Program2.java Step 2: Create package = “TestNGPack2” and under this package Create classes as Program3.java and Program4.java Each Class containing two methods as shown in below image. Once done with above steps your Project structure will look like this.   Program1.java package TestNGPack1; import org.testng.annotations.Test; public class Program1 { //@Test annotation describes this method as a test method @Test public void TC0

testng.xml File with TestNG

In any project, you will end up to a place where you need to execute so many test cases on a run. Running a set of test cases together is call executing a Test Suite. Those test cases can be dependent to each other or may have to be executed in a certain order. The main advantage of using TestNG framework in Selenium is its ease of running multiple tests from multiple classes using just one configuration In TestNG framework, we need to create testng.xml file to create and handle multiple test classes. Testng.xml is an XML file that describes the runtime definition of a test suite. It describes complex test definition while still remain easy to edit. Using Testng.xml file we can run test available in one or more class file and make them as a single group, hence making test more mea

TestNG Report

TESTNG REPORTING:   A perfect test automation tool is what you need for the successful execution of the testing requirements in the Agile process. And there are multiple factors which play a critical role in the formation of a robust automation framework. One such factor is reporting which not only make you aware of the status of the success or failure but helps you in finding out the potential bugs. So, you should mindfully choose how you are going to generate reports in Selenium WebDriver project. That’s where this post would lead you to make a decision. TestNG Reporting: TestNG library brings a very convenient reporting feature. Once you execute the tests, TestNG generates a test output folder at the root of the project. It combines two kinds of reports. 1.D


Annotations are nothing but a piece of instruction for the compiler that you apply to classes, methods or variables in your Java code. It is a powerful feature and an integral part of the TestNG framework. There are multiple TestNG annotations which you can use for different tasks. It is essential to know each of the annotation so that you could apply them correctly while working on a TestNG Selenium WebDriver project.  Let’s see what the TestNG annotations for Selenium WebDriver are and what is their objective? The TestNG annotations extend the same concept and control the execution sequence of the test code and test methods. I’ve drilled down the list of primary TestNG annotations along with a little detail about each of them. TestNG Annotations Description @Test

TestNG With Selenium

TestNG, as the name suggest, is the next generation test automation tool that fills the gaps in the JUnit framework. The basic idea behind the inception of these tools was to cut down the unit testing efforts during the Java development. However, these tools are now being utilized by the software testers for test-driven development. Since TestNG is the new entrant, it brings a list of cool features like TestNG annotations, parallel execution, test case management, effective reporting and much more. Interestingly, there is a TestNG plugin that we can integrate with the Eclipse IDE and instantly start creating TestNG projects in Eclipse.   How to Install TestNG in Eclipse IDE Just to talk a little about the TestNG features such as annotations, they are like the small hooks ye