java - TestNG - priority of @AfterMethod -


is possible call @aftermethod methods in specific order? have example code:

public class prioritytest {  @beforeclass(alwaysrun = true) public void setup() throws exception {     system.out.println("beforeclass prioritytest.java"); }  @test public void defaultpriority(){     system.out.println("default"); } @test (priority = 3) public void t1(){     system.out.println("t1"); } @test (priority = 2) public void t2(){     system.out.println("t2"); } @test (priority = 1) public void t3(){     system.out.println("t3"); } @test (priority = -1) public void t_1(){     system.out.println("t -1"); }  @aftermethod public void after2(){     system.out.println("after2"); } @aftermethod public void after1(){     system.out.println("after1"); } 

}

priority of @test works perfectly. want same @aftermethod, when write code @aftermethod (priority = 1) compilation error. when run without priority there alphabetically order (only method name matters). here output: beforeclass prioritytest.java t -1 after1 after2 default after1 after2 t3 after1 after2 t2 after1 after2 t1 after1 after2

is there possibility call methods in specific order (e.g. special paremeter or annotation)?

ps. know can write 1 aftermethod , call methods in specific order, think many aftermethod annotations.

@aftermethod doesn't support priority parameter. has dependsonmethods , dependsongroups can used instead.

dependsonmethods

the list of methods method depends on. there no guarantee on order on methods depended upon run, guaranteed these methods run before test method contains annotation run. furthermore, if of these methods not success, test method not run , flagged skip. if of these methods have been overloaded, overloaded versions run.

dependsongroups

the list of groups method depends on. every method member of 1 of these groups guaranteed have been invoked before method. furthermore, if of these methods not success, test method not run , flagged skip.

in case dependsonmethods can used.

@aftermethod public void after2(){     system.out.println("after2"); } @aftermethod(dependsonmethods = "after2") public void after1(){     system.out.println("after1"); } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -