Tuesday 21 January 2014

Java convert string to int value

Java provides two method parseInt() and valueOf() method to convert string into integer. Below example shows the usage of two methods to convert string to integer.

public class StringtoNumber {

public static void main(String[] args) {
String String1 = "000456";
  try{
  // using Integer.parseInt method
       int intvalue = Integer.parseInt(String1);
       System.out.println("With parseInt method, intvalue = " + intvalue );
        } catch(NumberFormatException e) {
        System.err.println("NumberFormatException in parseInt, "+ e.getMessage());
        }
         
        try{
        // using Integer.valueOf method
             int intvalue = Integer.valueOf(String1);
             System.out.println("With valueOf method, intvalue = " + intvalue );
             
          } catch(NumberFormatException e) {
              System.err.println("NumberFormatException in valueOf, "+ e.getMessage());
        }
     }
}

Output -
      With parseInt method, intvalue = 456

      With valueOf method, intvalue = 456

Note - Catch section gets executed in case, Java fails to convert string to integer.

Thursday 9 January 2014

Selenium WebDriver: How to Handle Ajax Application

A common problem we face during automation using selenium WebDriver is to handle the ajax calls. It is difficult to know when the call is complete and page has been updated. There are several ways to handle the ajax calls. This blog describes them one by one.
We can handle Ajax calls in two ways:


1. Hard Wait - this is most commonly used method but not recommended while doing the automation. Only in some exceptional cases use or for short time use it
·    JAVA: Use java method Thread.Sleep( to suspend execution for specified time. Syntax –

Thread.sleep(1000) // time unit is millisecond

·   Implicit Wait – An implicit wait is to tell WebDriver to stop the DOM for a certain amount of time. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance. Syntax –

driver.manage().timeouts().Implicitly Wait(10, TimeUnit.SECONDS); 
// Time is in  seconds or we can also change Unit in second argument

2.   Explicit Wait: An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code. Sample code is as follows -

WebDriver driver = new FirefoxDriver();
driver.get("http://google.co.in");
WebDriverWait myDElement = new WebDriverWait(driver, 10)

.until(ExpectedConditions.presenceOfElementLocated(By.xpath("xxxxx")));

Tuesday 7 January 2014

HP QTP : What is a Run-Time Data Table? Where can I find and view this table


Data like parameterized output, checkpoint values, and output values are stored in the Run-time Table. It is an XLS file which is stored in the Test Results Folder.  It can also be viewed in the Test Report. Click on View -> Data Table to display data table.

QTP : How will you check a web application for broken links



You can use the Page Checkpoint which gives a count of valid/invalid links on a page.

HP QTP : What is the difference between functions and actions in QTP




               QTP Action
                 Function
  • Action is a QTP concept and it can use QTP features like own Object Repository, Data Table, checkpoints etc.
  • Actions help make your Test modular and increase reuse. Example: You can divide your script into Actions based on functionality like Login, Logout etc.
  • It is slow in execution.
  • Functions is a VB Script programming concept and do not have their own Object Repository or Data Table. Functions help in re-use of your code. Ex:  You can create a Function in your script to concatenate two strings.
  • We can’t use checkpoints in functions, instead of checkpoints we can use validation points (Loops and Conditional statements)
  • Functions are faster in execution than Actions