selenium - Should I be using @Before @After annotations with TestNG? Webdriver -


my question far framework goes should using such testng annotations @beforemethod @beforetest @aftertest? or have code in each class?

for example why call firefox driver these @before annotations? can understand can reuse code , call chrome driver example, of time running same tests on chrome or other browsers require modifications pass, , can copy whole code anyway.

so wouldn't make sense have code or call code directly class using @test?

also, @aftertest why call teardown there? when can call in every class?

are there advantages/disadvantages of using these annotations instead of writing code directly in class?

for example, have file runs 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 actions contained in each class, opening specific browser, navigating url, , @ end of test closing browser. why want use of @before,@after annotations, opposed having contained in each class?

freedom of using @before or @after or other annotations in test code goes tester.

  • the basic reason using annotations in test code makes code easy-to-read , easy-to-understand other testers.provides clean code.
  • using annotations @before,@after,@beforeclass or many others helps reduce work , time write repetitive codes again , again. smart way repeat same actions in test execution without writing again.
  • test cases can grouped more easily resulting efficient parallel testing.
  • very efficient use of such annotations in test suites. in
    test-suites experiences dependencies. dependencies
    between various test-cases written pre-conditons and
    post-conditions
    . these pre-condictions , post-conditions can
    handle , efficently using such annotations.

though not rule of thumb using such annotations, using them when required in test code observed practice. hope solves confusion or question using annotations frameworks.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -