title: TestNG: Pass parameter to DataProvider from Maven
body: <p>It seems I tried all the possible ways to achieve this, but no luck. I have a complex code in DataProvider (it really collects data in a complex way), which i want to be eventually parametrized by CI.</p>
  
  <p>The first question here is how to even <strong>read</strong> parameters inside DataProvider. </p>
  
  <p>1 One way is to get parameters from testng.xml this way:</p>
  
  <pre><code>    String lolo = context.getCurrentXmlTest().getParameter("testcases");
  </code></pre>
  
  <p>But this doesn't solve the problem, because .xml file must be static then, and I want to pass parameters to it from Maven.</p>
  
  <p>2 The other way is to read parameters from @Factory in my case:</p>
  
  <pre><code>    String testCaseDataFilename = (method.getAnnotation(Factory.class)).parameters()[0];
  </code></pre>
  
  <p>Where @Factory is:</p>
  
  <pre><code>    @Factory(dataProvider="dataProviderMethod", parameters = {"authentication-testcases.json"})
  </code></pre>
  
  <p>It works too, but again, doesn't solve the problem, because now parameters must be harcoded in java test files, and my @Factory uses @DataProvider for itself, and it can't receive parameters from Maven implicitly.</p>
  
  <p>Additionally, I have other test parameters, which are passed by Maven, but they are used only in @Test tests, not DataProvider, and @BeforeSuite successfully receives them.</p>
  
  <p>I'll try to simplify: </p>
  
  <p>I am calling maven </p>
  
  <pre><code>-Dtestname=signUp -Dmyparam=1 test
  </code></pre>
  
  <p>and I want my DataProvider to receive this value of Dmyparam and use it to gather data. All I achieved is receiving this data with @BeforeSuite and setting it globally, but the problem is DataProvider is called <strong>before</strong> the data is set.</p>