Search code examples
javaseleniumtestngselenium-rcsequential

How to run/execute methods sequentially by Selenium RC and TestNG using Java


I have a java class containing 3 methods:

public class Test{
 public void orange(){
 }
 public void apple(){
 }
 public void mango(){
 }
}

I want to execute 3 methods mentioned above sequentially/orderly as i have written by Selenium RC and TestNG. How can I do this?


Solution

  • The easy way is to just change @Test to @Test(singleThreaded=true). If you do, all of the tests in your class will run sequentially in a single thread.

    Or

    If you want to be explicit about the order that the tests should run in, you can use the annotation @dependsOnMethods

    public void orange(){}
    
    @Test(dependsOnMethods = { "orange" })
    public void apple(){}
    
    @Test(dependsOnMethods = { "apple" })
    public void mango(){}
    

    This is also nice if you want some, but not all, of the methods in a class to run sequentially.

    http://testng.org/doc/documentation-main.html#dependent-methods