Sunday, 29 December 2013

Selenium - How to highlight Element

It is always a good practice to highlight element before performing an operation. This helps us to know where the Selenium is currently focused or which element it is being executed.

There is no native way to do this, but because Selenium allows to execute JavaScript, it can be accomplished by  executing JavaScript method. Code is as follows -

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class HighLightElement {

WebDriver driver = new FirefoxDriver(); //Launch firefox browser

@Test
   public void highlightTest() throws InterruptedException {
driver.get("https://www.facebook.com/"); // open facebook site
driver.manage().window().maximize(); // maximize browser
WebElement emailField = driver.findElement(By.xpath("//*[@id='email']")); //get
                reference to email text field
Thread.sleep(2000); //Stop program execution for 2 seconds
highlightElement(emailField); // call to highlight method


/** Method which executes Java Script code to highlight page object */
public void highlightElement(WebElement element) { 
   for (int i = 0; i < 2; i++) 
  { 
JavascriptExecutor js = (JavascriptExecutor) driver; 
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "color: red; border: 5px solid red;"); 
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, ""); 
     } 

}

Saturday, 28 December 2013

What is the difference between check point and output value


                   Checkpoint
                      Output Value
·        A checkpoint is a verification point that compares a current value for a specified property with the expected value for that property.
·        When the test is run, HP QTP compares the expected results of the checkpoint to the current results.
·        If the results do not match, the checkpoint fails & results of the checkpoint can be viewed in the Test Results window.
·        When Checkpoint is added, HP QTP adds a checkpoint with an icon in the test tree and adds a Checkpoint statement in the Expert View.
·        Checkpoint syntax - Window("Flight Reservation").WinComboBox("Fly To:").Check CheckPoint("Fly To:")
·        Insert -> Checkpoint -> Select the type of Checkpoint OR Right click the object in the Active Screen and select the type of checkpoint to be added.


·        An Output Value is used to retrieve the current value of any object in the application and stores it in a specified location. It can output values from text strings, table cells, databases, and XML documents. Unlike Checkpoints, no PASS/FAIL status is generated.
·        An output value is a value captured during the test run and entered in the run-time Data Table for use at another point in the test run.
·        When you create an output value, the test retrieves a value at a specified point during the test run and stores it in a column in the current row of the run-time Data Table.
·        When the value is needed later in the test run as input, HP QTP retrieves it from the Data Table.
·        You can output the property values of any objects.
·        Insert -> Output Value->Select the type of output value OR Right click the object in the Active screen and select the type of output value to be added.


Thursday, 26 December 2013

Selenium - How to read URL of a link

Selenium code to get URL is as follows -

    1. Find the link as a Web Element using findElement() method

                      WebElement Lnk_URL =  driver.findElement(By.id("Lnk"));

    2. Get URL value using  "href" attribute
                      
                       String URL = Lnk_URL.getAttribute("href");

Monday, 23 December 2013

What are the drawbacks of QTP

As of QTP version 10
·        Huge Tests in QTP consume lots of memory and increase CPU utilization.

·        Since QTP stores results in HTML file (and not txt) the result folder sometimes becomes big.

What is HP QTP Test Batch Testing tool

HP Quick Test Professional Test Batch Runner runs several tests in succession. Once the scripts are added in the tool, it will automatically open the scripts and start executing them one after the other.
·        To enable Test Batch Runner to run tests, you must select [Allow other HP products to run tests and components] in the Run pane of the Options dialog box.
·        Test Batch Runner can be used only with tests located in the file system. If you want to include tests saved in Quality Center in the batch run, you must first save the tests in the file system.
·        You can stop a test batch run at any time by clicking the Stop button.

To set up and run a test batch:
1.      From the Start menu, select Programs > Quick Test Professional > Tools > Test Batch Runner. The Test Batch Runner dialog box opens.
2.      Click the Add button or select Batch > Add. The Open Test dialog box opens.
3.      Select a test you want to include in the test batch list and click Open. The test is added to the list.
4.      If you want to save the batch list, click the Save button, or select File > Save, and enter a name for the list. The file extension is .mtb.
5.      When you are ready to run your test batch, click the Run button or select Batch > Run.


Thursday, 19 December 2013

