What I need to do is to create UI test cases for our application and we have decided to use Selenium with TestNG (we're still open to other options if there are considerable advantages).

The tests we are trying to create are tests where several users interact with each other using the application. Basically we need to have several users logging in in parallel into our application and perform different actions. There is a relation between the actions of the users so they need to synchronize their interaction in some points (e.g a user needs to wait, that a different user performs an action before he can perform his action). This means, that there also needs to have some sort of shared information between the users (I was simply thinking about sharing an object, that will take care of the synchronization points).

How should I structure my scenario where I need to describe the actions of different users, that will run in parallel using TestNG?

Is there a better framework for this or is there a pattern, that addresses this problem? Any suggestions are welcome!

The best I could thing so far is to create a test, where each @Test method has the actions of each user and then create a Suite, where I define, that the test methods should run in parallel.


public class MultiUserTest {
    public void user1Interaction() {
        User user1 = new User();
        // user1 performs actions
    public void user2Interaction() {
        User user2 = new User();
        // user2 performs actions

Then create a Test Suite, where I specify, that the methods of MultiUserTest should run in parallel.

However I don't really like this solution. I don't like the fact, that I'm relying on an XML configuration (Test Suite) to describe the correct behavior of my test (which will not be obvious just by looking at the java code). I also don't like the fact, that I will not be able to simply run the test by using the TestNG plugin on eclipse by doing Run As - TestNG Test.

Again, any suggestion is very welcome.

2 Answers 2


One possibility: Put each user's activities in a class (perhaps anonymous) that implements Callable. Then have your test method instantiate each Callable, invoke them using an ExecutorService, then retrieve the threads' results when they finish.


  • Callable
  • Executors, especially the unconfigurableExecutorService() method.
  • ExecutorService to invoke the subthreads and retrieve their results and exceptions.

You can use testNG Dependency feature for this. This would make sure that your methods run in a predefined order. You are also not relying on XML configuration order. Plus it will run fine with testNG eclipse plugin also.

  • How can I use TestNG Dependency to achieve this? I don't want to run the methods in a predefined order, I want to run them in parallel. The solution I added to the question is very close to what I was looking for, the only problem is that the fact that I want the methods to run in parallel cannot be specified in the test itself (through an annotation, for example) so that the eclipse plugin would also pick it up and I would not need an xml file. Jan 5, 2012 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.