Apr 16, 2015

UFT Tutorial 36

UFT Class 36 (UFT Error Handling Part-1)
---------------------
Handling Expected and Unexpected Errors is called Error Handling.

Expected Errors:
------------------
Whenever we use invalid input then we can expect errors.

Why we need to use Invalid input?

We use invalid input for negative Testing.

Unexpected Errors:---------------------
i) Resource response:

ii) Insufficient Resource:

iii) Availability of the Resource:
etc...
--------------------------------------------
How to handle Errors?
i) Using Conditional Statements.

ii) Using some built in functions.

iii) Using Option Explicit statement

iv) Using Exit statement

v) Using On Error Resume Next statement

vi) Recovery Scenarios (UFT Tool feature)

Etc...
-------------------------------------------
i) Using Conditional Statements.
If Not Dialog("Login").Exist(3) Then
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
End If
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "abcd"
Dialog("Login").WinEdit("Password:").SetSecure "55305d8c4ad0885ad2cc27ad15a8a30755825bff"
Dialog("Login").WinButton("OK").Click
---------------------------------------------
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("text:=Login", "index:=0").Activate
Dialog("text:=Login", "index:=0").WinEdit("attached text:=Agent Name:").Set "abcd"
Dialog("text:=Login", "index:=0").WinEdit("attached text:=Password:").SetSecure "55305d8c4ad0885ad2cc27ad15a8a30755825bff"
Dialog("text:=Login", "index:=0").WinButton("text:=OK").Click
-------------------------------------------------------------
ii) Using some built in functions.
Dim a, b
a = InputBox ("Enter A value")
b = Inputbox("Enter B value")
Msgbox Cdbl (a) + Cdbl (b)
-------------------------------
Dim a, b
a = InputBox ("Enter A value")
b = Inputbox("Enter B value")

If IsNumeric(a) = True and IsNumeric(b) = True Then
    Msgbox Cdbl (a) + Cdbl (b)
    Else
    Msgbox "Invalid Input"
End If
-----------------------------------------
iii) Using Option Explicit statement
Option Explicit
Dim Tickets, Price, Total
Tickets = 7
Price = 100
Total = Tickets * Price
Msgbox Total
--------------------------------------
iv) Using Exit statement
For OrderNumer = 1 To 5 Step 1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set OrderNumer
wait 2
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

If Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Exist(3) Then
Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("OK").Click
Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click
Window("Flight Reservation").WinButton("Button_2").Click
Reporter.ReportEvent 3, "Res1", "Up to: "& OrderNumer-1 & " Orders only Exists"
Exit For
End If
Next
-------------------------------------
OrderNumer = 15
Do Until OrderNumer > 20
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set OrderNumer
wait 2
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

If Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Exist(3) Then
Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("OK").Click
Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click
Window("Flight Reservation").WinButton("Button_2").Click
Reporter.ReportEvent 3, "Res1", "Up to: "& OrderNumer-1 & " Orders only Exists"
Exit Do
End If
OrderNumer = OrderNumer + 1
Loop
----------------------------------------------------
v) Using On Error Resume Next statement
If any error is there, skip the error and continue the Execution.

> When to choose:

If there is no impact on final output then we can use On Error Resume Next statement.

> When not to choose:

If there is any impact on final output then don't use.
------------------------------------------------
On Error Resume Next
VbWindow("Form1").Activate
VbWindow("Form1").VbComboBox("Combo1").Select "Chennai"
VbWindow("Form1").VbComboBox("Combo1").Select "Goa"
VbWindow("Form1").VbComboBox("Combo1").Select "Hyderabad"
VbWindow("Form1").VbComboBox("Combo1").Select "New Delhi"
VbWindow("Form1").VbComboBox("Combo1").Select "Mumbai"
-------------------------------------------------
On Error Resume Next
Dim a, b, c
a =100
b-200
c= a + b
Msgbox a+b
-----------------------------------------
Recovery Scenarios:
What is Recovery Scenario?
It is scenario, makes UFT from abnormal state to normal during execution.
------------------------------------------
Why Recovery Scenarios?
During Test execution UFT may face some problems, if we provide Recovery Scenarios then UFT recovers from abnormal state to normal and continues its execution.
------------------------------------------------------
Trigger Events:
a) Popup window

b) Test Run error

c) Object state

d) Application Crash
-----------------
Recovery Operations:
i) Keyboard or Mouse operation

ii) Close Application Process

iii) Function call

iv) Restart MS Windows

Create New Recovery Scenario

Associate Recovery scenarios (Internal/External) (Test Level/Tool Level)

Edit Recovery Scenario (If required)

Delete Recovery Scenario (If required)
--------------------------------------------
Recovery Scenario is file
.qrs
---------------------------
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "55306afc407d5012934700380b861c5e3392bc19"
Dialog("Login").WinButton("OK").Click

If Window("Flight Reservation").Exist(10) Then
    Window("Flight Reservation").Close
    Result = "Login Successful - Passed"
    Else
    If Dialog("Login").Dialog("Flight Reservations").Exist(3) Then
    Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
    Dialog("Login").WinButton("Cancel").Click
    End If
    Result = "Login Successful - Failed"
End If
Msgbox Result
-------------------------------------------------------

Apr 15, 2015

UFT Tutorial 35

UFT Class 35 (Object Identification Configuration Part-2, UFT Tool settings configuration, Dictionary Object)
i) How to configure single object?
Open Object Repository

> Select Object

> Add Property and Value
---------------------------------
ii) How to maintain different configurations for same environment?
3 web Application

Steps:

First Configure Object Identification according to 1st Application

> generate Script and store

> Come back to default configuration and Configure Object Identification according to 2nd Application

> generate Script and store

.
.
------------------------
Whenever you want to execute tests on 1st application then execute 1st application
Script.
----------
Whenever you want to execute tests on 2nd application then execute 2nd application
Script.
.
.
-------------------------------------------
Tool settings configuration and globalize

i) What is globalizing tool settings?
Providing common configuration for all machines/computers in a project.
-----------------------------------
ii) Why globalize tool setting?
Since UFT is 1-tier /Stand-alone/desktop application we can't share settings
-------------------------------------------------------------
iii) How to globalize?
Using "Generate Script" feature we can globalize tool settings.
---------------------------------------------
UFT Tool settings:
i) File menu -> Settings

ii) Tools menu -> Object identification

iii) Tools menu -> Options
---------------------------------------------------
Virtual Object Configuration
 

What is Virtual Object Configuration?
It is a process of making an area or user defined as virtual object.