Selenium - Can we set the speed of the WebDriver

This piece of functionality does not exist in Selenium WebDriver.  WebDriver provides  implicit wait and explicit wait to make sure that conditions happen before you attempt an action.

Tuesday, 10 December 2013

Java - How to check Palindrome

public class palindrome {
public static void main(String[] args) {
String original, reverse="";
        original = "jaj";
        int length = original.length();
        for ( int i = length - 1 ; i >= 0 ; i-- )
           reverse = reverse + original.charAt(i);
        if (original.equals(reverse))
           System.out.println("Palindrome, Original - "+ original+ " Reversed - " + reverse);
        else
          System.out.println("Not a Palindrome, Original - "+ original+ " Reversed - " + reverse);
}

}

Tuesday, 3 December 2013

WebDriver - List of classes which implements

WebDriver  is an interface to use for testing which represents web browser. Following is list of classes which implements WebDriver interface:

1.       AndroidDriver
2.       AndroidWebDriver
3.       ChromeDriver
4.       EventFiringWebDriver
5.       FirefoxDriver
6.       HtmlUnitDriver
7.       InternetExplorerDriver
8.       IPhoneDriver
9.       IPhoneSimulatorDriver
10.     RemoteWebDriver
11.     SafariDriver

How to handle java script alert using WebDriver

WebDriver supports handling  JavaScript alerts using Alert interface.

          // Bring control on already opened alert
               Alert alert = driver.switchTo().alert();

          // Get the text/message of the alert or prompt
               alert.getText(); 
         
         // Click ok button of alert
              alert.accept();

         // Click Cancel button of alert

              alert.dismiss();

Selenium - How to switch to Web Dialog window & back to Parent Browser Window

Steps are as follows -

           1.   Before clicking the link, get the handle id of the browser window.
                 String BrowserParent = driver.getWindowHandle();

           2. After clicking the link;
                 String str = driver.getWindowHandle();
                 driver.switchTo().window(st); // switch to child browser

           3.    Once the operation on the web dialog box is completed.    

                   driver.switchTo().window(BrowserParent);

Friday, 29 November 2013

Selenium TestNG - How to disable HTML Report Generation


Steps to disable TestNG default HTML Report generation is as follows - 
  1. Right Click on [Java Project] 
  2. Select [Properties] 
  3. Select [TestNG] 
  4. Select [Disable default Listeners]
  5. Click on [Ok] button
Note - This would work if you have installed TestNG as Eclipse plug-in.

How to read Operating System detail

 We can read operation system details using the Built in Environment Variable. Example -
         Platform = Environment ("OS")

         Msgbox Platform

What is Virtual Object

 Application Under Test (AUT) may contain objects that behave like standard objects but are not recognized by QTP. You can define these objects as virtual objects and map them to standard classes, such as a button or a check box. QTP emulates the user's action on the virtual object during the run session. In the test results, the virtual object is displayed as though it is a standard class object.
For example, suppose you want to record a test on a Web page containing a bitmap that the user clicks. The bitmap contains several different hyperlink areas, and each area opens a different destination page. When you record a test, the Web site matches the coordinates of the click on the bitmap and opens the destination page.
To enable QTP to click at the required coordinates during a run session, you can define a virtual object for an area of the bitmap, which includes those coordinates, and map it to the button class. When you run a test, QTP clicks the bitmap in the area defined as a virtual object so that the Web site opens the correct destination page.
You can define a virtual object using the Virtual Object Wizard Tools -> Virtual Objects > New Virtual Object. The wizard prompts you to select the standard object class to which you want to map the virtual object. You then mark the boundaries of the virtual object using a crosshairs pointer. Next, you select a test object as the parent of the virtual object. Finally, you specify a name and a collection for the virtual object. 

How will you call from one action to another action

HP QTP allows calling an action in 2 ways
1.  Call to copy of Action - The original action is copied in its entirety, including checkpoints, parameterization, the corresponding action tab in the Data Table, any defined action parameters, local object repository. The action is inserted into the test as an independent, non-reusable action (even if the original action was reusable). After the action is copied into your test, you can add to, delete from, or modify the action just as you would with any other non-reusable action. Any changes you make to this action after you insert it affect only this action, and changes you make to the original action do not affect the copied action. To view, Right-click & select Action > Insert Call to Copy.

