org.testng.TestNGException: Parameter 'browser' is required by @Configuration on method beforeclass but has not been marked @Optional or defined

15,448 views
Skip to first unread message

prasanth kotagiri

unread,
Oct 29, 2015, 10:29:44 AM10/29/15
to testng-users
Hi,

Here is my code

package YatraBooking;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;

public class YatraBookingValidation {
public WebDriver driver;
  @Test
  public void f() {
 
 driver.findElement(By.xpath("//*[@id='BE_Nav']/li[2]/a/span")).click();
 
  }
  @BeforeClass
  @Parameters("browser")
  public void beforeclass(String browser) throws Exception {
 
 
 
  if(browser.equalsIgnoreCase("firefox")){
 
       //create firefox instance
 
           driver = new FirefoxDriver();
 
       }
 
//Check if parameter passed as 'chrome'
 
       else if(browser.equalsIgnoreCase("chrome")){
 
           //set path to chromedriver.exe You may need to download it from http://code.google.com/p/selenium/wiki/ChromeDriver
 
           System.setProperty("webdriver.chrome.driver","E:\\Data\\Prasanth\\Library\\chromedriver_win32\\chromedriver.exe");
 
           //create chrome instance
 
           driver = new ChromeDriver();
 
       }
  driver.get("http://yatra.com");
  Thread.sleep(3000);
 }
 
  

  @AfterClass
  public void afterClass() {
  }

}


Testng.xml:


<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="tests">
  <test name="FirefoxTest">
  <parameter name="browser" value="Firefox"/>
    <classes>
      <class name="YatraBooking.YatraBookingValidation"/>
    </classes>
  </test> <!-- Test -->
  
  <test name="ChromeTest">
  <parameter name="browser" value="Chrome"/>
  <classes>
      <class name="YatraBooking.YatraBookingValidation"/>
    </classes>
  
  </test>
</suite> <!-- Suite -->


Here is my problem when i run the test from testng.xml the test is running fine and passed.

When i run the same test from POM.xml in MAVEN project it is throwing the following error like:

org.testng.TestNGException: Parameter 'browser' is required by @Configuration on method beforeclass but has not been marked @Optional or defined

Please provide me the suggestion ASAP

Krishnan Mahadevan

unread,
Oct 29, 2015, 11:21:25 AM10/29/15
to testng...@googlegroups.com
I cant recreate this problem.
Please show us the complete stacktrace of the failure when you run your tests from command prompt.

Also please show us how does your surefire plugin configuration look like in your pom file.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

prasanth kotagiri

unread,
Oct 30, 2015, 2:38:07 AM10/30/15
to testng-users
Hi Krishnan,

POM File:

  <modelVersion>4.0.0</modelVersion>
  <groupId>Garudah</groupId>
  <artifactId>Yatra</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <dependencies>
  <dependency>
  <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.48.2</version>
  </dependency>
  <dependency>
  <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>2.48.2</version>
  </dependency>
  <dependency>
  <groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.6</version>
  </dependency>
  <dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.44.0</version>
</dependency>
  </dependencies>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19</version>
          <configuration>
          
          <includes>
          <include>YatraBookingValidation.java</include>
          </includes>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
  
</project>

My Complete Stack Trace:

Please find the attachment of report..
emailable-report.html

Krishnan Mahadevan

unread,
Oct 30, 2015, 2:45:03 AM10/30/15
to testng...@googlegroups.com
You aren't even using the TestNG suite xml file that you created.

You are directly using the class name in your surefire plugin section

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19</version>
        <configuration>
        <includes>
          <include>YatraBookingValidation.java</include>
        </includes>
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
</build>



Change this such that the plugin refers to your suite xml file (you should find samples of how to do it on the surefire plugin documentation site )


On a side note, for the below problem
java.lang.RuntimeException: Process refused to die after 10 seconds, and couldn't taskkill it: Unable to find executable for: taskkill at org.openqa.selenium.os.ProcessUtils.killWinProcess(ProcessUtils.java:142) at org.openqa.selenium.os.ProcessUtils.killProcess(ProcessUtils.java:81) at org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.destroyHarder(UnixProcess.java:247) at org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.access$2(UnixProcess.java:246) at org.openqa.selenium.os.UnixProcess.destroy(UnixProcess.java:125) at org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:155) at org.openqa.selenium.firefox.FirefoxBinary.quit(FirefoxBinary.java:259) at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.quit(NewProfileExtensionConnection.java:204) at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.quit(FirefoxDriver.java:364) at org.openqa.selenium.firefox.FirefoxDriver.stopClient(FirefoxDriver.java:310) at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:519) at YatraBooking.YatraBookingValidation.afterClass(YatraBookingValidation.java:59)

