My configuration when test execution is through the Test suite level,
BeforeTestSuite
def login(){
}
AfterTestSuite
def logout(){
}
Again configuration when test execution is through Test case level,
BeforeTestCase
def login(){
}
AfterTestCase
def logout(){
}
Every time I’m updating the configuration. Instead of this, is there any alternative configuration to handle test listeners without updating every time.
Just remove @BeforeTestSuite and @AfterTestSuite; and let @BeforeTestCase and @AterTestCase be as is. And you stop editting your TestListener code at all. Your Test Cases and Test Suite should run ok.
When you run a Test Suite, you will see the test repeats login&logout as often as the number of your test cases contained in the test suite. It may look redundant. But would you really mind it?
If you stick to minimizing the number of login/logout processing, you can do something like the following psuedo code …
@BeforeTestCase
def loginIfNotYet(){
if (you are not yet login) {
login()
}
}
@AfterTestCase
def logoutIfNotYet(){
if (you are not yet logout) {
logout()
}
}
Your problem is reformed: how can a TestListener tell if you are logged in or logged out? It depends on your AUT design.
@kazurayam
Thanks for your reply.
I want the login method should run only one time in start of the execution & logout method should run only one time at end of the execution.
The execution can be either Test Case or Test suite level but only one time both the methods should execute.
So for this configuration I need the Test Listeners should be in the respective execution control.
So kindly let me know another alternative solution.
Hey, @Harinath, I think the solution @kazurayam suggests is general enough, because if you can tell the TestListener if you are already logged in or not yet, then you can direct the execution flow whenever you want, not just for the specific case of once before and after TestCase or TestSuite execution.
May I suggest try to set a GlobalVariable.logged_in to false initially, and then when you’re done logging in, you just set the variable to true. Would this solution work for you ?
My issue is if I’m executing Testcase level with the below config, execution fails
BeforeTestSuite
def login(){
}
AfterTestSuite
def logout(){
}
Similarly, if I’m executing at Test Suite level with the below config, login and logout methods executes for every test case
BeforeTestCase
def login(){
}
AfterTestCase
def logout(){
}
But I want the Listeners to execute only one time for any kind of execution i.e., either TestSuite level or TestCase level…
As @kazurayam suggested, just delete (or comment out) the BeforeTestSuite and AfterTestSuite and listeners will execute only before and after test case.
I want to execute the login and logout method only one time either it could be TestCase level or TestSuite level execution.
Kindly provide the solution.
I’m not sure I understand it.
Can you explain more about this, please? GlobalVariable.SUITEID = testSuiteContext.getTestSuiteId()
What does this imply?