santosh
santosh

Reputation: 171

Passing two parameters to testng test @Test

Code Snippet:

@Test
 @Parameters({"a,b"})
 public void submitLogin(String a , String b){
//Code here
    }

Error Displayed in Console: Method submitLogin requires 2 parameters but 1 were supplied in the @Test annotation.

Upvotes: 1

Views: 5614

Answers (3)

Sundeep Gupta
Sundeep Gupta

Reputation: 1966

The @Parameters allows you to specify the parameter names, whose value you put in the testng.xml file; Each parameter name must be a string. In your case you clubbed both the parameter names[ a, b] into one single String. The solution would be:

@Test
@Parameters({"a", "b"})
public void submitLogin(String a , String b){
    //Code here
}

And in your testng.xml define values for these variables as :

<parameter name="a" value="foo"/>
<parameter name="b" value="bar"/>

And yes, the order of annotations, @Parameters and @Test should not matter.

Upvotes: 1

QArea
QArea

Reputation: 4981

Try to use Parameters annotation before Test one. And each parameter should be quotation marked.

@Parameters({"a","b"})
@Test
 public void submitLogin(String a , String b){
//Code here
    }

Upvotes: 1

user1058106
user1058106

Reputation: 530

Don't you think that you are trying to pass one parameter "a,b" instead of two "a","b"?

Upvotes: 1

Related Questions