Tuesday, March 29, 2011

Automate rich text editor

Using selenium 1.0 difficult to Automate rich text editor, i have wasted my whole day to automate rich text editor , finally i got success.

to automate following type of rich text editor :

As selenium IDE will not record any text entering in to text area. we need to add manually


        selenium.selectFrame("//table/tbody/tr[2]/td/iframe"); //frame location
        selenium.typeKeys("//html/body/p/br", comment_fromdrupal);
        selenium.selectWindow("null");
        assertTrue(selenium.isElementPresent("edit-submit"));
        selenium.click("edit-submit");


so, for frame position, search using xpather, and use typeKeys.

Friday, March 4, 2011

Data driven test using multiple excel sheets

use jxl.jar

public String[] getExcelDataByRow(String sheetName, int rowNum){
       //Create a dynamic array
       String[] retVal=null;
       try{
           Workbook w=Workbook.getWorkbook(new File("c:/data.xls));
           Sheet s=w.getSheet(sheetName);
           //get the number of columns in the excel sheet
           int colCount=s.getColumns();
           //fix the size of the array with the col count
           retVal=new String[colCount];
           //loop through all the columns and store the value into
the array
           for(int i=0;i<colCount;i++){
               retVal[i]=s.getCell(i, rowNum-1).getContents();
           }
       }
       catch(Exception e){
           e.printStackTrace();
       }
       return retVal;
   }

--------------------------------------------
call the above method
String[] dataArr=dl.getExcelDataByRow("Login", 2);

Login is sheet name