2.    Call to Existing an Action - In this approach, a link is created to called Action. User can view the steps of the action in the action view, but you cannot modify them. The called action’s local object repository (if it has one) is also read-only. If the called external action has data in the Data Table, however, you can choose whether you want the data from the action’s data sheet to be imported as a local, editable copy, or whether you want to use the (read- only) data from the original action. (Columns and data from the called action’s global data sheet are always imported into the calling test as a local, editable copy.) To modify a called, external action, you must open the test with which the action is stored and make your modifications there. The modifications apply to all tests that call that action. If you chose to use the original action’s data when you call an external action, then changes to the original action’s data are applied as well. To view, Right-click & select Action > Insert Call to Existing Action.

Sunday, 24 November 2013

How does QTP identifies object

 HP QTP identifies any GUI Object based on its corresponding properties.  While recording, QTP identifies and store peculiar properties (as defined in the Object Identification settings) in the object repository of the GUI object. At run-time, QTP will compare the stored property values with the on-screen properties, to uniquely identify the GUI object.

What is Virtual Object

Application Under Test (AUT) may contain objects that behave like standard objects but are not recognized by QTP. You can define these objects as virtual objects and map them to standard classes, such as a button or a check box. QTP emulates the user's action on the virtual object during the run session. In the test results, the virtual object is displayed as though it is a standard class object.

For example, suppose you want to record a test on a Web page containing a bitmap that the user clicks. The bitmap contains several different hyperlink areas, and each area opens a different destination page. When you record a test, the Web site matches the coordinates of the click on the bitmap and opens the destination page.
To enable QTP to click at the required coordinates during a run session, you can define a virtual object for an area of the bitmap, which includes those coordinates, and map it to the button class. When you run a test, QTP clicks the bitmap in the area defined as a virtual object so that the Web site opens the correct destination page.

You can define a virtual object using the Virtual Object Wizard Tools -> Virtual Objects -> New Virtual Object. The wizard prompts you to select the standard object class to which you want to map the virtual object. You then mark the boundaries of the virtual object using a crosshairs pointer. Next, you select a test object as the parent of the virtual object. Finally, you specify a name and a collection for the virtual object. 
 

Tuesday, 19 November 2013

HP Quick Test Professional Supports 2 types of Object Repository


1.      Shared Object Repository (also called Global)

2.      Per-Action Object Repository, (also called Local)

What is Object Repository & their types in HP Quick Test Professional

Object Repository is a centralized place for storing Properties of objects available in AUT (Application Under Test). It is a test structure location where QuickTest stores object information/properties captured during recording. It acts as interface between test script and application in order to indentify the objects during script execution. The Object Repository can be used to:
·        Add a new object in the repository.
·        Rename logical name for readability.
·        Configure the object properties used to identify an object.
The Objects stored in the Object repository (OR) are called as Test Objects. Actually it is just equivalent to the corresponding actual object in AUT.

Object: It is a graphic user element in an application. It contains structure and properties. In QTP windows, WebPages, button, edit boxes, check boxes etc are termed as software object

Monday, 4 November 2013

Explain the HP QTP Tool interface

 HP QTP 11.0 contains the following key elements:
·   Title bar, displaying the name of the currently open test
·   Menu bar, displaying menus of QuickTest commands
·   File toolbar, containing buttons to assist you in managing tests
·   Test toolbar, containing buttons used while creating and maintaining tests
·   Debug toolbar, containing buttons used while debugging tests.

Note: The Debug toolbar is not displayed when you open QuickTest for the first time. You can display the Debug toolbar by choosing View > Toolbars > Debug.

·   Action toolbar, containing buttons and a list of actions, enabling you to view the details of an individual action or the entire test flow.

Note: The Action toolbar is not displayed when you open QuickTest for the first time. You can display the Action toolbar by choosing View > Toolbars > Action. If you insert a reusable or external action in a test, the Action toolbar is displayed automatically.

