0
@BeforeClass
@Parameters("folderName")
public void setUp(String folderName) {
    createLogger(this.getClass().getSimpleName(),folderName);
    configureDriver();
}

@AfterClass
public void tearDown() {
    shutDown();
}

When I run the above test case using maven

 mvn path/to/pom.xml clean -Dtest=HerveLeger test

It's giving following exception

setUp(com.hb.MFA.HerveLeger)  Time elapsed: 0.359 sec  <<< FAILURE!
org.testng.TestNGException: 
Parameter 'folderName' is required by @Configuration on method setUp_HerveLeger but has not been marked @Optional or defined

at org.testng.internal.Parameters.createParameters(Parameters.java:155)
at org.testng.internal.Parameters.createParameters(Parameters.java:358)
at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:86)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:199)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
at org.testng.SuiteRunner.run(SuiteRunner.java:254)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:115)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass(TestNGDirectoryTestSuite.java:129)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:113)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:111)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)

Here it is my TestNG.xml file

<test name="TEST NAME"> 
    <parameter name="folderName" value="TEstName"></parameter> 
    <classes> 
        <class name="com.org.Test" />
    </classes>
</test>

Please help me any one to solve this issue

1
Parameter 'folderName' is required by @Configuration on method setUp_HerveLeger but has not been marked @Optional or defined

It says it right in the exception description. You need to define a parameter in you're TestNG XML file or provide an optional value.

@Parameters("folderName")
public void setUp(@Optional("Insert folder name here or leave empty") String folderName) {

It is explained clearly in the TestNG Documentation: TestNG Parameters

Example TestNG.xml

<suite name="testSuiteNameHere">
<parameter name="folderName" value="SomeValue"/>
</suite>
  • Hello @CodeBreaker, I have tried your solution, Now it is not throwing any exception but it always taking the "Insert folder name here or leave empty" value instead of folderName – QAMember Mar 16 '16 at 5:21
  • @QAMember per TestNG docs "If no parameter is found in your testng.xml file, your test method will receive the default value specified inside the @ Optional annotation." You need to define a folder name parameter in your TestNG Xml file – CodeBreaker Mar 16 '16 at 5:25
  • Yes I have defined the parameter attribute with its value in TestNG.xml file – QAMember Mar 16 '16 at 6:27
  • There must be a config error or typo somewhere if it isn't picking it up. Make sure your maven config is registering the xml file or it is being passed correctly via command line – CodeBreaker Mar 16 '16 at 20:16
0

try this

mvn path/to/pom.xml clean -Dtest={testname} -DfolderName=HerveLeger test

Also you can try, removing @parameters and add simple java call

System.getProperty("folderName");

and pass it with

-DfolderName="HerveLeger"

thourgh maven goal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.