Closed sgupta304 closed 6 years ago
Singletons cannot be shared across multiple JVMs. Singletons are created on the Java heap and only available to the JVM in which it was created.
When you use Courgette, each test will start in a new JVM so any objects created during the test run will only exist in that one instance, this is why your singleton object is null for each test.
Some info here as well: https://stackoverflow.com/questions/12032895/how-to-create-singleton-java-class-for-multiple-jvm-support
I want to be able to initialize a few things before the threads are kicked off i.e. setup configurations for the entire suite, start appium server, possibly the BMP proxy server.
This setup will need to be moved outside your test and happen before your test run. This should not be as part of the actual test!
One way to do this is by using a Gradle task and running that task before running your tests.
Ah I got it. That's was my hunch as well. Thanks for confirming it. I will keep that in mind.
When you say the setup needs to be done outside of the test. You are saying that anything that happens inside the BeforeSuite and AfterSuite hook needs to happen outside of the Courgette Runner class?
If you need to share a single instance of something like an appium server then this should be started before your test runs and outside the Courgette Runner class.
You could use the BeforeClass annotation to do "something" once.
The message "I will start my server once!" will only be called once before your tests start.
You could do something similar if you want to start a single server instance for example.
public class ChromeTestSuite extends TestNGCourgette {
@BeforeClass
public void beforeTestSuite() {
System.out.println("I will start my server once!");
}
}
Sounds good. Thank you so much!
Hi Prashant,
I ran into an issue over the weekend. I created a singleton class which will in charge of gather all of the configurations needed during runtime and set it to a Suite object which the entire application should be able to use through out. However, once the Testng Courgette runner kicks off the suite singleton object becomes null.
Here is the singleton:
Here is the courgette runner:
Is there anything that I am missing? I want to be able to initialize a few things before the threads are kicked off i.e. setup configurations for the entire suite, start appium server, possibly the BMP proxy server.