Monday, April 22, 2013

Connection string for mysql from QTP

server="10.1.1.1"
dbname="testdb"
dbuname="test"
dbpwd="testpwd"

Set rs=createobject("adodb.recordset")
set contf=Createobject("ADODB.Connection")
contf.Open "Driver={MySQL ODBC 3.51 Driver};SERVER=" & server & ";DATABASE=" & dbname & ";user id=" & dbuname & ";password=" & dbpwd & ";Pooling=True"
contf.CommandTimeout =300

rs.Open "SELECT user_id FROM user_details WHERE first_name='testname'",con
msgbox rs(0).value

Sort the column of a java table

The below code unsets the sort for all the columns and sets the descending order to the 2nd column of the java table

On error resume next
For i=0 to JavaWindow("Administrator").JavaTable("Pending").GetROProperty("cols")-1
    JavaWindow("Administrator").JavaTable("Pending").Object.setSortMode i,0
Next
JavaWindow("Administrator").JavaTable("Pending").Object.setSortMode 2,4
On error goto 0

Set date to date control of a java application

dt1=date-50
dt1=monthname(month(dt1),true) & " " & day(dt1) & ", " & year(dt1)
JavaWindow("Title").JavaList("To").Object.addItem dt1
JavaWindow("Title").JavaList("To").Select dt1
JavaWindow("Title").JavaButton("Go").Click

Check the background color of a row in a java table

set obj=JavaWindow("Title").JavaTable("JTable").Object
set obj1=obj.getCellRenderer(1,0)
obj.prepareRenderer obj1,1,0
set color=obj1.getBackground
If color.tostring="javax.swing.plaf.ColorUIResource[r=255,g=255,b=255]" Then
    msgbox "Its white color"
Else
    msgbox "Its not white color"
End if

Friday, April 19, 2013

Read the selected value from dropdown using Web Driver



Get selected option from dropdown:

      public String getSelecteduser(String ele) {
            WebElement dropdown = driver.findElement(By.id(ele));
            Select select = new Select(dropdown);
            WebElement option = select.getFirstSelectedOption();
            String str = option.getText();
            return str;
           
      }

Contributed by Ch. Suma

Write testcase result into Excel using Web Driver



Write testcase result into Excel: The below code writes the result of the test case in the 8th column of the excel sheet by creating a new excel file test_results.xls

public void excelwrite(int row) throws BiffException, IOException,
                  RowsExceededException, WriteException {

Workbook existingWorkbook = Workbook.getWorkbook(new File(
                        "D:\\Test cases.xls"));
WritableWorkbook workbookCopy = Workbook.createWorkbook(new File(
                        "D:\\Test_Results.xls"), existingWorkbook);
WritableSheet sheetToEdit = workbookCopy.getSheet("Sheetname");
            WritableCell cell;
            Label l = new Label(8, row, "Pass");
            cell = (WritableCell) l;
            sheetToEdit.addCell(cell);
            workbookCopy.write();
            workbookCopy.close();
            existingWorkbook.close();
            File firstFile = new File(
                        "D:\\Test cases.xls");
            firstFile.delete();

            File oldFile = new File("D:\\Test_Results.xls");

            oldFile.renameTo(new File(
                        "D:\\Test cases.xls"));
      }     

Contribute by Ch.Suma

Read data from excel using Web driver



Read data from Excel:

      public String readExcel(int row, int col, int sno) throws Exception {
            File file = new File(
                        "D:\\TestData\\Test cases.xls");
            Workbook wb = Workbook.getWorkbook(file);
            Sheet st = wb.getSheet(sno);
            Cell cl = st.getCell(row, col);
            String sr = cl.getContents();
            return sr;
      }

Contributed by Ch. Suma

AI in Software Testing: How Artificial Intelligence Is Transforming QA

For years, software testing has lived under pressure: more features, faster releases, fewer bugs, smaller teams. Traditional QA has done her...