Reputation: 109
**Class 1:** **Class 2:**
@BeforeTest @Test
public void browserSetup(){ public void testCase2(){
... ...
} }
@Test @Test
public void testCase1(){ public void testCase3(){
... ...
} }
@AfterMethod
public void tearDown(){
...
}
In this two class is my selenium java code structure. Here class 1 execute browserSetup, testcase 1 and tearDown. Here my doubt is how to execute "tearDown" method, after class 2 methods.
I want to run this program like below, 1. browserSetup 2. testCase1 3. tearDown 4. testCase2 5. tearDown 6. testCase3 7. tearDown
Any solution for this?
Upvotes: 0
Views: 97
Reputation: 5740
You can use inheritance for that:
Mother class:
@BeforeTest
public void browserSetup(){
...
}
@AfterMethod
public void tearDown(){
...
}
Class 1:
@Test
public void testCase1(){
...
}
Class 2:
@Test
public void testCase2(){
...
}
@Test
public void testCase3(){
...
}
Upvotes: 0
Reputation: 1270
If you are asking how to associate a particular teardown method to a particular @Test method, there is no need for annotations: Simply call it at the end of your test method in a finally:
@Test
public void someTest() {
try {
// test something
} finally {
someParticularTearDown();
}
}
Upvotes: 1