How to pass testng Dataprovider first set parameters to first test and second set Paramater to second test ans so on -
here code, want pass first set data {"shankar","admin123"} test1() , second set data {"siva","admin@123"} test2(), please me on have tried @ factory also...please me guys.
package com.vmetry.dataprovider; import org.testng.annotations.dataprovider; import org.testng.annotations.test; public class dataprovidertest { @test(dataprovider="dp") public void test1(string uname, string pass){ system.out.println("the test1 param are: "+uname+"-"+pass); } @test(dataprovider="dp") public void test2(string uname, string pass){ system.out.println("the test1 param are: "+uname+"-"+pass); } //passing data provider data @dataprovider(name="dp") public object[][] data(){ object[][] obj={{"vasanth","admin123"},{"shanmugam","admin@123"}}; return obj; } }
****************************actually case************************ please click image know scenario requirement
in example not need use dataprovider
@ all:
public class dataprovidertest { @test public void test1(){ string uname="shanmugam"; string pass="admin123"; system.out.println("the test1 param are: "+uname+"-"+pass); } @test public void test2(){ string uname="shanmugam"; string pass="admin@123"; system.out.println("the test1 param are: "+uname+"-"+pass); } }
if odd reason must use dataprovider
can create additional ones filter original one:
public class dataprovidertest { @test(dataprovider="dp1") public void test1(string uname, string pass){ system.out.println("the test1 param are: "+uname+"-"+pass); } @test(dataprovider="dp2") public void test2(string uname, string pass){ system.out.println("the test1 param are: "+uname+"-"+pass); } @dataprovider(name="dp1", indices={0}) public object[][] data(){ return data() } @dataprovider(name="dp2", indices={1}) public object[][] data(){ return data() } @dataprovider(name="dp") public object[][] data(){ return new object[][]{{"vasanth","admin123"},{"shanmugam","admin@123"}}; } }
or if want 1 test class per data provider record test(s):
public class dataprovidertest { private final string uname; private final string pass; @factory(dataprovider="dp") public dataprovidertest(string uname, string pass) { this.uname=uname; this.pass=pass; } @dataprovider(name="dp") public static object[][] data() { return new object[][]{{"vasanth","admin123"},{"shanmugam","admin@123"}}; } @test public void test() { system.out.println("the test1 param are: "+uname+"-"+pass); } }
Comments
Post a Comment