When we choose Virtual Object Configuration?
Suppose in our AUT, one area is there, UFT is not recognizing that area as object, then we can configure that area as object.

Virtual Object Configuration is related to Recording only.
----------------------------------------------------
Navigation for Virtual Object Configuration:
> Tools
> Virtual Object
> Virtual object manager
> Click New > Click Next
>Select Class of Object
>Next > Mark the Object
>Next > Next
> Enter Object name
> Finish
---------------------------
Ex:
VbWindow("Form1").VirtualButton("Submit").Click
-----------------------------------------------------
Dictionary Object
It is used define key, value pairs.

It is equilent to Associated Array in Perl script

VBScript        Perl
------------------------------
Scalar variables    Scalar
Array variable        Array
Dictionary Object    Associate Array/Hash variable
---------------------------------------
What is the difference between Array and Associate Array?

In case of Array Variables user can define values only, keys (indexes) are pre-defined.

In case of Associate Array (in Perl) or Dictionary Object(in VBscript, user can
define key and value pairs.
------------------
Array
Dim a(3)

a(0) = 10
a(1) = "India"
a(2) =#10/10/2010#
a(3) = 100

Keys Values
------------------------
We can use Dictionary items as Global variables

Example: 

Dim objDictionary
Set objDictionary = CreateObject("Scripting.Dictionary")
'Defining Key and items
objDictionary.Add 1, 100
objDictionary.Add "Agent", "Hyderabad"
objDictionary.Add "Password", "mercury"
objDictionary.Add "AppPath", "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
objDictionary.Add "*", "abc"
objDictionary.Add "d", #10/10/2010#

Msgbox objDictionary.Count '6

objDictionary.Remove(1)
Msgbox objDictionary.Count '5

Msgbox objDictionary.Exists("*") 'True
Msgbox objDictionary.Exists("a") 'False

objDictionary.RemoveAll
Msgbox objDictionary.Count '0
----------------------------------
UFT Test Example:

 'Dictionary items as Global Variables
SystemUtil.Run objDictionary("AppPath")
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set objDictionary("Agent")
Dialog("Login").WinEdit("Password:").Set objDictionary("Password")
wait 2
Dialog("Login").WinButton("OK").Click
----------------------------------------------

Apr 14, 2015

webdriver test cases

Selenium WebDriver Sample Test Case
--------------------------------------------------- 
Operating Environment: MS Windows

Programming Language: Java

IDE: Eclipse:
------------------------
WebDriver Environment Setup: 

---------------------------------------------------
> Download and Java (JDK) and Install

> Set Path Variable (Environment Variable)

> Download EClipse Software

> Download WebDriver Java Language Binding and Add WebDriver Jars to Java Project
in Eclipse

> Download and Install Firebug (As Firefox Browser Plug in)
(If we want use IE or Chrome browsers, no need to download any plug in, they have their own developer tools to inspect elements.)

> Download Internet Explorer and Chrome Drivers for WebDriver.

---------------------------------------------------
Write A Sample Test:


 > Launch EClipse IDE

> Create java Project

> Create Package

> Create Class and write Test/Program

---------------------------------------------------
 How to Write: 
---------------------------------------------------
 > Import WebDriver Libraries and Browser (Ex: Firefox) driver libraries.

> Create Driver Object

> Inspect Elements using Firebug for Firefox browser.

> Write Test using Element locators and WebDriver Methods.
-----------------------------------------------------------------
Note: WebDriver Methods and Web element locators are common for all Browsers.
 
---------------------------------------------------
 Create a Test for Gmail Login Functionality:
Steps:
i) Launch the Browser
ii) Navigate to Gmail home page
iii) Enter Email
iv) Enter Password
v) Click Sign In Button
---------------------------------
a) Test for Firefox Browser:

-----------------------------
package WebDriverTests;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class GmailLogin {
    public static void main(String [] args) throws InterruptedException {
        WebDriver driver = new FirefoxDriver();
        driver.get("http://gmail.com");
        driver.findElement(By.id("Email")).sendKeys("gcreddy123");
        driver.findElement(By.id("Passwd")).sendKeys("selenium123");
        driver.findElement(By.id("signIn")).click();
        Thread.sleep(10000);
        String Expected ="inbox";
        String URLTitle = driver.getCurrentUrl();
        if (URLTitle.contains(Expected)){
            System.out.println("Login Successful");
        }
            else{
                System.out.println("Login Failed");   
            }
            }
    }
-------------------------------------------------------
a) Test for Internet Explorer Browser:
package WebDriverTests;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class GmailLogin {
    public static void main(String [] args) throws InterruptedException {
        System.setProperty("webdriver.ie.driver", "d://IEDriverServer.exe");
        WebDriver driver = new InternetExplorerDriver();
        driver.get("http://gmail.com");
        driver.findElement(By.id("Email")).sendKeys("gcreddy123");
        driver.findElement(By.id("Passwd")).sendKeys("selenium123");
        driver.findElement(By.id("signIn")).click();
        Thread.sleep(10000);
        String Expected ="inbox";
        String URLTitle = driver.getCurrentUrl();
        if (URLTitle.contains(Expected)){
            System.out.println("Login Successful");
        }
            else{
                System.out.println("Login Failed");   
            }
            }
    }
---------------------------------------------------------
c) Test for Chrome Browser
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class GmailLogin {
    public static void main(String [] args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "d://chromeDriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("http://gmail.com");
        driver.findElement(By.id("Email")).sendKeys("gcreddy123");
        driver.findElement(By.id("Passwd")).sendKeys("selenium123");
        driver.findElement(By.id("signIn")).click();
        Thread.sleep(10000);
        String Expected ="inbox";
        String URLTitle = driver.getCurrentUrl();
        if (URLTitle.contains(Expected)){
            System.out.println("Login Successful");
        }
            else{
                System.out.println("Login Failed");   
            }
            }
    }
----------------------------------------------------------

Apr 12, 2015

Selenium WebDriver Tutorial

Selenium WebDriver

> It is a most important tool in Selenium Suite(Others are Selenium IDE, Selenium RC and Selenium Grid).

> It is an Interface (Programming Interface) allows us to execute tests
against different browsers (ex: Firefox, IE, Chrome etc...)

> WebDriver enables us to use different programming languages to create tests.

Java
.NET
PHP
Perl
Python
Ruby
---------------------------
WebDriver Environment Setup:

> Download and Install Java (on OS(Ex: Microsoft Windows))

> set path Environment variable

> Download and unzip Eclipse software

