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

Friday 3 January 2014

What is the Difference between Bitmap Check point & Image Check point

Bitmap checkpoint does a pixel to pixel comparison of an image or part of an image.

Image Checkpoint checks the value of an image in your application like alt text, destination URL. Note: You create an image checkpoint by inserting a standard checkpoint on an image object. It is supported only in web environment.

How to create runnable jar file for your Selenium project

   1.   Right click on your project in eclipse
   2.   Select Export
   3.   Select [Java -> Runnable Jar file]
   4.   Provide Export Location
   5.   Click finish

 Run generated .jar file from command prompt


Script will run on machine having Browser & Java.

How to open Selenium IDE in Firefox

Selenium IDE can be opened in two ways
1.       Go to [View -> Side bar -> Selenium IDE]

2.       Go to [Tools -> Selenium IDE]

What are the element locators available with Selenium which could be used to locate elements on web page

There are mainly 5 locators used with Selenium –
1.       html id
2.       html name
3.       XPath locator
4.       Css locators
5.       DOM
6.       LinkText
7.       PartialLinkText
8.       Tagname

9.       Classname

Thursday 2 January 2014

QTP / UFT : How to for broken links on a web application

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


What is Text output & its use in QTP

A Text Output values enables to capture or to output text strings displayed in an AUT during run time. For example, suppose that you want to store the text of any error message that appears after a specific step in the Web application you are testing. You can create a text output value while recording or editing your test.

To create a text output value while recording:
1.   Highlight or display the text string you want to use for an output value.
2.  Select Insert > Output Value > Text OutputValue. The pointer changes into a pointing hand.
3.  In your application, click the text string for which you want to specify a text output value. The Text Output Value Properties dialog box opens.

4.  QTP creates a column (using logical name of object) in Global DataTable to store output value.