Monday, June 17, 2013

Selenium - log4j:WARN

Selenium : log4j:WARN




Please find the below steps to solve the issue

Issue :
log4j:WARN No appenders could be found for logger (com.app.MyLogger).
log4j:WARN Please initialize the log4j system properly.


Solution :
1)download log4j-1.2rc1-2002-04-16.jar file
2)Add the log4j-1.2rc1-2002-04-16.jar file to build path
3)create object private static org.apache.log4j.Logger log= Logger.getLogger(MyLogger.class);
4)once you run the Mylogger.java file system will automatically creates the log4j.properties file
5)find out the log4j.propertiesfile and replace the contents as per the requirements(mostly system will creates in bin directory)
6)if not find log4j.properties file create one new file in bin directory (/workspace/projectdirectory/bin/)
6)log4j.properties
log4j.rootLogger=debug, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%t %-5p %c{2} - %m%

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;
}
}
}