Check if you have somewhere altered the PATH variable. 
On windows "taskkill" is expected to be found very easily. This normally comes up when you have altered the PATH variable and overwritten it with some random stuff.







Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

kishore ramineni

unread,
Apr 30, 2016, 11:33:44 AM4/30/16
to testng-users
Hi ,

I found alternative way to pass parameters.

By specifying the parameter values from sure-fire plug-in:  i have specified as follows


<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          <systemProperties>
            <property>
              <name>browserType</name>
              <value>firefox</value>
            </property>
            <property>
              <name>appUrl</name>
              <value>https://www.expedia.com.au/</value>
            </property>
          </systemProperties>
        </configuration>
      </plugin>

instead of @parameters i have used  them sure-fire plugin with name and values pair.

But still i am not sure why it's not considering parameters from testng.xml. have to figure out that.

--Thanks,
kishore

⇜Krishnan Mahadevan⇝

unread,
May 1, 2016, 12:37:48 AM5/1/16
to testng...@googlegroups.com
Kishore,

I can't recreate your problem. I am able to run a suite xml file which has parameters defined in it using Maven.

Here's sample :

public class ParamsDemo {
@BeforeClass
@Parameters ("value")
public void beforeClass(int value) {
System.err.println("Value passed was : " + value);
}

@Test
public void testMethod() {
System.err.println("Hello world");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Class1Suite" parallel="false">
<test name="Class1Test">
<parameter name="value" value="420"/>
<classes>
<class name="organized.chaos.forums.ParamsDemo"/>
</classes>
</test> <!-- Class1Test -->
</suite> <!-- Class1Suite -->
Surefire plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
    <version>2.15</version>
<configuration>
<suiteXmlFiles>${file}
<suiteXmlFile>${folder}/${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<skipTests>false</skipTests>
</configuration>
</plugin>

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
[XmlSuite] [WARN] 'parallel' value 'false' is deprecated, default value will be used instead: 'none'.
Value passed was : 420
Hello world
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.474 sec - in TestSuite

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------






Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.

Vinoth Kumar

unread,
Dec 1, 2016, 1:00:34 PM12/1/16
to testng-users
I am also facing the same problem, can anyone please help me, find here my code below.

package ParallelTest;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.Keys;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class SampleParalleltest {
WebDriver driver;
String baseUrl, NodeUrl;
@BeforeTest
@Parameters ({"platform", "browserName", "remoteurl"})
public void setUp(String platform , String browserName, String remoteurl) throws MalformedURLException{
baseUrl = "http://youtube.com";
DesiredCapabilities capability = null;
if(browserName.equals("chrome")) {
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
System.out.println("Browser Name is Chrome!" );
} else {
System.out.println("Invalid Browser Name");
}
 
capability.setPlatform(Platform.WIN10);
capability.setVersion("54.0");
capability.setCapability(FirefoxDriver.MARIONETTE, true);
driver = new RemoteWebDriver (new URL (remoteurl), capability);
}
@Test 
public void OpenUrl(){
driver.get(baseUrl);
driver.findElement(By.id("masthead-search-term")).sendKeys("pwrdby");
driver.findElement(By.id("masthead-search-term")).sendKeys(Keys.ENTER);
System.out.println("You opened Google.com on differnt system, and your tEST IS FINE!!");
}

}
*************************
Testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" thread-count ="1" parallel = "test">
  <test verbose="2" name="WIN10">
  <parameters>
<parameter name ="platform" value = "WIN10"/>
<parameter name ="browserName" value = "chrome" />
<parameter name ="remoteurl" value = "http://192.168.1.117:5568/wd/hub" />
</parameters>
    <classes>
      <class name="ParallelTest.SampleParalleltest">
      <methods>
<include name = "OpenUrl" />  <!-- Name of the TESTS -->
</methods>
</class>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Error which i got while running!

[TestNG] Running:
  C:\Users\giri\AppData\Local\Temp\testng-eclipse-2096902633\testng-customsuite.xml

[Utils] Attempting to create D:\Vinoth\Selenium\Updated one\Workspace\ParalelTestwithSeleniumgrid\test-output\Default suite\Default test.xml
[Utils]   Directory D:\Vinoth\Selenium\Updated one\Workspace\ParalelTestwithSeleniumgrid\test-output\Default suite exists: true
FAILED CONFIGURATION: @BeforeTest setUp
org.testng.TestNGException: 
Parameter 'platform' is required by @Configuration on method setUp but has not been marked @Optional or defined
in C:\Users\giri\AppData\Local\Temp\testng-eclipse-2096902633\testng-customsuite.xml

I will be happy if anyone could help out on this. thanks in advance!

custom...@gmail.com

unread,
Jul 14, 2017, 3:35:12 PM7/14/17
to testng-users
Hi, did you find any solution for this problem? i have the same(( and cant find the solution

⇜Krishnan Mahadevan⇝

unread,
Jul 17, 2017, 1:34:06 AM7/17/17
to testng...@googlegroups.com

How are you running your test ? Am hoping you are running it from within the IDE by right clicking on the corresponding suite xml file and NOT by right clicking on the corresponding TestNG test class.

If the above still doesn't resolve your issue please make sure you include the following :

1. TestNG version (please use 6.11 which is the latest released version )
2. Sample test code which can be used to recreate the problem ( please trim it to a simple one which doesn't use any selenium etc )
3. How are you running it ? Via IDE (which IDE?) or via a build tool (Gradle/ant/maven) or via command prompt (using Java command)


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
--

80Vikram

unread,
Aug 2, 2017, 10:05:26 AM8/2/17
to testng-users
Hi Krishnan,

I'm also facing same issue when I've below setup

 
    @BeforeSuite
    @Parameters({ "appName_" })
    public synchronized void setupMethod()

It works well in below case though

    @BeforeTest(alwaysRun = true)
    @Parameters({ "appName_" })
    public synchronized void setupMethod

My requirement is that I need to run multiple test classes in parallel but want to call @BeforeSuite in only 1st test class which does the setup.

Please clarify.

Thanks & Regards,
Vikram

80Vikram

unread,
Aug 2, 2017, 10:24:36 AM8/2/17
to testng-users
I found this https://stackoverflow.com/questions/10651725/how-to-use-testng-parameters-in-beforesuite-to-read-resource-file but it doesn't solve my problem

As I need to pass multiple parameter values for each of the test classes, how to define them at suite level ?

I need the setup for parallel execution with appium + selenium grid + all connected android emulators.

Thanks,
Vikram

Krishnan Mahadevan

unread,
Aug 2, 2017, 11:35:16 PM8/2/17
to testng...@googlegroups.com

Please share a simple test, which can be executed to reproduce the problem so that it would help folks here understand what is going wrong.

Also include the following information:

 

  1. TestNG version [ The latest released version is 6.11]
  2. How are you running the tests [via IDE or via a build tool]
  3. What does your suite xml file look like

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

khushboo vyas

unread,
Jun 11, 2018, 3:21:50 AM6/11/18
to testng-users
Hi all who are facing this issue "Parameter 'browser' is required by BeforeTest on method setup but has not been marked @Optional or defined".
- run your test by doing -->right click-->run as Testng suite on your .xml class particularly. 

akash kansal

unread,
Jun 11, 2018, 3:38:16 AM6/11/18
to testng-users
Hi,

Please Read this post. 


If still not able to solve then add testng.xml file  configuration in your pom.xml.
working fine in my project.

Manish Chaudhari

unread,
Jul 24, 2018, 9:00:22 AM7/24/18
to testng-users
In xml file try with the below code: - 
Change the parameter line position in the xml file.

<suite name="Suite" parallel="tests">
<parameter name="browser" value="Firefox"/>
  <test name="FirefoxTest">
  
On Thursday, October 29, 2015 at 7:59:44 PM UTC+5:30, prasanth kotagiri wrote:

Yevhen B

unread,
Jul 25, 2018, 4:17:35 AM7/25/18
to testng...@googlegroups.com
Manish,
You probably missed mentioning your testng.xml Surefire's configuration in POM:

<configuration>
<suiteXmlFiles>
<suiteXmlFile>${project.build.testOutputDirectory}/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
Cheers,
Yevhen



--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.

Hasmukh patel

unread,
Sep 3, 2018, 3:38:31 AM9/3/18
to testng-users
Hi,
I am having same problem.

Here is my testng.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
        <classes>
            <class name="testSelenium.DNATest">
                <methods>
                    <parameter name="browser" value="Chrome"></parameter>
                    <include name="test_Login" />
                </methods>
            </class>
        </classes>
    </test>
</suite>

----
@Test(priority=1)
    @Parameters("browser")
    public void test_Login(String browser) throws InterruptedException{
        System.out.println(browser);

---Error
SKIPPED: test_Login
org.testng.TestNGException:
Parameter 'browser' is required by @Test on method test_Login but has not been marked @Optional or defined
in C:\Users\hpatel\AppData\Local\Temp\testng-eclipse-683121992\testng-customsuite.xml
    at org.testng.internal.Parameters.createParameters(Parameters.java:154)
    at org.testng.internal.Parameters.createParameters(Parameters.java:361)
    at org.testng.internal.Parameters.handleParameters(Parameters.java:451)
    at org.testng.internal.Invoker.handleParameters(Invoker.java:1274)
    at org.testng.internal.Invoker.createParameters(Invoker.java:989)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1079)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

Krishnan Mahadevan

unread,
Sep 3, 2018, 11:58:00 AM9/3/18
to testng...@googlegroups.com

Can you please try using TestNG 6.14.3 (the latest released version as of today) and let us know if this is still a problem ?

Since you haven’t shared the imports you are using, you might also want to quickly double check if the annotations are all from the TestNG project and not from the Junit project.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

From: <testng...@googlegroups.com> on behalf of Hasmukh patel <hasmukh...@gmail.com>


Reply-To: <testng...@googlegroups.com>
Date: Monday, September 3, 2018 at 1:08 PM
To: testng-users <testng...@googlegroups.com>

--

You received this message because you are subscribed to the Google Groups "testng-users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.

mario...@globant.com

unread,
Jan 21, 2019, 3:32:52 PM1/21/19
to testng-users
it works for me to create an xml and run it , is like this

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
 
<suite name="My second suite" >

 <parameter name="browser"  value="chrome"/>
 
  <test name="My second test">

  <classes>
    <class name="com.automation.training.tests.WikiTests">
    </class>
  </classes>
  
 
 </test>
</suite>


 please check if the value is the same in your class  MyDriver"chrome" and the test suite  <parameter name="browser"  value="chrome"/>

The information contained in this e-mail may be confidential. It has been sent for the sole use of the intended recipient(s). If the reader of this message is not an intended recipient, you are hereby notified that any unauthorized review, use, disclosure, dissemination, distribution or copying of this communication, or any of its contents, is strictly prohibited. If you have received it by mistake please let us know by e-mail immediately and delete it from your system. Many thanks.

 

La información contenida en este mensaje puede ser confidencial. Ha sido enviada para el uso exclusivo del destinatario(s) previsto. Si el lector de este mensaje no fuera el destinatario previsto, por el presente queda Ud. notificado que cualquier lectura, uso, publicación, diseminación, distribución o copiado de esta comunicación o su contenido está estrictamente prohibido. En caso de que Ud. hubiera recibido este mensaje por error le agradeceremos notificarnos por e-mail inmediatamente y eliminarlo de su sistema. Muchas gracias.


milgina G

unread,
Jan 22, 2019, 3:16:53 AM1/22/19
to testng-users
Thanks khushboo vyas

Abhijeet Kumar Gunjan

unread,
Feb 4, 2020, 2:19:48 PM2/4/20
to testng-users
According to me the biggest which mostly everyone is doing is adding Parameter tag after test block in testng.xml specially for @before annotation case, that is 


<suite name="Suite">
  <test thread-count="5" name="Test">
  <parameter name="browser"  value="chrome_u"/>
    <classes>
      <class name="Demo_Package.Dummmmy"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Correct one is:-

<suite name="Suite">

  <parameter name="browser" value="chrome_u"/>
  <test thread-count="5" name="Test">
    <classes>
      <class name="demo_Package.Dummmmy"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

and we can add the @Optional too now that is 

@Parameters({"browser"})
@BeforeSuite(alwaysRun=true)
public void login(@Optional("chrome") String browser) throws Exception
        {

Satish T

unread,
Jul 6, 2020, 3:13:39 PM7/6/20
to testng-users
if you want to run the the same test case from independent class then use such syntax

@Test
@Parameters({ "browser", "version" })
public void takeScreenShot(@Optional("firefox") String x, @Optional("65") String y) { ......}

and if ur running from testng.xml then u need not to add @Option parameter in ur test

 <suite name="Suite">
<parameter name="browser" value="firefox"></parameter>
<parameter name="version" value="65"></parameter>
<test thread-count="5" name="Test">
<classes>
<class name="com.qa.tests.ExcelWrite" />
</classes>
</test> <!-- Test -->

basically when u run the test case from indenedent class then testng.xml never comes into picture so the @Test will not get values and u will get error, to avoid this error we use @Optional  , means if ur @Test will not get values then it uses from @Optional
Reply all
Reply to author
Forward
0 new messages