Getting error related to @Parameters annotation while using testNG with Maven

Hello,
I’m using testNG with Maven and facing an error related to @Parameters annotation. I’ve created a launch bowser method in my test case and passing parameter (eg: Firefox) to it from testng.xml using @Parameters annotation.  I’ve mentioned the correct testNG.xml path in pom.xml and when run it as Maven test, I’m getting the error message “Parameter ‘browser’ is required by @Configuration on method launchPage but has not been marked @Optional or defined”. When I run testNG.xml file as a TestNGsuite (not as Maven test), it is working perfectly.  As per the error message I’ve included @Optional parameter and passed the hard coded browser value as ‘Firefox’ in the same above launch browser method (which shouldn’t be done as per my knowledge), in this case I’m not getting any error message but pom.xml is not recognizing and running testNG.xml (I was already appended my test cases with ‘Test’ at the end). Below is the pom.xml code. Please suggest any solutions. Many Thanks in advance.

<project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
<modelVersion>4.0.0</modelVersion>

<groupId>com.wordPress.maven</groupId>
<artifactId>WordPressMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>WordPressMaven-build</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<!– sourceDirectory>src/test/resources</sourceDirectory –>
<!– To define the plugin version in your parent POM –>
<pluginManagement>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/suites-test-testng.xml</suiteXmlFile>
</suiteXmlFiles>
<parallel>methods</parallel>
<threadCount>5</threadCount>

</configuration>
</plugin>

<!–
plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<encoding>iso-8859-1</encoding>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
–>

</plugins>
</pluginManagement>
</build>

<dependencies>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.45.0</version>
</dependency>

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>

<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-api</artifactId>
<version>2.18.1</version>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.3.1</version>
</dependency>

</dependencies>

<reporting>
<plugins>
<!– TestNG-xslt related configuration. –>
<plugin>
<groupId>org.reportyng</groupId>
<artifactId>reporty-ng</artifactId>
<version>1.2</version>
<configuration>
<!– Output directory for the testng xslt report –>
<outputDir>/target/testng-xslt-report/index.html</outputDir>
<sortTestCaseLinks>true</sortTestCaseLinks>
<testDetailsFilter>FAIL,SKIP,PASS,CONF,BY_CLASS</testDetailsFilter>
<showRuntimeTotals>true</showRuntimeTotals>
</configuration>
</plugin>
</plugins>
</reporting>

<pluginRepositories>
<pluginRepository>
<id>reporty-ng</id>
<url>https://github.com/cosminaru/reporty-ng/raw/master/dist/maven</url>
</pluginRepository>
</pluginRepositories>

</project>

Add Comment
4 Answer(s)

There has to be a parameter node inside your testNG.xml file which should send across the Browser variable. Something like this

<parameter  name=’browser’ value=’InternetExplorer ‘/>

if you dont need the parameter always, you can mark it optional by passing the default value in the method signature of the method which is looking for a variable called browser

something like this
@Parameter(‘browser’)
public void methodname(@Optional("mysql") browserVal)

Virender

Virender Singh Professor Answered on March 24, 2015.
Add Comment

Hello Virender,

Thanks for your response.  I’m passing the parameter from Testng.xml and want to use across my test still I’m facing the error. Below is my testng.xml please have a look and suggest any solutions for it so that it would be helpful. Many Thanks.

<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd” >

<suite name=”Suite1″ parallel=”tests” thread-count=”3″ >

<test name=”Add Blog dashboard / Firefox” >
<parameter name=”browser” value=”Firefox” />
<parameter name=”userName” value=”gpavanptesting@gmail.com” />
<parameter name=”Password” value=”Pavanroyal@16″ />
<classes>
<class name=”TestCases.PO_AddBlogDashboardRunnerClass”/>
</classes>
</test>
<test name=”Login / Firefox” >
<parameter name=”browser” value=”Firefox” />
<classes>
<class name=”TestCases.LoginTC”/>
</classes>
</test>
<test name=”Add Blog / Chrome” >
<parameter name=”browser” value=”Firefox” />
<parameter name=”userName” value=”pavangurram” />
<parameter name=”Password” value=”Pavanroyal@16″ />
<classes>
<class name=”TestCases.PO_AddBlogRunnerClass”/>
</classes>
</test>

</suite>

pavangurram Train Answered on March 24, 2015.
Add Comment

Hello Virender,

Could you please take time to have a look into above issue as it is not resolved by me.

Many Thanks
Pavan

pavangurram Train Answered on March 26, 2015.
Add Comment

Hi Pawan,

I am sorry I don’t have much expertise in Maven, but I think a few months back some one shared this with me

http://stackoverflow.com/questions/13245411/how-to-pass-java-code-a-parameter-from-maven-for-testing

Please try this and let me know.  It will be good if you can share a sample maven project with me, a small one, with this problem.

Virender

Virender Singh Professor Answered on March 27, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.