> Download WebDriver Java language binding and Add webDriver jar files (in EClipse)

> Install Firebug plug-in for Firefox Browser (Install on FireFox) to inspect Web elements.
---------------------------------------------------
Navigation to Add WebDriver Jar files in eclipse:
Create Java Project
> Select src and right click
> Build Path
> Configure Build Path
> Select Libraries tab
> Click on "Add External JARs
> Browse path of the webDriver jars
> Add
-----------------------------------
Pre-requisites to create Automated Tests:
-----------------------------------------
> Import WebDriver Libraries and Firefox driver library
    
> Create driver object

> Using web element (Object) locaters(properties) and Methods, write object call statements.

> Insert java programmatic statements to enhance tests.
---------------------------------------------------------- 

WebDriver Sample Programs:
1) Launch Firefox Browser, Navigate to Google home, Capture the Title and Display.
package WebDriverSample;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class GetBrowserTitle {
    public static void main(String [] args){
    WebDriver driver = new FirefoxDriver(); // Launches Firefox Browser with blank url
    driver.get("https://www.google.com"); // Navigates to the specified URL
    String Title = driver.getTitle();
    System.out.println(Title);
    driver.close(); // Closes the Browser
}
}
-------------------------------------------

2) Launch Firefox Browser, Navigate to Google home, Capture the Title and verify with expected:

package WebDriverSample;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class GetBrowserTitle {
    public static void main(String [] args){
    WebDriver driver = new FirefoxDriver(); // Launches Firefox Browser with blank url
    driver.get("https://www.google.com"); // Navigates to the specified URL
    String actual = driver.getTitle();
   
    if (actual.contentEquals("Google")){
        System.out.println("Test Passed");
    }
    else {
        System.out.println("Test Failed");
    }
    driver.close(); // Closes the Browser
}
}
----------------------------------------
3) Launch Google Home page and click on Gmail link
package WebDriverSample;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class GetBrowserTitle {
    public static void main(String [] args){
    WebDriver driver = new FirefoxDriver(); // Launches Firefox Browser with blank url
    driver.get("https://www.google.com");
    driver.findElement(By.linkText("Gmail")).click();
    //driver.close(); // Closes the Browser
}
}
--------------------------------------------------------
4) Gmail Login

/* Gmail Login
 * Steps:
 * i) Launch the Browser
 * ii) Navigate to Gmail Home page
 * iii) Enter Email
 * iv) Enter Password
 * v) Click on Sign in
 */
//---------------------------------------------
package WebDriverSample;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class GmailLogin{
    public static void main (String []args){
        WebDriver abcd = new FirefoxDriver(); //i) Launch the Browser
        abcd.get("http:/www.gmail.com"); //ii) Navigate to Gmail Home page
        abcd.findElement(By.id("Email")).sendKeys("gcreddy123"); //Locating Email edit box and entering a value
        abcd.findElement(By.name("Passwd")).sendKeys("selenium123");//Locating Password edit box and entering a value
        abcd.findElement(By.id("signIn")).click(); //Click on Sign in
            }
}
------------------------------------------------
Selenium     UFT
Element -    Object
Locater        Property
--------------------------
// Close Browser

UFT:
'Close the Bower
Browser("title:=Google").Close

'Enter a Value into Edit box
Browser("title:=Google").Page("title:=Google").WebEdit("name:Email").Set "gcrindia"
-------------------------------------------
Selenium:

driver.close();
driver.findElement(By.id("Email")).sendKeys("gcrindia");

abcd.findElement(By.id("signIn")).click();
-------------------------------------------

Apr 8, 2015

UFT Tutorial 34

UFT Class 34 (Object Identification Configuration)

Test design in UFT:
    Object Repository based Test Design
    Descriptive Programming

> Object Identification Configuration feature is related to
Object Repository based Test Design only.

> What is Object Identification Configuration?

Configuring important properties information for Objects to recognize them uniquely.

> Why Object Identification Configuration?
Generally 20 to 20 properties available for every software object, using that complete information recognizing objects is time taking process.
Some objects properties values may change dynamically.

Ex:

Environment: Standard Windows

Object is: Window

Property: window id

Property value:

1st time: 132303

2nd time: 1573653
------------------------------------
> When Object Identification Configuration is required?

Scenario 1:
We are using Descriptive programming for Test design-Not required.

Scenario 2:
(UFT has default configuration for every environment, that default configuration based on UI design standards.)

We are using Object Repository based Test design and development followed UI design standards- Not required.

Scenario 3:
We are using Object Repository based Test design and development Not followed UI design standards- Required.
---------------------------
How to know if the Development team is following UI design standards or not?
By Record and Playback.
-------------------------------------
Object Identification Configuration is:

Environment Level:
Ex: Standard Windows

Test Object Class Level
Ex: WinButton

Ex: If we configure Button object in Standard windows environment that configuration is applicable for all Buttons in our standard windows application.
-----------------------
Object Identification:

Normal Identification
    a) Mandatory properties
        native class
        text
   
    b) Assistive properties
        height
        width

Smart Identification (Optional)
    a) Base filter properties
    b) Optional filter properties


Ordinal Identifier(Index)
    Index (0, 1, 2, 3....)
    Location (0, 1, 2, 3....)
    CreationTime (Only for Browser)
   
---------------------------------
i) Normal Identification process:

During learning (Recording is learning or Add objects is learning) UFT
1st reads all mandatory properties at a time and thinks weather that information is sufficient or not to recognize the object uniquely, if it feels sufficient stops learning and stores that information, otherwise it goes to Assistive properties and learn properties one by one, if it feels sufficient, then stops learning and stores that information(Mandatory + Assistive).

After learning all Mandatory and Assistive properties still it feels not sufficient, finally it goes to Ordinal identifier.

Either index or Location is unique for this version, no guaranty for next versions.
--------------------------------------------------
Environment: Standard windows
Test object Classes
Ex:
Window
Dialog
WinButton
WinEdit
etc...
-------------------------
WinButton: Smart Identification
100 buttons

60 buttons -Mandatory properties
30 buttons -Mandatory + Assistive properties
8 buttons - Smart Identification properties   
-------
2 Ordinal Identifier
----------------------------
ii) Smart Identification process: (Normal + Smart Identification)

During learning (Recording is learning or Add objects is learning) UFT
1st reads all mandatory properties at a time and thinks weather that information is sufficient or not to recognize the object uniquely, if it feels sufficient stops learning and stores that information, otherwise it goes to Assistive properties and learn properties one by one, if it feels sufficient stops learning and stores that information(Mandatory + Assistive).

 After learning all Mandatory and Assistive properties still it feels not sufficient, then It goes to Base filter properties and learns all Base filter properties at a time and thinks that info is sufficient or not?  Otherwise it goes to Optional filter properties and learns properties one by one.

