This category contains 20 posts

Thread affinity in TestNG

Most of us would have at some point or the other built a Selenium based TestNG test that kind of looks like below: When running this above class with parallel=”methods” we would be expecting that TestNG would run the method a() and c() on the same thread. But TestNG doesn’t do that. It guarantees that … Continue reading

Automatically wire-in a parent Guice-module into your TestNG test

What is dependency injection ? Quoting WikiPedia, here’s the definition of dependency injection: In software engineering, dependency injection is a technique whereby one object supplies the dependencies of another object. A dependency is an object that can be used (a service). An injection is the passing of a dependency to a dependent object (a client) … Continue reading

Building Dynamic TestNG Suites

We have all at some point wished that we had a way wherein we could dynamically build the TestNG suite xml file based upon some parameters and still make use of built in test execution mechanisms such as maven surefire plugin to run our tests. Its very easy to build these sort of customizations if … Continue reading

Dynamic parameterization in TestNG

TestNG provides us users with two  ways in you can achieve data driven tests. You make use of the @DataProvider annotation wherein you bind your @Test method with a data source. You make use of the @Parameters annotation and have your @Test method read values from a suite xml file. There are enough blogs and documentation pages that … Continue reading

Running setup only once per Test/Suite Without Using @BeforeSuite/@BeforeTest

This is a common question that I am noticing asked by many users in the TestNG google forums and also on StackOverFlow. So instead of constantly repeating myself in all these places, I thought I should just blog it as a solution for others to refer to it. Lets say you have a scenario wherein … Continue reading

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