1

I have multiple testNG classes that are to test different features of our website. For each class, before it is being executed, it needs to run a same config() call to have some devices setup.

So for each individual test class, it looks in this format:

    public class TestFeature1 extends TestEnvironment {
        @BeforeSuite
        @Parameters({ "clusterURL"})
        public void config(String clusterURL) throws URISyntaxException {
             ...
        }
        ...
}

My question is, all these classes may be running separately, or running in one testng session. If it was the later case, how to have this config() being executed only once ? Currently I am using testNG 6.14.3 now.

Navarasu
  • 8,209
  • 2
  • 21
  • 32
user3595231
  • 711
  • 12
  • 29

1 Answers1

1

Move the config method to base class and extend all the test with base test.

  public class BaseTest extends TestEnvironment {
        @BeforeSuite
        @Parameters({ "clusterURL"})
        public void config(String clusterURL) throws URISyntaxException {
             ...
        }
        ...
   }

  public class TestFeature1 extends BaseTest {

        ...
   }

  public class TestFeature2 extends BaseTest {

        ...
   }
Navarasu
  • 8,209
  • 2
  • 21
  • 32