Sunday, June 16, 2013

Selenium : Framework

Selenium : Framework 

Explanation:

1. We are using Excel Sheet 1 as Input sheet and treating it like a database.
2.The test cases are retrieved based on the query where Execute (1st row treated  as column header) is "yes" .
3. In our case ,Test Case 3 , is "yes" .Therefore that row is retrieved.
4. The retrived data i.e., row is in the form of a string ,with "|" used as a separator to differentiate between each cell.This  is convertered into a 1D array.
5. This 1D array is stored in a dictionay , where "test_case_name" holds Name of the test case and operation_1,operation2..... holds the corresponding operations .

Output:

  •  null|Test Case 3|yes|LOGIN(usn,pass)|Welcome|Logout|null
  • Test Case 3

(1st line is the processed string from the query
2nd line , number of elements
3rd line is dictionary key)

import java.util.Dictionary;
import java.util.Hashtable;


class Sample
{
public static void main(String[] args)
{
Dictionary dict = new Hashtable();
Object oData=Excel_DB.mOperation("Framework", "Select * from [Sheet1$] where Execute='yes'");
System.out.println(oData);
String[] aArr=oData.toString().split("\\|");
System.out.println(aArr.length);
dict.put("test_case_name",aArr[1]);
for (int iCount=3 ;iCount<=aArr.length-1;iCount++) //
{
dict.put("Operation "+(iCount-2),aArr[iCount]); //Dictionay name starts with Operation 3,Operation 4 ...
}
System.out.println(dict.get("test_case_name")); // Dictionary name to be displayed

}
}


import java.sql.*;
// Excel Format -- > SlNo Test_Case_Name Execute Operations_1 Operations_2 //Each space is seperate column

public class Excel_DB//Connect_Xl_using_JDBC
{
public static Object mOperation(String sWb,String sQuery)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:"+sWb);
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(sQuery);
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount(); //Get Column Count
// System.out.println("Columns="+numberOfColumns);

Object columnValue = null;
while (rs.next())
{
for (int i = 1; i <= numberOfColumns; i++)
{
if (i > 1)
columnValue = columnValue+"|"+rs.getString(i);
}
}
st.close();
con.close();
return columnValue;
}
catch (Exception ex)
{
System.err.print("Exception: ");
System.err.println(ex.getMessage());
return null;
}
}
}

No comments:

Post a Comment