3

What is the difference between BeforeClass and BeforeTest in TestNG - Selenium WebDriver, please suggest me best link or site for this.

1

This is a duplicate question of below :

https://stackoverflow.com/questions/30587454/difference-between-beforeclass-and-beforetest-in-testng

since you asked site to refer please consider below websites:

You can refer below link:

https://www.guru99.com/all-about-testng-and-selenium.html

| improve this answer | |
6

@BeforeTest method runs before the test method, belonging to the classes inside the tag. It is called once for each test tag. It is used to initialize common objects between different test classes inside one test tag.

@BeforeClass method runs before the class is invoked. It is called once for each test class inside the test tag. It is used to initialize common objects between different test methods inside one test class.

For example:

   <suite name="suit1">
      <test name="TestTag1">
        <classes>
          <class name="TestClass1"/>
        </classes>
      </test>
      <test name="TestTag2">
        <classes>
          <class name="TestClass2"/>
          <class name="TestClass3"/>
        </classes>
      </test>
    </suite>

Here, @BeforeTest will be called twice, one time before TestTag1 the second time before TestTag2 while @BeforeClass will be called three times, one time before TestClass1 the second time before TestClass2 and the third time before TestClass3

Site for Reference

| improve this answer | |
  • thank you for valuable answer. – sushen Mar 9 at 4:07
  • @sushen Do accept the answer which is most applicable to you, by clicking the tick sign near to the answer. – JAINAM Mar 9 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.