What is the difference between Onstart Function in ISuiteListener and @beforeSuite of TestNG?

OnStart Method in ISuiteListener¬†–before TestNG picks up your suite for execution, it first makes a call to onStart() method and runs whatever has been scripted in this method.

@BeforeSuite Annotation In TestNG-
Method with this annotation would run before execution of test suite.

These two sound same to me.
How the two are different from each other?
In which  condition one is  more useful than the other?

Default Asked on January 19, 2016 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)

    Hi Neha

    @BeforeSuite Annotation In TestNG-
    This is like a common method you wanted to run before your test suite
    this will run once only in a suite
    ex: may be you wanted to create a database connection before your test suite and wanted to use it throughout your test case run

    OnStart Method in ISuiteListener
    Generally listeners are used for logging purpose
    so if you will define onstart method in your class. the method will be called for every method that will run in your test suite.
    like in this case

    public void onStart(ISuite arg0) {
    Reporter.log(“About to begin executing Suite “ + arg0.getName(), true);
    } // the method will log same when any method will run About to begin executing Suite + method name

    so that it will be easier for you to log

    Vice Professor Answered on January 20, 2016.

    So as u said, In a suite if have a test case with 4 methods(functions) OnStart would be called before executing each of the function?
    This is bit confusing as ONStart should only be executed before suite.

    on January 27, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.