After learning all Mandatory, Assistive, Base filter, and Optional filter properties still it feels not sufficient, finally it goes to Ordinal identifier.
--------------------------------------------
Normal Identification:
    Mandatory Properties
    Assistive Properties
------
Ordinal Identifier
------------------------------
Smart Identification
    Mandatory Properties
    Assistive Properties
    Base filter Properties
    Optional filter Properties
------
Ordinal Identifier
------------------------------
Come back to default configuration:
Reset Test object - It resets selected Test object class only.

Reset Environment - It resets selected Environment only.

Reset All - It resets all loaded environments.
-------------------------------------------
> Configuring Single object

> Maintain different configurations for same environment.

Apr 7, 2015

UFT Tutorial 33

UFT Class 33 (Debugging Tests, Database Objects and VBScript Examples)

What is Debugging?

Locating and isolating errors thru Step by step execution.

Debugging is optional.

When Debugging is required?

Whenever Test is not showing any errors and not providing correct output.

How to debug?
Using VBScript debug commands and breakpoints.

i) Step into (F11)
    a) It starts the execution
    b) It executes one statement at a time.
    c) If it is function call, it opens the function and executes one function statement at a time.
-------------------------
ii) Step over (F10)
    a) It executes one statement at a time.
    b) It executes all functions statement at a time.

iii) Step out (Shift + F11)
------------
    a) It executes all remaining function statements at a time

Breakpoint (F9)

Types of Test Execution:

i) At a time execution (using Run Command)

ii) Step by step execution (Using Debug commands)

iii) Hybrid execution (Using Run command, debug commands and Breakpoints)
------------------------
Ex:
Dim a, b, c
a = 10
b = 20
c = a + b
a = 5
b = 3
c = a ^ b
Call Login("abcd", "mercury")
a = 10
b = 20
c = a - b
a = 5
b = 3
c = a * b
a=100
------------------------------
Database Objects
-----------------
i) Database Connection Object

It is used to connect to a Database (any database)

Create Database Connection Object:

Set Variable = CreateObject("Adodb.Connection")
------------------
ii) Database Recordset Object
It is used to perform operations on database tables.

Create Database Recordset Object:

Set variable = CreateObject("Adodb.Recordset")
-------------------------------------
Generate Connection String for MS Access Database:
Launch Notepad -> Save as udl file -> Click on udl File
-> Select database as MS Access-> OK

Open the File with Note Pad -> get the connection string

Examples:
------------
'Read Test data from a database and perform Data driven Testing for Login operation
Dim objConnection, objRecordset
Set objConnection = CreateObject("Adodb.Connection")
Set objRecordset = CreateObject("Adodb.Recordset")

'Create Connection String for MS Access Database
objConnection.Provider =("Microsoft.ACE.OLEDB.12.0")
objConnection.Open ("C:\Users\G C Reddy\Desktop\testdb.accdb")
objRecordset.Open "Select Agent, Password from Login", objConnection

Do Until objRecordset.EOF = True
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe”
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set objRecordset.Fields("Agent")
Dialog("Login").WinEdit("Password:").Set objRecordset.Fields("Password")
Wait 2
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
objRecordset.MoveNext
Loop
objRecordset.Close
objConnection.Close

Set objRecordset = Nothing
Set objConnection = Nothing
--------------------------------------------
i) Export data from a database to an excel file
Dim objConnection, objRecordset, objExcel, objWorkbook, objWorksheet
Set objConnection = CreateObject("Adodb.Connection")
Set objRecordset = CreateObject("Adodb.Recordset")

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\abc.xlsx")
Set objWorksheet = objWorkbook.Worksheets(1)

objConnection.Provider = ("Microsoft.ACE.OLEDB.12.0")
objConnection.Open "C:\Users\G C Reddy\Desktop\testdb.accdb"
objRecordset.Open "Select Agent, Password from Login", objConnection

objWorksheet.Cells(1, 1) = "Agent"
objWorksheet.Cells(1, 2) = "Password"
i = 2
Do Until objRecordset.EOF = True
objWorksheet.Cells(i, 1) = objRecordset.Fields("Agent")
objWorksheet.Cells(i, 2) = objRecordset.Fields("Password")
objRecordset.MoveNext
i= i+ 1
Loop
objWorkbook.Save
objExcel.Quit
objRecordset.Close
objConnection.Close
Set objWorksheet= Nothing
Set objWorkbook= Nothing
Set objExcel= Nothing

Set objRecordset= Nothing
Set objConnection= Nothing
-------------------------------------------------------
ii) Export data from a database to a text file.
Dim objConnection, objRecordset, objFso, objTextstream
Set objConnection = CreateObject("Adodb.Connection")
Set objRecordset = CreateObject("Adodb.Recordset")

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objfso.OpenTextFile("C:\Users\G C Reddy\Desktop\xyz.txt", 2)

objConnection.Provider = ("Microsoft.ACE.OLEDB.12.0")
objConnection.Open "C:\Users\G C Reddy\Desktop\testdb.accdb"
objRecordset.Open "Select Agent, Password from Login", objConnection

objTextstream.WriteLine "Agent Password"

Do Until objRecordset.EOF = True
objTextstream.WriteLine  objRecordset.Fields("Agent") &", "& objRecordset.Fields("Password")
objRecordset.MoveNext
Loop
objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
objRecordset.Close
objConnection.Close
Set objRecordset= Nothing
Set objConnection= Nothing
---------------------------------------
iii) Export data from an excel file to a text file
Dim objFso, objTextstream, objExcel, objWorkbook, objWorksheet, RowCount
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\abc.xlsx")
Set objWorksheet = objWorkbook.Worksheets(1)

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objfso.OpenTextFile("C:\Users\G C Reddy\Desktop\xyz.txt", 2)

RowCount= objWorksheet.UsedRange.Rows.Count
objTextstream.WriteLine "Agent Password"
For i = 2 To RowCount Step 1
    objTextstream.WriteLine objWorksheet.Cells(i, 1) &", "& objWorksheet.Cells(i, 2)
Next

objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing

objExcel.Quit
Set objWorksheet= Nothing
Set objWorkbook= Nothing
Set objExcel= Nothing
----------------------------------------------
iv) export data from a text file to an excel file.
--------------------------------------------
Dim objFso, objTextstream, objExcel, objWorkbook, objWorksheet
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\abc.xlsx")
Set objWorksheet = objWorkbook.Worksheets(1)

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objfso.OpenTextFile("C:\Users\G C Reddy\Desktop\xyz.txt")
objTextstream.SkipLine
objWorksheet.Cells(1, 1) = "Agent"
objWorksheet.Cells(1, 2) = "Password"
i = 2
Do While objTextstream.AtEndOfStream = False
    myLine = objTextstream.ReadLine
    myField = Split(myLine, ", ")
    objWorksheet.Cells(i, 1) = myField(0)
    objWorksheet.Cells(i, 2) = myField(1)
    i = i + 1
Loop

objWorkbook.Save
objExcel.Quit
Set objWorksheet= Nothing
Set objWorkbook= Nothing
Set objExcel= Nothing

objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
-----------------------------------------
Assignments:
i) Export data from Excel file to database

ii) Export data from Text file to database
-------------------------------------------

Apr 6, 2015

io and file handling in Java

I/O and File Handling in Java.
 

There are three ways available for reading input:
i) Scanner

ii) DataInputStream

iii) BufferedReader
---------------
Using java.util.Scanner is the easier and includes many methods to check input data is valid to read.

Example:---------------
package javaiooperations;
import java.util.Scanner;
public class ReadInput {
public static void main(String [] args){
    Scanner scan = new Scanner(System.in);
   
    System.out.println("Enter Your Name");
    String s1 = scan.nextLine();
    System.out.println("Your Name is: " + s1);
   
    System.out.println("Enter Your City Name");
    String s2 = scan.next();
    System.out.println("Your City Name is: " + s2);
   
    System.out.println("Enter Your Number");
    int a = scan.nextInt();
    System.out.println("Your Number is: " + a);
   
    System.out.println("Enter Your City Name");
    double b = scan.nextDouble();
    System.out.println("Value is: " + b);
    scan.close();
}
}
-------------------------------------------
File handling in Java----------------------
Two categories of File System Operations

i) High level operations / External operations

Create a folder

delete a folder

create a text file

delete a text file etc...

ii) Low level operations / Internal operations

Read data

Write data etc...
------------------------
Using File Class we can perform High level operations
Examples:
1) Create a Folder
package javaiooperations;

import java.io.File;

public class CreateFolder {
   
    public static void main(String [] args){
        File fileObject = new File("C:/Users/G C Reddy/Desktop/Selenium");
        fileObject.mkdir();
        }
}
---------------------------------
2) Check the existence of Selenium Folderpublic static void main(String [] args){
        File fileObject = new File("C:/Users/G C Reddy/Desktop/UFT");
        boolean a = fileObject.exists();
        System.out.println(a);
        }
-------------------------------------
3) Delete a Folder
public static void main(String [] args){
        File abc = new File ("C:/Users/G C Reddy/Desktop/Selenium");
        abc.delete();
        boolean a = abc.exists();
        //System.out.println(a);
        if (a == true) {
            System.out.println("Folder exists");
        }
        else{
            System.out.println("Folder doesn't exist");   
        }
        }
-----------------------------------
4) Create a Text file
public class CreateFolder {
   
    public static void main(String [] args){
        File abc = new File ("C:/Users/G C Reddy/Desktop/Selenium.txt");
        try {
            abc.createNewFile();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
-------------------------------------------
5) Delete a text file    public static void main(String [] args){
        File abc = new File ("C:/Users/G C Reddy/Desktop/Selenium.txt");
        abc.delete();
       
    }
------------------------------------      

UFT Tutorial 32

UFT Class 32 (Batch Testing/ Batch Execution)
----------------------------
Batch Testing:


Executing series of Tests

> It is one of the advantages of Test Automation, In Manual Testing for each and every Test case execution human user interaction is mandatory. If It is automation Test Tool can execute series of tests without user interaction.

They are four ways for batch testing in UFT:

i) Using "Test Batch Runner" tool

ii) Using AOM(Automation Object Model) Script.

iii) Using Driver script in Automation framework.

iv) Using QC/ALM tool
---------------------------------------------------
Steps of Batch Testing Using "Test Batch Runner" tool:

a) Create basic tests and run them once.

b) Launch "Test Batch Runner" Tool and create Test batches.

c) Provide permission to "Test Batch Runner" Tool to execute tests and components.

d) Run the Test Batch.
----------------------------
Note: "Test Batch Runner" Tool doesn't provide batch wise Result.

Note 2: "Test Batch Runner" Tool can execute entire Test batch or part of the Test batch.
-----------------------------------
Navigation to Provide permission to "Test Batch Runner" Tool:

Tools menu -> Options -> GUI Testing -> Test Runs ->
Select "Allow other HP products to Run tests and components -> OK
---------------------------------------
Test Batch execution process:
---------------------------
Test batch Runner tool launches UFT tool and provides instructions,
UFT only executes Tests one by one based on "Test batch Runner" instructions.
-------------------------------
ii) Using AOM(Automation Object Model) Script.
---------------------------------------
Automation Object model is a private object model.

Usage of VBScript:
    i) Client side scripting in the web
    ii) Server side scripting in the web
    iii) Network Administration
    iv) System Administration
    v) Test Automation etc...

Global object models (ex: Filesystem object model, Excel object model and Database object models)
for all types of Scripting,

AOM (QTP Application object) is a Private object model, it is only for
UFT Test Automation.
------------------------

QTP Application object is used to automate UFT tool operations.

Create QTP Application object:

Set Variable = CreateObject("QuickTest.Application")
----------------
Note: Don't run AOM scripts from UFT tool editor,
AOM is not UFT test script, It is VBScript file.

> You can create AOM script in UFT tool editor for getting context help.

Otherwise open notepad, write the code and save as .vbs file

Example (Batch Testing using QTP Application Object):
Dim objQTP
'Create QTP Application Object, it is used to automate UFT tool operations
Set objQTP = CreateObject("QuickTest.Application")
objQTP.Visible = True 'To view the UFT tool during execution.

objQTP.Launch 'To launch UFT Tool.

objQTP.Open "C:\Users\G C Reddy\Desktop\Tests\Login"
objQTP.Test.Run 'To run the Test
objQTP.Test.Close 'To close the Test

objQTP.Open "C:\Users\G C Reddy\Desktop\Tests\OpenOrder"
objQTP.Test.Run 'To run the Test
objQTP.Test.Close 'To close the Test

