My question is as far as a framework goes should I be using such TestNG Annotations as @beforemethod @beforetest @aftertest? Or just have the code in each class?
For example why would I call the firefox driver with these @before annotations? I can understand that then i can reuse the code and just call a chrome driver for example, but most of the time running the same tests on chrome or other browsers require some modifications to pass, and I can just copy the whole code anyway.
So wouldn't it make sense to have the code or call the code directly into the class I am using for @test?
Also, with @afterTest why would i call teardown there? When i can just call it in every class?
Are there any advantages/disadvantages of using these annotations instead of writing the code directly in the class?
For example, I have this file which runs some tests:
package FireFox;
import org.testng.annotations.Test;
public class TestGroup {
//////////////////////////////////////////////////
@Test(priority=1)
public void SessionTasks() {
Session_Tasks call = new Session_Tasks();
call.sessionTasks();
}
////////////////////////////////////////////////
@Test(priority=2)
public void SignUp () {
Signup call = new Signup();
call.signup();
}
//////////////////////////////////////////////////
@Test(priority=3)
public void Signup_PostQ() {
Signup_PostQs call = new Signup_PostQs();
call.signup_postq();
}
//////////////////////////////////////////////////
@Test(priority=4)
public void Sign_In() {
SignIn call = new SignIn();
call.signIn();
}
//////////////////////////////////////////////////
@Test(priority=5)
public void Sign_In_PostQ() {
SignIn_PostQs call = new SignIn_PostQs();
call.signIn_postq();
}
//////////////////////////////////////////////////
@Test(priority=6)
public void SessionConnect() {
Session_Connect call = new Session_Connect();
call.sessionConnect();
}
//////////////////////////////////////////////////
@Test(priority=7)
public void TutorMenu() {
Tutor_Menu call = new Tutor_Menu();
call.Tutor_menu();
}
}
All the actions are contained in each class, opening specific browser, navigating to a url, and at the end of the test closing the browser. Why would I want to use any of the @before,@after annotations, as opposed to having everything contained in each class?