I am going Home... Dec 2009
Author: Tarun K
I am finally going home for this year, I will be taking off for two weeks coming weekend. This is one of the most deserved holiday for me as my current project happened at break neck speed. My lateral enter in agile project which had about 9 sprints completed. I was assimilated to do Test Automation using a Tool which I had no idea of. I was disillusioned about those senior managers who I used to respect (why do they become manager if they can not tackle pressure!!!). My peevish manager is turned over appreciative now a days and keeping singing accolades for no reason (Is he next on the list of lay off). Any ways I got to meet many lovely developers during this project and this is the only take back I have from this project. I should stop this blog now lest it should be filled with sheer sarcasm.
0 Comment
Custom verification with selenium (Soft Assertion)
Author: Tarun K
Basic problem with existing verify.* methods of selenium is: they don't take message argument.
Hence when a verification error is encountered one would not be able to point root of failure. One way to over come this is to overload existing verify.* methods to take message argument. Here in I have listed entire class which we use for custom verification is Selenium -
package com.ciber.core.functionlibrary;
import org.testng.Reporter;
import com.thoughtworks.selenium.SeleneseTestBase;
/**
* Adds message to verify.* methods
* This message would be available in test report if verification fails
* checkForVerificationErrors SHOULD be called on the object
* of CustomVerification class, else test method would not be marked
* as fail even in the wake of verification errors
*
* @author tbhadauria
*
*/
public class CustomVerification extends SeleneseTestBase {
public void verifyTrue(String msg, Boolean b) {
try{
assertTrue (b);
} catch (Error e) {
verificationErrors.append(e);
Reporter.log(msg);
}
}
public void verifyEquals(String s1, String s2) {
try {
assertEquals(s1, s2);
} catch (Error e) {
verificationErrors.append(e);
}
}
public void verifyEquals(String msg, String s1, String s2) {
try {
assertEquals(s1, s2);
} catch (Error e) {
verificationErrors.append(e);
Reporter.log(msg);
}
}
public void verifyEquals(String msg, Object obj1, Object obj2) {
try {
assertEquals(obj1, obj2);
} catch (Error e) {
verificationErrors.append(e);
Reporter.log(msg);
}
}
public void verifyEquals(String msg, String[]str1, String[] str2) {
try {
assertEquals(str1, str2);
} catch (Error e) {
verificationErrors.append(e);
Reporter.log(msg);
}
}
public void verifyEquals(String msg, Object[]str1, Object[] str2) {
try {
assertEquals(str1, str2);
} catch (Error e) {
verificationErrors.append(e);
Reporter.log(msg);
}
}
}
~ T
HTML Parsing and Selenium
Author: Tarun K
HTML parsing is always been a burning requirement with selenium. Though Selenium doesn’t have built in API which could do HTML parsing,
given its high integrability it could be integrated with HTMP parser to achieve the same. I have experimented on HTML parsing using Jericho which is java library. To begin HTML parsing the only demand Jericho makes is about HTML Source and this could be obtained using Selenium API - getHtmlSource(). Herein I have listed functions which I have developed using Jericho -
Count number of tables on a page –
// Get Source object for HTML Tables.
Source source = new Source(selenium.getHtmlSource());
List
Reporter.log("Number of Tables are: " +table.size());
***Reporter is TestNG API***
Retrieve Table Data-
// Retrieve table data from a specific table.Source tableSource = new Source(table.get(3).toString());
Reporter.log("Table data is:" +HTMLTableParser.getTableData(tableSource, false)); Reporter.log("True Table data is:" +HTMLTableParser.getTableData(tableSource, true));
Definition of ***getTableData*** is as following –
/**
* Returns the Segment or content of HTML table
* available between Start and End tag
*
* @param tableSource
* @param rawHTMLData
*
* @return HTML Table data
*/
public static List
// Table data to be returned
List
// Collect table rows
List
// Loop through table rows
for (int tableRowIndex=0; tableRowIndex
// Loop through table columns
for(int tableColummnIndex=0; tableColummnIndex
return tableRows.size();
}
Count Number of columns in a individual rows –
Map
for(Map.Entry
Reporter.log("Number of columns at row: " +rowAndColumnData.getKey()
+" are: " +rowAndColumnData.getValue());
}
// Get data from individual columns.
Reporter.log("Column specific table data is:" +HTMLTableParser.getTableDataForColumn(tableSource, false, 0, 1));
Reporter.log("Column specific raw table data is:" +HTMLTableParser.getTableDataForColumn(tableSource, true, 0, 1));
Definition of ***countTableColumnsInRows*** is as following –
/**
*
* Retrieves table data for specific columns beginning from specific row
* To return data from beginning of row pass rowNumber as *0
*
* @param tableSource
* @param rawHTMLData
* @param rowNumber
* @param columnNumber
* @return Table Data
*/
public static List
Boolean rawHTMLData, int rowNumber, int columnNumber) {
// Table data to be returned
List
// Collect table rows
List
// Loop through table rows
for (int tableRowIndex=rowNumber; tableRowIndex
// If supplied index is with in size of table data
// This check is useful when retrieving data from uneven html table
if (columnNumber < rawhtmldata ="="">
All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or sponsors.