objQTP.Open "C:\Users\G C Reddy\Desktop\Tests\FaxOrder"
objQTP.Test.Run 'To run the Test
objQTP.Test.Close 'To close the Test

objQTP.Quit 'To close UFT Tool
Set objQTP = Nothing 'To release the memory.
----------------------------------------------
Batch Testing using AOM,

Read Test paths from a text file and execute using Loop statements.
Dim objFSO, objTextstream, objQTP, TestPath
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objFSO.OpenTextFile("C:\Users\G C Reddy\Desktop\testpaths.txt")

Set objQTP = CreateObject("QuickTest.Application")
objQTP.Launch

Do Until objTextstream.AtEndOfStream = True
TestPath= objTextstream.ReadLine
objQTP.Open TestPath
objQTP.Test.Run
objQTP.Test.Close
Loop

objQTP.Quit
objTextstream.Close
Set objTextstream = Nothing
Set objFSO = Nothing
----------------------------------------
Debugging Tests

What is Debugging?

Locating and Isolating Errors thru Step by Step execution

Application Life Cycle
--------------------------
Development phase    Testing phase        Production phase
-----------------------------------------------------------------
Error            Defect            Failure
Mistake            Bug
            Fault
-----------------------------------------------------------
When Debugging Tests is required?
Debugging is optional in UFT Test Automation,

Scenario 1:
Test is not showing any errors and providing correct output - Not required.

Scenario 2:
Test is showing errors -Debugging is optional

Scenario 3:
Test is not showing any errors and Not providing correct output - Debugging is required.

x = a * b


How to Debug Tests?

Apr 1, 2015

UFT Tutorial 31

UFT Class 31 (VBScript Excel Application Operations Part-2)
--------------------------------------
Excel Application Object (Main Object)

Set Variable = CreateObject("Excel.Application")
------------------------------------
Excel Workbook Object (Sub Object)

Set Variable = ExcelApplicationObject.Workbooks.Add/Open("File path")
--------------------------------------------
Excel Work sheet object (Sub-sub Object)

Set Variable = ExcelWorkBookObject.Worksheets(Sheet id)
--------------------------------------------------------
Examples:
'Read data from an excel file and perform data driven testing for login functionality.
Dim objExcel, objWorkbook, objWorksheet, RowsCount
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\testdata.xlsx")
Set objWorksheet = objWorkbook.Worksheets(1)

RowsCount = objWorksheet.UsedRange.Rows.Count

For i = 2 To RowsCount Step 1
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set objWorksheet.Cells(i, 1)
Dialog("Login").WinEdit("Password:").Set objWorksheet.Cells(i, 2)
Wait 2
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
Next

objExcel.Quit
Set objWorksheet= Nothing
Set objWorkbook= Nothing
Set objExcel= Nothing
------------------------------------------
'Read data from an excel file and perform data driven testing for login functionality.
Dim objExcel, objWorkbook, objWorksheet, RowsCount
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\testdata.xlsx")
Set objWorksheet = objWorkbook.Worksheets(1)

RowsCount = objWorksheet.UsedRange.Rows.Count

For i = 2 To RowsCount Step 1
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").Activate @@ hightlight id_;_459804_;_script infofile_;_ZIP::ssf1.xml_;_
Dialog("Login").WinEdit("Agent Name:").Set objWorksheet.Cells(i, 1)
Dialog("Login").WinEdit("Password:").Set objWorksheet.Cells(i, 2)
Wait 2
Dialog("Login").WinButton("OK").Click

If Window("Flight Reservation").Exist(12) Then
    Window("Flight Reservation").Close
    objWorksheet.Cells(i, 3) = "Login Successful - Passed"
    Else
    SystemUtil.CloseDescendentProcesses
    objWorksheet.Cells(i, 3) = "Login Unsuccessful - Failed"
End If
Next
objWorkbook.Save
objExcel.Quit
Set objWorksheet= Nothing
Set objWorkbook= Nothing
Set objExcel= Nothing
--------------------------------------------
'Read data from an excel file and perform data driven testing for login functionality.
Dim objExcel, objWorkbook, objWorksheet, RowsCount
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\testdata.xlsx")
Set objWorksheet = objWorkbook.Worksheets(1)

RowsCount = objWorksheet.UsedRange.Rows.Count

For i = 2 To RowsCount Step 1
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set objWorksheet.Cells(i, 1)
Dialog("Login").WinEdit("Password:").Set objWorksheet.Cells(i, 2)
Wait 2
Dialog("Login").WinButton("OK").Click

If Window("Flight Reservation").Exist(12) Then
    Window("Flight Reservation").Close
    objWorksheet.Cells(i, 3) = "Login Successful - Passed"
    Else
objWorksheet.Cells(i, 4) = Dialog("Login").Dialog("Flight Reservations").Static("Please enter password").GetROProperty("text")
    SystemUtil.CloseDescendentProcesses
    objWorksheet.Cells(i, 3) = "Login Unsuccessful - Failed"
End If
Next
objWorkbook.Save
objExcel.Quit
Set objWorksheet= Nothing
Set objWorkbook= Nothing
Set objExcel= Nothing
-------------------------------------------
'Read Button Names from Login Dialog and export to excel file 2nd sheet.
Dim objExcel, objWorkbook, objWorksheet, oButton, Buttons, i
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\testdata.xlsx")
Set objWorksheet = objWorkbook.Worksheets(2)

Set oButton = Description.Create
oButton("Class Name").Value = "WinButton"

Set Buttons= Dialog("Login").ChildObjects(oButton)
Msgbox Buttons.Count

objWorksheet.Cells(1, 1) = "Button Names"
For i = 0 To Buttons.Count - 1 Step 1
    objWorksheet.Cells(i+2, 1) = Buttons(i).GetRoProperty("text")
Next
objWorkbook.Save
objExcel.Quit
Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set objExcel = Nothing
--------------------------------------------
'Open 1 to 10 Orders, capture OrderNo and Customer names, export to excel file 3rd sheet.
Dim objExcel, objWorkbook, objWorksheet, oButton, Buttons, i
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\testdata.xlsx")
Set objWorksheet = objWorkbook.Worksheets(3)
objWorksheet.Cells(1, 1) = "Order No"
objWorksheet.Cells(1, 2) = "C_Name"

For i = 1 To 10 Step 1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set i
wait 2
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
OrderNo = Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")
C_Name = Window("Flight Reservation").WinEdit("Name:").GetROProperty("text")

objWorksheet.Cells(i+1, 1) = OrderNo
objWorksheet.Cells(i+1, 2) = C_Name
Next
objWorkbook.Save
objExcel.Quit
Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set objExcel = Nothing
----------------------------------
Comparison Examples:

i) One to One Binary comparison

ii) One to One Textual comparison

iii) Many to many comparison
----------------------------------------
'One to One Comparison
'Working with multiple excel files

Dim objExcel, objWorkbook1, objWorkbook2, objWorksheet1, objWorksheet2
Dim RowsCount, i, Expected, Actual
Set objExcel = CreateObject("Excel.Application")

Set objWorkbook1 = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\abc.xlsx")
Set objWorkbook2 = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\xyz.xlsx")

Set objWorksheet1 = objWorkbook1.Worksheets(1)
Set objWorksheet2 = objWorkbook2.Worksheets(1)

RowsCount = objWorksheet1.UsedRange.Rows.Count
For i = 2 To RowsCount Step 1
    Expected = objWorksheet1.Cells(i, 1)
    Actual = objWorksheet2.Cells(i, 1)
   
    If Expected = Actual Then
        objWorksheet2.Cells(i, 2)= "Passed"
        Else
        objWorksheet2.Cells(i, 2)= "Failed"
    End If
Next
objWorkbook2.Save
objExcel.Quit

Set objWorksheet2= Nothing
Set objWorksheet1= Nothing
Set objWorkbook2= Nothing
Set objWorkbook1= Nothing
Set objExcel= Nothing
-----------------------------------
'One to One Textual Comparison
'Working with multiple excel files
Dim objExcel, objWorkbook1, objWorkbook2, objWorksheet1, objWorksheet2
Dim RowsCount, i, Expected, Actual
Set objExcel = CreateObject("Excel.Application")

Set objWorkbook1 = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\abc.xlsx")
Set objWorkbook2 = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\xyz.xlsx")

Set objWorksheet1 = objWorkbook1.Worksheets(1)
Set objWorksheet2 = objWorkbook2.Worksheets(1)

RowsCount = objWorksheet1.UsedRange.Rows.Count
For i = 2 To RowsCount Step 1
    Expected = objWorksheet1.Cells(i, 1)
    Actual = objWorksheet2.Cells(i, 1)
   
    If StrComp(Expected, Actual, 1) = 0 Then
        objWorksheet2.Cells(i, 2)= "Passed"
        Else
        objWorksheet2.Cells(i, 2)= "Failed"
    End If
Next
objWorkbook2.Save
objExcel.Quit

Set objWorksheet2= Nothing
Set objWorksheet1= Nothing
Set objWorkbook2= Nothing
Set objWorkbook1= Nothing
Set objExcel= Nothing
----------------------------------------
'Many to many Textual Comparison
'Working with multiple excel files
Dim objExcel, objWorkbook1, objWorkbook2, objWorksheet1, objWorksheet2
Dim RowsCount, i, Expected, Actual
Set objExcel = CreateObject("Excel.Application")

Set objWorkbook1 = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\abc.xlsx")
Set objWorkbook2 = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\xyz.xlsx")

Set objWorksheet1 = objWorkbook1.Worksheets(1)
Set objWorksheet2 = objWorkbook2.Worksheets(1)

RowsCount = objWorksheet1.UsedRange.Rows.Count
Flag = 0
For i = 2 To RowsCount Step 1
    Expected = objWorksheet1.Cells(i, 1)
   
    For j = 2 To RowsCount Step 1
    Actual = objWorksheet2.Cells(j, 1)
If StrComp(Expected, Actual, 1) = 0  Then
    Flag = 1
    Exit for
    Else
    Flag = 0
End If   
    Next
If Flag = 1 Then
        objWorksheet2.Cells(i, 2)= "Passed"
        Else
        objWorksheet2.Cells(i, 2)= "Failed"
    End If       
Next
objWorkbook2.Save
objExcel.Quit

Set objWorksheet2= Nothing
Set objWorksheet1= Nothing
Set objWorkbook2= Nothing
Set objWorkbook1= Nothing
Set objExcel= Nothing
--------------------------------------------------
'Create an Excel file and Add one more sheet
Dim objExcel
Set objExcel = CreateObject("Excel.Application")
objexcel.Visible = True 'To view the operation while execution
objExcel.Workbooks.Add 'Create New file
objExcel.Worksheets.Add 'Create New sheet

objExcel.ActiveWorkbook.SaveAs "C:\Users\G C Reddy\Desktop\UFT.xlsx"

objExcel.Quit 'To close Excel Application
Set objExcel = Nothing 'To release the memory.
--------------------------------------------------
Assignment:
-------------
Create an excel file and move 1st sheet to 3rd position.
---------------------------------------------------
'Create an Excel file and rename 1st sheet as "Module", 2nd sheet as "TestCase" and 3rd sheet as "TestStep".

Dim objExcel
Set objExcel = CreateObject("Excel.Application")
objexcel.Visible = True
objExcel.Workbooks.Add

objExcel.Worksheets(1).Name = "Module"
objExcel.Worksheets(2).Name = "TestCase"
objExcel.Worksheets(3).Name = "TestStep"

objExcel.ActiveWorkbook.SaveAs "C:\Users\G C Reddy\Desktop\UFT2.xlsx"

objExcel.Quit
Set objExcel = Nothing
-------------------------------------------------------
Batch Testing / Batch Execution
------------------------------
Executing series of Tests is called batch testing

There are 4 ways for batch Testing in UFT:

i) Using "Test Batch Runner" tool

ii) Using AOM (Automation Object Model) script

iii) Using Driver script in automation framework

iv) Using ALM/QC tool
----------------------------------
Steps for Batch Testing Using "Test Batch Runner" tool:

i) Create basic tests and run them once

ii) Launch "Test Batch Runner" and create Test batches.

iii) provide permission to "Test Batch Runner" to execute tests.

iv) Run test batches
------------------------------

Mar 31, 2015

UFT Tutorial 30

UFT Class 30 (VBScript File System Operations Part-2, Excel Object Model Part-1)
--------------------------------------
'Read Test Data from a Text file and perform Data Driven Testing for Login Functionality.
Dim objFso, objTextstream, myLine, myField
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objFso.OpenTextFile("C:\Users\G C Reddy\Desktop\UFT.txt")
objTextstream.SkipLine

Do Until objTextstream.AtEndOfStream = True
myLine = objTextstream.ReadLine
myField = Split(myLine, ", ")

SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe”
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set myField(0)
Dialog("Login").WinEdit("Password:").Set myField(1)
wait 2
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close   
Loop

objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
--------------------------------------------
'Read Test Data (from 4 to 7 Records) from a Text file and perform Data Driven Testing for Login Functionality.
Dim objFso, objTextstream, myLine, myField, LineCount
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objFso.OpenTextFile("C:\Users\G C Reddy\Desktop\UFT.txt")

LineCount= 0
Do Until objTextstream.AtEndOfStream = True
myLine = objTextstream.ReadLine
LineCount = LineCount + 1

If LineCount  > 4 And LineCount <= 8 Then
myField = Split(myLine, ", ")

SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe”
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set myField(0)
Dialog("Login").WinEdit("Password:").Set myField(1)
wait 2
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
End If
Loop

objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
------------------------------------------------------
'Write Data to a Text file
Dim objFso, objTextstream, num1, num2, result
num1 = 100 : num2= 200 : result = num1 + num2
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objFso.OpenTextFile("C:\Users\G C Reddy\Desktop\UFT.txt", 2)
objTextstream.Write "Addition of num1, num2 is: "& result
objTextstream.Write "Subtraction of num1, num2 is: "& num1 - num2

objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
------------------------------------
'Write Data (Line by Line) to a Text file
Dim objFso, objTextstream, num1, num2, result
num1 = 100 : num2= 200 : result = num1 + num2
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objFso.OpenTextFile("C:\Users\G C Reddy\Desktop\UFT.txt", 2)
objTextstream.WriteLine "Addition of num1, num2 is: "& result
objTextstream.WriteLine "Subtraction of num1, num2 is: "& num1 - num2

objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
---------------------------------
'Write Data (Append) to a Text file
Dim objFso, objTextstream, num1, num2, result
num1 = 500 : num2= 400 : result = num1 + num2
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objFso.OpenTextFile("C:\Users\G C Reddy\Desktop\UFT.txt", 8)
objTextstream.WriteLine "Addition of num1, num2 is: "& result

objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
------------------------------------------
'Open 1 to 10 Orders and Read Order Number and Customer name
'Export to a Text file

Dim objFso, objTextstream, num1, num2, result
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objFso.OpenTextFile("C:\Users\G C Reddy\Desktop\UFT.txt", 2)
'Login to Application (One time)
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe”
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "551b4bf7c618d4eede8b4426aa921e65623e0a6d"
Dialog("Login").WinButton("OK").Click
objTextstream.WriteLine "Order_No C_Name"
objTextstream.WriteLine "-----------"
'Open Order (10 times)
For i = 1 To 10 Step 1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set i
wait 2
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
OrderNo = Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")
C_Name = Window("Flight Reservation").WinEdit("Name:").GetROProperty("text")
objTextstream.WriteLine OrderNo & ", "& C_Name
Next
'Close Application (One time)
Window("Flight Reservation").Close

objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
---------------------------------------------
'Compare two text files by Size, by Text and by Binary values
Dim objFso, objTextstream, File1, File2
Dim objTextatream1, objTextstream2, Read1, Read2
File1 = "C:\Users\G C Reddy\Desktop\UFT.txt"
File2 = "C:\Users\G C Reddy\Desktop\abc.txt"

Set objFso = CreateObject("Scripting.FileSystemObject")
Msgbox "File 1 Size is: "& objFso.GetFile(File1).Size &" Bytes"
Msgbox "File 2 Size is: "& objFso.GetFile(File2).Size &" Bytes"
'1) Compare two text files by Size
If objFso.GetFile(File1).Size = objFso.GetFile(File2).Size Then
    Msgbox "Files are same by Size"
    Else
    Msgbox "Files are Not same by Size"
End If

'2) Compare two text files by Text
Set objTextatream1 = objFso.OpenTextFile(File1)
Set objTextatream2 = objFso.OpenTextFile(File2)
Read1 = objTextatream1.ReadAll
Read2 = objTextatream2.ReadAll

If StrComp(Read1, Read2, 1) = 0 Then
    Msgbox "Files are Same by Text"
    Else
    Msgbox "Files are Not Same by Text"
End If
'3) Compare two text files by Binary Values
If StrComp(Read1, Read2, 0) = 0 Then
    Msgbox "Files are Same"
    Else
    Msgbox "Files are Not Same"
End If
objTextatream1.Close
objTextatream2.Close

Set objTextatream1= Nothing
Set objTextatream2 = Nothing
Set objFso = Nothing
-----------------------------------------------
Excel Object Model
 

Excel Application Object

It is used to perform Operations on Excel Application / Excel files
----------------
Excel Application

Excel File / Workbook

Excel Sheet / Worksheet
-------------------
Create Excel Application Object
------------------------------

Set Variable = CreateObject("Excel.Application")
----------
Examples:
---------------------------------------
1) Create an Excel file/Workbook

Dim objExcel
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True 'To view the operation during execution
objExcel.Workbooks.Add ' To create new file
objExcel.ActiveWorkbook.SaveAs "C:\Users\G C Reddy\Desktop\UFTExample.xlsx"

objExcel.Quit 'To close Excel Application
Set objExcel = Nothing
--------------------------------------------
'2) Check existence of Excel file, if not exists then create the file
Dim objFso, objExcel
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")

If Not objFso.FileExists("C:\Users\G C Reddy\Desktop\UFTExample.xlsx") Then
objExcel.Workbooks.Add ' To create new file
objExcel.ActiveWorkbook.SaveAs "C:\Users\G C Reddy\Desktop\UFTExample.xlsx"
End If

objExcel.Quit 'To close Excel Application
Set objExcel = Nothing
Set objFso = Nothing
-------------------------------------------------
'3) Check existence of Excel file, if exists, open the file and enter some data. If not exist, create the file and enter some data.
Dim objFso, objExcel
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")

If objFso.FileExists("C:\Users\G C Reddy\Desktop\UFTExample.xlsx") Then
objExcel.Workbooks.Open ("C:\Users\G C Reddy\Desktop\UFTExample.xlsx")
objExcel.Worksheets(1).Cells(1, 1) = "VBScript"
objExcel.ActiveWorkbook.Save
Else
objExcel.Workbooks.Add
objExcel.Worksheets(1).Cells(1, 1) = "VBScript"
objExcel.ActiveWorkbook.SaveAs "C:\Users\G C Reddy\Desktop\UFTExample.xlsx"
End If

objExcel.Quit 'To close Excel Application
Set objExcel = Nothing
Set objFso = Nothing
-----------------------------------------------
Excel Application Object (Main Object)

Excel Workbook Object (Sub-Object)

Excel Worksheet Object (Sub-sub Object)
------------------------------