Friday, April 19, 2013

Write a value to text box using Web Driver



The below code writes the value in the textbox with property ele

public void Textbox(String ele, String value) {
            WebElement element = driver.findElement(By.id(ele));

            if (element != null) {
                  element.clear();
                  element.sendKeys(value);
            }
      }

Contributed by Ch. Suma

Thursday, April 18, 2013

Report pass or fail status in excel sheet in run time

The below code writes pass or fail status for a particular test case in the excel sheet.

The procedure takes 3 parameters.

shname is sheet name
tid is the test case id mentioned in the first column of the excel sheet
res is the result. it can be "pass" or "fail"
This result will be placed in the 5th column as the template will be (Testcase id, test case title, description, test data,Result)
If the test cases are more than 3000, change the value in the for loop

Public sub report_result(shname,tid,res)
    Set oexcel = CreateObject("Excel.Application")
    Set obook = oexcel.Workbooks.Open("c:\TF_Automation\Results\TF_TestScripts.xls")
    obook.Sheets(shname).select
'    oexcel.Visible=true
    For i=1 to 3000
        if tid=oexcel.Cells(i,1).value Then
            oexcel.Cells(i,5)=res
            Exit for
        End If
    Next
    obook.Save
    obook.Close
End Sub

Killng a process with specific size

The below code kills the javaw.exe process less than 40k size
 
Public sub close_processes
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process where name = 'javaw.exe'")
    npr=colProcess.count
    ReDim arrOld(npr)
    i=0
    For Each objProcess in colProcess
        If (objProcess.WorkingSetSize/1000000)<40 Then
            arrOld(i)=objProcess.ProcessId
            i=i+1
        End If
    Next
   
    For i=0 to ubound(arrOld)-1
        Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process where processID='" & arrOld(i) & "'")
        For Each objWMIProcess In colProcess
            intRC = objWMIProcess.Terminate()
         Next
    Next

    Set objWMIService = Nothing
    Set colProcess = Nothing

End Sub

Capturing and attaching screenshot for failed step


The below code capture screenshot and places the file in a specific location.

fCnt is a public variables to be declared in function library and initialized to 0

Public function capture_scrshot
       fCnt=fCnt+1
    desktop.CaptureBitmap"d:\Screenshots\" & fCnt & ".png",True
    capture_scrshot="d:\Screenshots\" & fCnt & ".png"
end  Function


This file can be attached to the failed step by calling this function as below

reporter.ReportEvent  micFail,"Step description","Step details",capture_scrshot

Handling Ajax dropdown - Webdriver



Below code types the value in the given dropdown   

  public void Dropdown1(String eleproperty, String value) {
            WebElement element = driver.findElement(By.id(eleproperty));
            if (element.isEnabled()) {
                  element.sendKeys(value);
                  Sleep();

            } else {
                  System.out.println("object is disable");
            }

            String actval = driver.findElement(By.id(eleproperty)).getAttribute("value");
            if (value.equals(actval)) {
                  System.out.println(actval);
            }
      }

Contributed by: Ch. Suma

Handling dropdown - webdriver



The Below code searches for an item in the drop down and selects it 

 public void Dropdown(String eleproperty, String value) {
            WebElement element = driver.findElement(By.id(eleproperty));
            if (element.isEnabled()) {
                  WebElement dropdown = driver.findElement(By.id(eleproperty));
                  Select select = new Select(dropdown);
                  String str = dropdown.getText();
                  List<WebElement> options = select.getOptions();
                  for (WebElement we : options) {
                        if (we.getText().equals(value)) {
                              we.click();
                              break;
                        }
                  }
            } else {
                  System.out.println("Object is disabled");
            }

      }

Contributed by: Ch. Suma

Wednesday, April 17, 2013

Debugging

After the script are developed to make sure that the scripts are correct and we need to debug the script

Script can have two types of errors:
1.    Syntactical Errors        2. Logical Errors.
 

Syntactical Error can be identified by running script or saving script and verify in Information pane
 

For Logical Error we need to apply Debug options.
 


Debugging is a process of executing the test script with some temporary breaks in order to identify the errors.
 

To do the same QTP has provided below Debug options:
1.    ExitRun
2.    ExitAction
3.    Break Point
4.    Step commands
    a. Step Into
    b. Step Out
c. Step Over
 

Step Into: It is used for executing a single step, If that step is a function call or action call then, it will step into the function or action.
 

Step out: It is used to executing all the remaining statements from the position of the pointer in a function or an action and steps out of the function or an action.

Step over: It is used for executing a single step. If that step is a function call or an action call then, it will execute the complete block of statements in that function or an action and steps out of that function or an action.
 

Break Points: It is a feature provided by QTP, which is used for breaking the execution temporarily

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

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...