TestNG: repeat a method -
i have test case requires me log out multiple times. want log out own test/method. instead of creating log out method each time, there way can call method?
@test(priority = 1, groups = {"regression"}) public void createaccount() throws exception {} @test(priority = 2, groups = {"regression"}) public void addpayment() throws exception {} @test(priority = 3, groups = {"regression"}) public void logout() throws exception {} @test(priority = 4, groups = {"regression"}) public void login() throws exception {} @test(priority = 5, groups = {"regression"}) public void logout() throws exception {}
you can using @aftermethod annotation. method called after every test method. if want run test methods, can pass in itestresult test method names. might want include alwaysrun=true
logout method run if test fails.
something this:
@aftermethod(alwaysrun=true) public void logout(itestresult result) { if (result.getname().equalsignorecase("addpayment")) { // logout } }
hope helps.
Comments
Post a Comment