TestNG @BeforeSuite Annotation
Till now, we read about the @BeforeTest and @AfterTest which have control over the particular
@BeforeSuite: The @BeforeSuite annotated method is executed before the execution of all the test cases defined in the
Generally, @BeforeSuite is used when we have different URLs to run your test cases. Environment variables are set in a @BeforeSuite annotated method so that before executing all the test cases, you need to load all the environment variables for your framework, and then it starts executing your test cases.
The @BeforeSuite annotated method is given as the first priority, so it is executed before all the other test methods.
Let's understand the @BeforeSuite annotated method through an example.
Step 1: Open the Eclipse.
Step 2: We create three modules of loan, i.e., Car_loan.java, Home_loan.java, and Personal_loan.java.
Step 3: Create testng.xml file to configure classes.
We created three modules of loan, i.e., Car loan, Personal loan, and Home loan. Their class files are configured in the testng.xml file. The @BeforeSuite annotated method is defined in the Personal_loan.java file which means that @BeforeSuite annotated method, i.e., before_suite() is executed first before all the test methods available in configured classes in the XML file. According to the testng.xml file, TestNG will first execute the before_suite() method and then TestNG will follow the sequence of
Step 4: Run the testng.xml file. Right click on the testng.xml, and then move down to the Run As, click on the 1 TestNG Suite.