title: "Parameter 'browser' is required by BeforeClass on method beforeClass but has not been marked @Optional or defined" error in maven project
body: <p>I have a maven project where in I am running testng.xml from pom.xml file.</p>
  
  <p>My testng.xml file looks like below:</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="Suite" parallel="tests"&gt;
    &lt;test name="FirefoxTest"&gt;
    &lt;parameter name="browser" value="firefox"/&gt;
      &lt;classes&gt;
        &lt;class name="tests.PM_User_Test"/&gt;
      &lt;/classes&gt;
    &lt;/test&gt; &lt;!-- Test --&gt;
  
    &lt;test name="ChromeTest"&gt;
      &lt;parameter name="browser" value="chrome"/&gt;
      &lt;classes&gt;
        &lt;class name="tests.PM_User_Test"/&gt;
        &lt;class name="tests.PM_Extension_Test"/&gt;
      &lt;/classes&gt;
    &lt;/test&gt; &lt;!-- Test --&gt;
  &lt;/suite&gt; &lt;!-- Suite --&gt;
  </code></pre>
  
  <p>and below is my class:</p>
  
  <pre><code>    package base;
  
  import java.io.IOException;
  import java.lang.reflect.Method;
  import java.util.concurrent.TimeUnit;
  
  import org.openqa.selenium.UnexpectedAlertBehaviour;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.firefox.FirefoxDriver;
  import org.openqa.selenium.remote.CapabilityType;
  import org.openqa.selenium.remote.DesiredCapabilities;
  import org.openqa.selenium.chrome.ChromeDriver;
  import org.testng.ITestResult;
  import org.testng.annotations.AfterClass;
  import org.testng.annotations.AfterMethod;
  import org.testng.annotations.AfterSuite;
  import org.testng.annotations.BeforeClass;
  import org.testng.annotations.BeforeMethod;
  import org.testng.annotations.BeforeSuite;
  import org.testng.annotations.Optional;
  import org.testng.annotations.Parameters;
  
  import utilities.ExcelReadAndWrite;
  import utilities.Take_Screenshot;
  
  public class ConfigClass
  {
      public WebDriver driver = null;
      public static String excelPath = null;
      public static ExcelReadAndWrite loginData;
      public static ExcelReadAndWrite pmTests;
      public static ExcelReadAndWrite snmTests;
      public static ExcelReadAndWrite ipData;
  
  
      @BeforeSuite
      public void beforeSuite()
      {
          excelPath = "C://Users//mallikar//git//PM//PM//src//main//java//myTestData//TestData.xlsx";
          loginData = new ExcelReadAndWrite("logindata", excelPath);
          pmTests = new ExcelReadAndWrite("PMTestData", excelPath);
          snmTests = new ExcelReadAndWrite("SNMTestData", excelPath);
          ipData = new ExcelReadAndWrite("IP", excelPath);
      }
  
      @AfterSuite
      public void afterSuite() 
      {
  
      }
  
      @Parameters({"browser"})
      @BeforeClass
      public void beforeClass(String browser)
      {
          DesiredCapabilities dc = new DesiredCapabilities();
          dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
          if(browser.equalsIgnoreCase("firefox"))
          {
              driver = new FirefoxDriver(dc);
          }
          else if(browser.equalsIgnoreCase("chrome"))
          {
              driver = new ChromeDriver();
          }
  
      }
  
      /*@Parameters("browser")
      @BeforeClass
      public void beforeClass()
      {
          DesiredCapabilities dc = new DesiredCapabilities();
          dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
          driver = new FirefoxDriver(dc);
      }*/
  
      @AfterClass
      public void afterClass()
      {
          driver.close();
      }
  
      @BeforeMethod
      public void beforeMethod()
      {
  //      driver.get("https://sqa.stackexchange.com/questions/36253/taking-screenshot-on-test-failure-selenium-webdriver-testng");
  //      System.out.println(driver);
          driver.manage().window().maximize();
          driver.manage().deleteAllCookies();
          driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
      }
  
      @AfterMethod
      public void afterMethod(ITestResult result) throws IOException
      {
          if(result.getStatus() == 2)
          {
              String methodName = result.getMethod().getMethodName();
              new Take_Screenshot().get_Screenshot(driver, methodName);
          }
      }
  }
  
  
  But I am getting the "Parameter 'browser' is required by BeforeClass on method beforeClass but has not been marked @Optional or defined" error in maven project.
  
  However when I run only testng.xml file it is absolutely working fine. The pro
  </code></pre>
  
  <p>blem comes when I run testng.xml from pom.xml file.</p>
  
  <p>Below is the content of POM.xml file where I have defined testng.xml:</p>
  
  <pre><code>&lt;profiles&gt;
      &lt;profile&gt;
          &lt;id&gt;Regression&lt;/id&gt;
          &lt;build&gt;
      &lt;plugins&gt;
      &lt;plugin&gt;
          &lt;inherited&gt;true&lt;/inherited&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.3.2&lt;/version&gt;
          &lt;configuration&gt;
             &lt;encoding&gt;UTF-8&lt;/encoding&gt;
          &lt;/configuration&gt;
      &lt;/plugin&gt;
  
      &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.12.2&lt;/version&gt;
          &lt;configuration&gt;                        
            &lt;suiteXmlFiles&gt;
                 &lt;suiteXmlFile&gt;src/test/resources/testng.xml&lt;/suiteXmlFile&gt;              
            &lt;/suiteXmlFiles&gt;         
          &lt;/configuration&gt;       
        &lt;/plugin&gt;   
      &lt;/plugins&gt;
    &lt;/build&gt;
      &lt;/profile&gt;
    &lt;/profiles&gt;
  </code></pre>
  
  <p>I have gone through lot of threads about this on internet but I haven't found any solution. Please somebody help me with this.</p>
  
  <p>And below are the console logs when I run mvn clean install command</p>
  
  <pre><code>Running TestSuite
  Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@ba4d54
  Tests run: 10, Failures: 2, Errors: 0, Skipped: 8, Time elapsed: 2.368 sec &lt;&lt;&lt; FAILURE!
  beforeClass(tests.PM_Extension_Test)  Time elapsed: 2.098 sec  &lt;&lt;&lt; FAILURE!
  org.testng.TestNGException:
  Parameter 'browser' is required by BeforeClass on method beforeClass but has not been marked @Optional or defined
  
          at org.testng.internal.Parameters.createParams(Parameters.java:289)
          at org.testng.internal.Parameters.createParametersForMethod(Parameters.java:377)
          at org.testng.internal.Parameters.createParameters(Parameters.java:721)
          at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:164)
          at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:275)
          at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:176)
          at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:122)
          at java.util.ArrayList.forEach(ArrayList.java:1257)
          at org.testng.TestRunner.privateRun(TestRunner.java:770)
          at org.testng.TestRunner.run(TestRunner.java:591)
          at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
          at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
          at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
          at org.testng.SuiteRunner.run(SuiteRunner.java:304)
          at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
          at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
          at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
          at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
          at org.testng.TestNG.runSuites(TestNG.java:1032)
          at org.testng.TestNG.run(TestNG.java:1000)
          at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77)
          at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:159)
          at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:99)
          at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:106)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
          at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
          at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
          at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
          at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
  
  beforeClass(tests.PM_User_Test)  Time elapsed: 0.002 sec  &lt;&lt;&lt; FAILURE!
  org.testng.TestNGException:
  Parameter 'browser' is required by BeforeClass on method beforeClass but has not been marked @Optional or defined
  
          at org.testng.internal.Parameters.createParams(Parameters.java:289)
          at org.testng.internal.Parameters.createParametersForMethod(Parameters.java:377)
          at org.testng.internal.Parameters.createParameters(Parameters.java:721)
          at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:164)
          at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:275)
          at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:176)
          at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:122)
          at java.util.ArrayList.forEach(ArrayList.java:1257)
          at org.testng.TestRunner.privateRun(TestRunner.java:770)
          at org.testng.TestRunner.run(TestRunner.java:591)
          at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
          at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
          at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
          at org.testng.SuiteRunner.run(SuiteRunner.java:304)
          at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
          at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
          at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
          at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
          at org.testng.TestNG.runSuites(TestNG.java:1032)
          at org.testng.TestNG.run(TestNG.java:1000)
          at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77)
          at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:159)
          at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:99)
          at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:106)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
          at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
          at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
          at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
          at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
  
  
  Results :
  
  Failed tests:   beforeClass(tests.PM_Extension_Test): (..)
    beforeClass(tests.PM_User_Test): (..)
  
  Tests run: 10, Failures: 2, Errors: 0, Skipped: 8
  
  [WARNING] Could not delete temp direcotry C:\Users\mallikar\git\PM\PM\target\surefire because Directory C:\Users\mallikar\git\PM\PM\target\surefire unable to be deleted.
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time:  10.374 s
  [INFO] Finished at: 2019-09-26T16:39:22+05:30
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project PM: There are test failures.
  [ERROR]
  [ERROR] Please refer to C:\Users\mallikar\git\PM\PM\target\surefire-reports for the individual test results.
  [ERROR] -&gt; [Help 1]
  [ERROR]
  [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  [ERROR]
  [ERROR] For more information about the errors and possible solutions, please read the following articles:
  [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
  </code></pre>