This category contains 15 posts

Dears Listeners…stand in Q please

Yes, you read the title right.. but I was not hinting at you the readers.. but I was referring to the TestNG listeners¬†. We have all at some point or the other wondered.. what if I could have my listeners follow some order when they are being executed by TestNG. I too wondered this. There … Continue reading

Testcase specific logs for a Selenium project

Problem statement: You would like to have a separate log file for every testcase so that if there are failures, its very easy for you to be able to debug and find out failures. For going through this, I am going to be using a selenium based test as an example. Selenium has a webdriver … Continue reading

How to run test methods in parallel but test classes in sequence

This question came up recently on the TestNG forum. Since when solving this question I had a chance to use one of the lesser known features of TestNG, I thought I should perhaps capture this as a blog so that it can help someone. Here’s the problem statement : A user on the forum wanted … Continue reading

Working with @TestInstance annotation

Sometimes one would need to gain access to the test class instance to which an @Test annotated test method belongs to, from within a data provider. This could be particularly useful in cases, wherein the data provider may need to behave differently based on the type of the class to which the @Test method belongs … Continue reading

Parallel execution of multiple TestNG suites

If we would like to run more than one TestNG suite in parallel, here’s how to go about doing it. For the sake of convenience am going to conveniently assume that your project is a Maven project. We first start by defining two properties in our pom file – One property to accept a list … Continue reading

Running tests which don’t have TestNG annotations

This question came up very recently on the TestNG forum and I found it to be quite interesting. So I decided to spend sometime trying to figure out how to get this to work. The reason why this problem statement sounded interesting was because it was mentioned that the classes in question are all legacy … Continue reading

What are data providers in TestNG

Data providers is a very common need when you are building tests that are data driven in nature. TestNG provides for two types of data providers. Greedy Data provider Lazy Data provider Both the above flavors of data providers can be used in your TestNG driven tests to satisfy the following scenarios. You need to … Continue reading

Sharing data across Tests in different TestClasses

So today I saw another interesting question posted on the TestNG-Users google forum. How does one go about sharing data across test methods which are spilt over different test classes. Here’s two ways which I can think of in which this can be done. Approach 1: Via the TestClass’s instance. Here’s how you do it. … Continue reading

Sharing parameters among different TestNG suites.

Off late I have been seeing a couple of queries every now and then which asks “How do I share parameters across multiple TestNG suite xmls”, so I thought I would perhaps write up a post which details it. There are two ways in which this can be done. Approach (1) Leverage what TestNG directly … Continue reading

BeanShell and TestNG

Very recently someone asked a question if I could have the luxury of referring to VM arguments in the TestNG Suite XML file so that they had the luxury of choosing the group to be run at run-time. At first I ended up responding with “NO” as an answer. After pondering more over this question, … Continue reading