Set Priority For Selenium WebDriver TestNG @Test Method Execution

We tin sack set evidence execution priority for selenium WebDriver @Test notation methods. If at that spot Is single @Test notation method In your evidence shape hence you lot create non bespeak to set evidence execution priority but supposing you lot accept multiple @Test notation methods In unmarried evidence shape hence many of you may human face upward Issue like @Test method's execution sequence Is dissimilar than the actual sequence.

You volition discovery basic TestNG Framework Tutorials links on THIS PAGE.

Example Is every bit bellow.

package TestNG_Advanced;  import org.testng.annotations.Test;  world shape setPriority {      @Test     world void Login() {   System.out.println("LogIn Test code.");        }      @Test     world void checkMail() {   System.out.println("checkMail Test code.");        }      @Test     world void LogOut() {   System.out.println("LogOut Test code.");      } }

If you lot volition run to a higher house evidence In eclipse hence console output volition looks similar bellow.
LogOut Test code. LogIn Test code. checkMail Test code.

As per console output, LogOut() @Test method Is executed first, then Login() @Test method and at concluding checkMail() @Test method. So this Is foreign in addition to non every bit per my requirement. It should execute Login() @Test first, checkMail() @Test 2d in addition to LogOut() @Test 3rd.

TestNG has really proficient characteristic to resolve this Issue past times setting priority of test. You tin sack gear upward priority alongside @Test notation to right evidence execution sequence every bit bellow.
package TestNG_Advanced;  import org.testng.annotations.Test;  world shape setPriority {       @Test(priority=1)     world void Login() {   System.out.println("LogIn Test code.");        }        @Test(priority=2)     world void checkMail() {   System.out.println("checkMail Test code.");        }       @Test(priority=3)     world void LogOut() {   System.out.println("LogOut Test code.");      }   }

If you lot volition run to a higher house code snippet In eclipse hence console output volition looks similar bellow.
LogIn Test code. checkMail Test code. LogOut Test code.

So now, Test execution sequence Is right in addition to every bit per my requirement. If you lot encounter In example, We gear upward evidence execution priority for all three @Test methods.

This means you lot tin sack gear upward evidence execution priority for each in addition to every @Test method of your class.
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post