·  Test pane, containing two tabs to view your test-the Tree View and the Expert View Test Details pane, containing the Active Screen.
·  Data Table, containing two tabs, Global and Action, to assist you in Parameterzing your test Debug Viewer pane, containing three tabs to assist you in debugging your test-Watch Expressions, Variables, and Command. (The Debug Viewer pane can be opened only when a test run pauses at a breakpoint.)
·  Status bar, displaying the status of the test.

What is QTP testing process

QuickTest testing process consists of 7 main phases:
1.  Create your test plan - This is preparatory phase where you identify the exact test steps, test data and expected results for you automated test. You also identify the environment and system configurations required to create and run QTP Tests.
2.  Recording a session on your application - During this phase, you will execute test steps one by one on your AUT, and QTP will automatically record corresponding VB script statements for each step performed.
3. Enhancing your test - In this stage you will insert checkpoints, output values, parametrization  programming logic like if…else loops to enhance the logic of your test script.
4. Replay & Debug - After enhancements you will replay the script to check whether it’s working properly and debug if necessary.
5.  Run your Tests - In this phase you will perform the actual execution of your Test Script.
6.  Analysing the test results - Once test run is complete, you will analyse the results in the Test Fusion report generated.
7.  Reporting defects - Any incidents identified needs to be reported. If you are using Quality Centre, defects can be automatically raised for failed tests in QTP.

Wednesday, 30 October 2013

How to Install TestNG in Eclipse

  • Open Eclipse
  • Go to Help – Install New Software – Click Add
  • In Add Repository box, type TestNG and type the URL http://beust.com/eclipse
  • TestNG plugin will added into Available Software List.
  • Click on Next and follow the installation screen to complete the setup
  • Restart Eclipse and go to Run menu and open Run Configurations

Thursday, 24 October 2013

Hybrid (Keyword + Data) Framework using Selenium WebDriver, JXL API, Log4J

Selenium Test Framework is a test automation framework, is developed using WebDriver, JXL API, LOG4J and MS Excel. It has following features -

  1. Hybrid (Keyword + Data) Framework
  2. Firefox browser testing
  3. Data Driven testing using XLS file, write one test method against multiple test data sets
  4. Well defined Tear Down feature, which provides ability to continue with test execution even in test failures/application crash
  5. HTML Test Report
  6. Test Script creation in XLS File
Visit link https://drive.google.com/file/d/0BypxAnZwsvAcYlVCajhMME5paWs/viewDrop a message if you want to download framework code.



Wednesday, 2 October 2013

What is the difference between Browser and Page

Browser and Page are two different type of objects. A browser is a topmost level object for a website. and a page comes one level below it... One Browser object can have multiple pages inside it.

Monday, 23 September 2013

Capturing the Sub Menu values using Selenium Web Driver

