title: How to pass parameters to @BeforeClass & @AfterClass methods through testNG.xml file
body: <p>I am trying to pass parameter to @BeforeClass method through testNG.xml file, but when I run my script, neither the script is executed nor any error is shown in the console, just the script is terminated. Not sure where am I going wrong. Kindly help me on this. </p>
  
  <p>P.S: Script is working good when I use @BeforeSuite annotation instead of @BeforeClass</p>
  
  <h1>Thanks in advance</h1>
  
  <p>Below is my code snippet:</p>
  
  <p>BaseSetup.java</p>
  
  <pre><code>public class BaseSetup {
  
  private  WebDriver driver;
  private String userdir = System.getProperty("user.dir");
  private  void SelectBrowser(String browsername){
  
      switch(browsername){
  
      case "GoogleChrome": 
  
          //initChromeBrowser();
  
          break;
  
      case "FireFox":
  
          initFireFoxBrowser();
  
          break;
  
      default: 
          System.out.println("Wrong input");      
      }
  
  }
  
  private  void initChromeBrowser(){
  
      System.setProperty("webdriver.chrome.driver", userdir +"\\chromedriver.exe");
  
      driver = new ChromeDriver();
  
      launchApp();
  
  }   
  private void initFireFoxBrowser(){
  
      System.setProperty("webdriver.gecko.driver", userdir +"\\geckodriver.exe");
  
      driver = new FirefoxDriver();
  
      launchApp();
  
  }
  
  private  void launchApp(){
  
      driver.manage().window().maximize();
  
      driver.get("https://www.google.co.in");
  }
  
  @Parameters({"browsername"})
  
  @BeforeClass
  
  public  void LaunchBrowser(String browsername){
  
          SelectBrowser(browsername);     
  }
  }
  </code></pre>
  
  <p>Below is my testNG.xml code</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&gt;
  &lt;suite name="SampleTestSuite"&gt;
  &lt;test name="SampleTest"&gt;
  
  &lt;classes&gt;
  
    &lt;class name="com.pac.base.BaseSetup"&gt;
    &lt;parameter name="browsername" value="FireFox"&gt; &lt;/parameter&gt;     
     &lt;/class&gt;
  
     &lt;/classes&gt;
  
     &lt;/test&gt; &lt;!-- Test --&gt;
     &lt;/suite&gt; &lt;!-- Suite --&gt;
  </code></pre>