I'm looking for a bit of assistance with my plan layout if possible
Currently what I have is the following which works well:
@dataprovider connects to a mysql database, then stores 300 results into an
array
@test loops for all 300 entries and all tests pass
What I need, and I'm struggling with is:
After the @test has finished I then need to somehow go back to the
dataprovider (with a variable) then run the query and tests again.
If you imagine a directory structure, I query the database for all
categories beginning with A, test the results then re-query the database for
categories beginning with B and re-test the outcome.
Not sure how to go about this, so far I've tried to add in a loop into my
@dataprovider, so the array have for example 300 A categories, 300 B
categories etc. But this was giving me all sorts of issues with the array.
Any ideas how I can achieve this or would I need a separate class for each
data query?
Mike
--
View this message in context: http://old.nabble.com/Looping-within-%40dataprovider--Looping-a-class--Help-Req%21%21-tp32060376p32060376.html
Sent from the testng-users mailing list archive at Nabble.com.
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Below is a copy of the current code I have including the loop to query the
database again within the @dataprovider.
The issue i'm having is the return for the array, no matter how or where I
put it it simply does not work ('myData cannot be resolved to a variable'
appears as an error for the final line) if its included in the loop which
I've defined near the top of the test.
Hopefully its something simple.
Code below//get data
@DataProvider(name = "GetCategoryByLetter")
public String [][] RetrieveData(){
for(int i=1; i<3; i++){
int rowCount = 0;
int columnCount = 0;
String ABC = null;
switch (i){
case 1: ABC = "a";
break;
case 2: ABC = "b";
break;}
//ABC is category letter
//SQL query
String SQL =
"SELECT Name, category_id, uri_name, @rownum:=@rownum+1 as rownumber\n" +
"FROM (\n" +
"SELECT Name,category_id, uri_name\n" +
"FROM tbl_business_category\n" +
"Where Name like '"+ABC+"%' And display_category = 1\n" +
"ORDER BY category_id ASC\n" +
") Name,\n" +
"(SELECT @rownum:=0) r\n";
//Connect to the database.
String myData [][] = null;
try {
Class.forName("com.mysql.jdbc.Driver") ;
String url = "jdbc:mysql://site";
Connection conn = DriverManager.getConnection(url,"user","pass");
// Execute the SQL statement
Statement stmt = conn.createStatement();
ResultSet resultSet = stmt.executeQuery(SQL);
// Get Column count
ResultSetMetaData resultSet_metaData= resultSet.getMetaData();
columnCount = resultSet_metaData.getColumnCount();
// Get Row Count
while( resultSet.next() )
rowCount++;
//Initialize data structure
myData = new String [rowCount][(columnCount)];
resultSet.beforeFirst();
//populate data structure
for(int row=0; row<rowCount; row++)
{
resultSet.next();
for(int col=1; (col<=(columnCount)); col++)
{
myData[row][col-1] = resultSet.getString(col);}
}
stmt.close();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}//loop
return myData;
}
--
View this message in context: http://old.nabble.com/Looping-within-%40dataprovider--Looping-a-class--Help-Req%21%21-tp32060376p32062569.html
I had noticed that but if I move the array within the loop I get the
following for the RetrieveData 'This method must return a result of type
String[][]'
its as tho it cannot be seen once its in the loop
--
View this message in context: http://old.nabble.com/Looping-within-%40dataprovider--Looping-a-class--Help-Req%21%21-tp32060376p32062908.html
Cédric Beust ♔
15 July 2011 5:15 AM
Michael, I suggest you read a Java tutorial, this will help you tremendously moving forward.
--Cédric
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
mburns
15 July 2011 5:12 AM
Hi,
I had noticed that but if I move the array within the loop I get the
following for the RetrieveData 'This method must return a result of type
String[][]'
its as tho it cannot be seen once its in the loop
Cédric Beust ♔
15 July 2011 4:46 AM
You are declaring myData inside the for loop but returning it outside.
--Cédric
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
mburns
15 July 2011 4:28 AM
Cédric Beust ♔
15 July 2011 2:01 AM
The easiest way to do this is to calculate all the values that you need upfront, which is what you did by getting 300 results with A, then 300 results with B and then returning that result.
What kind of issues did you run into with this approach?
--Cédric