This program opens url and prints all submenu of Home menu.

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class ReadSubMenu {

public static void main(String[] args) {
WebDriver driver = new FirefoxDriver(); //object created to start firefox driver

Actions action = new Actions(driver); // object created to perfomr mouse operation

driver.get("http://demo.lateralcode.com/css-drop-down-menus/"); // open url

WebElement home = driver.findElement(By.linkText("Home")); // find home menu

action.moveToElement(home).build().perform(); //put mouse pointer on Home menu

List we = home.findElements(By.xpath("//*[@id='menu']/ul/li[1]/ul/li")); // common property of all sub menu item

//travers through all submenu & print their text
for (int i =0; i
{
System.out.println(we.get(i).getText()); //print submenu text
}
 }

}

Tuesday, 17 September 2013

HP QTP :- What is the file extension of the script file and OR in QTP

In QuickTest Professional, File extension is as follows –

·        Per test object rep: filename.mtr
·        Shared Object rep: filename.tsr
·        Code file extension id: script.mts

Monday, 16 September 2013

Selenium : - Code to Login into drobbox.com

Code to Open dropbox.com & login is as follows - 

WebDriver driver; //declare object of WebDriver

driver = new FirefoxDriver(); //create object reference of Firefox driver

driver.get("http://dropbox.com"); //open dropbox.com

String parent = driver.getWindowHandle(); //read & store windows handle of parent browser

driver.findElement(By.linkText("Sign in")).click(); //click on Sing In link

//Switch to new window opened

for(String winHandle : driver.getWindowHandles()){ //iterate through all window open

   driver.switchTo().window(winHandle); //put focus to child browser window

}

driver.findElement(By.cssSelector("*[id='login_email']")).sendKeys("hello");//enter email

driver.findElement(By.cssSelector("*[id='login_password']")).sendKeys("hello"); //enter password

driver.findElement(By.name("login_submit_dummy")).click(); //click on Sign In button

driver.switchTo().window(parent); //return the control to parent browser

Friday, 13 September 2013

Selenium : How to switch to Web Dialog window & back to Parent Browser Window

Steps are as follows -

           1.  Before clicking the link, get the handle id of the browser window.
                  String BrowserParent = driver.getWindowHandle();

     2.  After clicking the link & once Web Dialog is opened
                 String str = driver.getWindowHandle();
                 driver.switchTo().window(st); // switch to child browser

     3.  Once the operation on the web dialog box is completed.    
                driver.switchTo().window(BrowserParent); //return back to Browser window

What is the use of desired capabilities

Selenium desired capabilities allows to set/change a lot of browser capabilities like cookies, profile, set proxy etc..


It helps to handle cookies, SSL certificate alerts, file upload/save(in Firefox) etc.

Thursday, 12 September 2013

JXL And POI, which api is better and why

  •      jxl does not support  XLSX files
  •      jxl exerts less load on memory as compared to ApachePOI
  •      jxl doesn't support rich text formatting while ApachePOI does.
  •      jxl has not been maintained properly while ApachePOI is more up to date.
  •      Sample code on Apache POI is easily avaialble

Wednesday, 11 September 2013

How to handle java script/error/exception alert using WebDriver

WebDriver would support handling js alerts using Alert interface.
         
          // Bring control on already opened alert
               Alert alert = driver.switchTo().alert();

          // Get the text/message of the alert or prompt
               alert.getText(); 
         
         // Click ok button of alert
              alert.accept();

         // Click Cancel button of alert
              alert.dismiss();

How to open Selenium IDE in Firefox

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

What are the technical issues with Selenium

Limitation of Selenium are as follows -

  1.      Very difficult to find good documentation
  2.      We cannot run scripts from step as we can do in QTP. SO script generation takes a lot of time
  3.      WebDriver doesn’t support safari and mac (as of now).
  4.      No documentation for Selenium Grid
  5.      Difficult to generate reports.
  6.      Password encryption is not possible.

Tuesday, 10 September 2013

QTP/UFT : Working with WebTable

QTP provides different methods to perform operation on WebTable.  This blog discusses about few of them -
How to check if  a WebTable exist
    msgbox Browser(…).page(…).webtable(…).exist ‘returns true/false
 How to find number of rows in WebTable
msgbox Browser(“").Page("").WebTable(“").RowCount  ‘ returns count of row in a           WebTable

How to find number of columns in a web table
    msgbox Browser("").Page("").WebTable(“").ColumnCount(1) ‘return column count in a 1st   
    row of WebTable

How to read data from a Cell WebTable
    msgbox Browser("").Page("").WebTable(“").GetCellData(row,column)
  ‘Where row & column specifies row number & column number of a Cell
How to find object using  childObject on a WebTable
 Set oDesc=Description.Create
 oDesc("micclass").value= WebCheckBox
 set oChild=Browser("").Page("").WebTable(“").ChildObjects(oDesc)
 msgbox oChild.count

How read data from WebTable using ChildItemCount and childItem
     oChild=Browser("").Page("").WebTable(“).ChildItemCount(row,col,” WebCheckBox”)
    If oChild >0
    Childitem will return object oftype defined in arguments for childitem
    Set cItem = Browser("").Page("").WebTable(“").ChildItem(row,col, WebCheckBox,0)
    If (strobjType = "Link" or strobjType ="WebEdit") Then
       cItem.Click
    ElseIf(stobjType = "WebCheckBox") Then
       cItem.Set "ON"
    End If
 

Friday, 6 September 2013

Which environments are supported by HP QTP

 QTP supports the following environments
  •         Active X
  •         Delphi
  •         Java
  •         .Net
  •         Oracle
  •         People Soft
  •         Power Builder
  •         SAP
  •         Siebel
  •         Stingray
  •         Terminal Emulator
  •         Visual Basic
  •         Visual Age
  •         Web
  •         Web Services