Static Keyword in Java

What is Static Keyword in Java?

Static means a field or an method that belongs to the class, rather than to an instance of the class.In simple terms, it means that we can call a static method/field even without creating the object of a  class to which they belongs!.We can have a static method or a static variable.

We have used this concept in our public static void main(String[] args), while using this we never created the object of main method but instead Java virtual machine can call the main method without creating a new application object.

Note:- we cannot use Static with class unlike final keyword.
illegal modifier error on creating static class
Static class is not possible!!

How to access static method/Variable

Syntax:-
ClassName.StaticMethod/Variable Name

Example:-
We would be accessing the static method of class(StartURL) using StartURL.testURL();

Accessing static method by its name in java

Code:-
package Java;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class StartURL {
 //Creating Static variable
 private static WebDriver driver;
  //Creating an Static Method
 public static void testURL(String sURL)
 {
  driver = new FirefoxDriver();
  driver.get(sURL);
  System.out.println("Inside Static Method");
 }
 
}
package Java;

public class MainTestCase extends StartURL{

 public static void main(String[] args) {
  //Accessing the Static method without 
  //creating class object
  StartURL.testURL("http://www.uftHelp.com");
 
 }

}


Note:- We can still access the static method or variable by using the instance object of the class, but this is not a good coding practice.In above case we could have done it using :-  
 public static void main(String[] args) {
  //Accessing the Static method  
  //By creating class object
  StartURL obj = new StartURL();
  obj.testURL("http://www.uftHelp.com");
} 
 
Still Eclipse or other Java IDE's would generate warning message :-
Static method warning message in Eclipse


Important points:-
1.Static method is associated with a class while non static method is associated with an object.
2.We can use Static + final to create constant value that's attached to a class.
Example:-
package Java;
public class StartURL {
 //Creating Static variable
 final static int noOfDays = 365;
 
 public static void main(String[] args) {
  System.out.println(noOfDays);
 }
}
3.When we create different object of an class, each class contains its distinct copy of instance variable and each is stored in different memory location but incase of static variables, it is shared across the class , which occupies an fixed location in memory.So by using static keyword we are making our program memory efficient.
4.Non static (methods, variables) can not be accessible inside static methods,meaning we can only access  static stuff Inside static methods.
Example:-
Cannot Access non static variable inside a static method of java
Interface in Java

Understanding Interface concept of Java in Selenium

When we first start with selenium automation our very first line of code comes as :-
WebDriver driver = new FireFoxDriver;

Have we ever thought what is the meaning of this code of line ...WebDriver driver ?
Simple answer to this is "WebDriver is an Interface,and we are defining a reference variable(driver) whose type is an interface.Now any object we assign to it must be an instance of a class(FireFoxDriver) that implements the interface."

Confused!!!, no worries lets understand Interface concept in Java first, it would really assist us in clearing our doubts.

Do follow us on FB,G+,Twitter or LinkedIn  to learn more 

What is an Interface?
Interface is like a blueprint of Class. It contains variables and body less methods(Abstract methods), where we just declare methods but we implement them inside the class which inherit Interface.

Note:- Java 8 introduced “Default Method” or (Defender methods), which allows us to add new methods with declaration and definition (like a normal method)to the Interfaces without breaking the existing implementation of these Interface.

Example:-

Public Interface WebDriver()
{

  int iNum = 10;
  public void get(String URL);

}

Above example just contain the structure of a get method, now a class which would implement this interface need to define the method.

Note:- By default all the variables and methods inside an Interface are public-ally accessible. 

Example:-

Public class FirefoxDriver implements WebDriver()
{
public void get(String sURL)
{
  System.out.println("URL="+sURL);
}

}

Now we know that incase of Interface, "If we define a reference variable whose type is an interface,any object we assign to it must be an instance of a class that implements the interface."

In our example that Class is FireFoxDriver and Interface is WebDriver, so we can say WebDriver driver = New FirefoxDriver();



WebDriver interface implements Firefoxdriver class



Note:- We need to use the Implements Keyword to consume Interface inside a Class.

Lets learn more about an Interface

Interface instance:-
We can create a reference variable of an interface but we can't instantiate any interface since it is just a contract to be implemented in a Class.

WebDriver driver = New WebDriver ...Not allowed, 
cannot instantiate interface in java
but below code is allowed....
Example:-

WebDriver driver = New FireFoxDriver();
driver.get(testUrl);

Creating Interface in Eclipse:-
Lets create a sample interface in Eclipse and implement it inside a Class.
Right click on package and go to -> New -> Interface.
Creating Interface in Eclipse

Important points:-
    1. Class that implements an interface must implement all the methods declared in the interface.Now our FirefoxDriver class should implement all the methods declared inside an WebDriver interface, same is the case with ChromeDriver or IEDriver classes.
    2. While implementing methods, we must follow the exact same signature (name + parameters) as declared in the interface.
    3. We can not instantiate/create object of an Interfacewebdriver driver = new webdriver ();
    4. All the variable inside an interface are by default Final.
    5. Class cannot Extend Interface only Implements it.
    6. Interface an Extend another Interface but then the class which implements the interface need to implemented the methods of both interface .
    7. Class can implement multiple Interface(Remember class cannot extend multiple classes,multiple inheritance in class is not possible)
      Class inherit from multiple Interface

    8. Interface can not hold constructor.
    9. Interface can not hold instance fields/variables.
    10. By default all the methods of Interface are public so no need to provide access modifiers.
    11. An interface can have another interface i.e. known as nested interface. 

Abstract Class v/s Interface 
Abstract class is similar to interface, like we cannot instantiate them, and they may contain a mix of methods declared with or without an implementation.But in abstract class, we can declare fields that are not static and final, and define public, protected, and private concrete methods. With interfaces, all fields are automatically public, static, and final, and all methods that are  declared or defined (as default methods) are public. We can implement any number of interfaces unlike abstract class which can extend only one class.


Note:- We could have implemented WebDriver driver = New FirefoxDriver(); as FirefoxDriver driver = new Firefoxdriver();

But we would face problem incase we need to run the same code for chromedriver then we need to create the object as ChromeDriver driver = new ChromeDriver();.

Thus to avoid this we are creating reference of WebDriver and assigning the object of implementing class i.e webdriver driver; driver = new firefoxdriver or driver = new chromedriver();


Understanding important concepts of Java for Selenium

We would be highlighting some of the most vital concepts of Java used in Selenium.Hope it assist our readers to learn and incorporate it while creating the Selenium scripts.

  1. Final Keyword
  2. Interface in Java
  3. Meaning of Static in Java 

Why we use Final Keyword ?

We can use "Final" with a variable, Method or Class

Final variable :-
Example Scenario:-
In the below code we have declared WebDriver as Final but why??

public class LoginPage {
    private final WebDriver driver;
    public LoginPage(WebDriver driver) {
        this.driver = driver;

     }

Lets understand what is meaning of Final Keyword first!!

  • Final Variable, is nothing but a constant(driver would act as constant above), as we cannot change its value once it is initialized.
  • We need to initialize the value of final variable at the time of declaration,(like final int itest = 10;).We have a exception that we can have final variable uninitialized(blank Final Variable) but  than it must be initialized inside a Constructor (i.e this.driver = driver ;) the way it is done in our example scenario above.
Now in our example scenario, we have taken webdriver variable as final, so that one's its value is initialized to the current webdriver instance we don't want it to change.

Final Method:-
1.We cannot override a final method.
Example:- We have taken TestClassA and TestClassB, where B Extends A, now incase we try to override the method of A in B.

Final method override error in Java

2.But an subclass can call the final method of parent class but not override.Example we can call the add() method below using TestClassB object

Final method can be called in subclass Java



Final Class:-
1.We cannot extend a final Class
Example:- We have made our TestClassA as Final , and we cannot extend this class in TestClassB.
Cannot Extend Final Class in Java


Important points:-
1.All variables inside an Interface are by default treated as final.
2.We need to initialize the final variable value while declaration other option is to initialize it inside a constructor.
3.We cannot override final method.
4.We cannot inherit final class.
5.We cannot declare constructor as final.

Understand Keyword Driven Framework by using UFT - (Part 3)

We are on the last step of completion of our "Keyword Driven Framework".we hope you are quiet comfortable with our last tutorials on architecture of Keyword Driven Framework-Part 1 and its various components with working code in Keyword Driven Framework- Part 2, before arriving on the final step.Here we are discussing the last component of our framework i.e our Keyword sheet.We would discuss its structure with examples.So that our readers can independently create and design Keyword sheet as per their project requirements.

Do follow us on Fb,G+,Twitter for more topics.

Keyword Sheet:-
Keyword Driven Framework Data Sheet
KeyWord Sheet
Test Details:- It is our Test Step which is performed on the AUT.It adds readablity to our keyword and same message is shown inthe result viewer of UFT.

MainWindow:- It is the parent object of the AUT (Like Browser in Web application)

Screen :- Child objects, here we can separate the hierarchy of objects  by ";"  until our action object.
Example:-
We have object with following hierarchy :- 
Browser("test").Page("test").Frame("test").WebEdit("test")

  • Webedit is our action object.
  • MainWindow :- Browser object
  • Screen :- Page Object; Frame object

So thus as child hierarchy increases we need to separate the objects by ";" and add to Screen column.

Keyword:- Operation to be performed on the Action object
Example:- 
1.COMMENT :- This keyword just adds "Test Details" to the result viewer.(Action object is blank here)
2.LAUNCH :- It launches our Browser Application (Action object is blank here)
3.IN:SET  :-It is a input operation of setting a value into edGoogleSearch (Action object)
4.IN:CLICK :- It is again clicking on the button object
5.CHECK:ALT :- It is a Check operation,which tries to match the actual "ALT" property of the action object with the Expected value.
6.SKIPME :- This keyword is just used skip the given step and no action will performed , even no reporting is done for this step unlike "COMMENT" keyword.

Note:- Keyword annotation are user created, we can modify the same as per our  requirement and something which is more meaningful.

Object:- It is our action object(on which UFT would perform operation in the AUT), it can be blank incase no object is required to be passed like "COMMENT',"LAUNCH".

Value :- It contains our main parameter that need to be passed to the keyword to perform event on the action object.
Example:- 
1.LAUNCH keyword have value = "iexplore.exe", thus it opens IE browser
2.IN.SET keyword have value = "uftHelp", thus it sets this value into the Action object(edGoogleSearch)

Param1/Param2:-
It contains any aditional paramters that need to be passed to the Keyword to achieve the task
Example:-
1.Launch Keyword(refer row-3 in the image above), contains "Param1", which points to the URL of the application
2.CHECK:ALT Keyword it contains "=" as "Param1", which is used to compare the value of the Title.

Reporting:-
We can use customized reporting as per the project and management requirements.Here are using Result Viewer in reporting with the help of Reporter.Report Event.


Result Viewer reporting in UFT
Result Viewer for Reporting


Hope this framework enlightens our audience with the basic level architecture and implementation of the Keyword Driven Framework.In our Next post we would we modifying this approach to include data driven framework so that we can achieve a our initial target of designing Hybrid Driven Framework.

Understand Keyword Driven Framework by using UFT - (Part 2)

After our basic overview of Keyword Driven Framework in Part -1 , now we would implement and understand its individual components. Part3 contains the keyword sheet creation and run results.

Test Scenario:- 
We would be using the following scenario to exemplify our Keyword Framework
1.Launch web browser 
2.Search "uftHelp" on "Google"
3.Open the first link of search Result
4.Verify that www.uftHelp.com, page is opened
5.Search any given value on this Tutorial website
6.Close the Application 

Solution Explorer:-
This is how our Framework Solution would look like.

Solution Explorer in UF
Solution Explorer in UFT
TC_01_Search :-Name of our Test Case

We have taken 2 input parameters:-
FilePath:- Path of our Excel sheet containing Keywords
SheetName:- Keyword sheet in the Excel

Input Parameters property window UFT
Input Parameters 
How to set input Parameters?

  • Select the Test Case(TC_01_Search) in Solution Explorer
  • View -> Properties
  • Open "Parameters Tab" -> Add -> Add Input Parameter
  • Fill the Name and Default Value , Leave Type as String 

Driver:-
It contains our driving script to control and call the other components of the framework.

Note:- 
  • We tried to add appropriate comments to explain the code,Please contact us or add comments below for any clarification.
  • For clear comprehension of the code try to run the script in debug mode (F11).

You can also follow us on FB,G+,Twitter or LinkedIn for more updates.

Code:-


Option Explicit
'*******************Variable Declaration-Start*********************
'File Path for Test Sheet
Dim sTestFilename
'Taking file path from Test Arguments
sTestFilename = TestArgs("FilePath")
'Test Sheet Name 
Dim sSheetName
sSheetName = TestArgs("SheetName")
'Excel Objects
Dim objExcel,objWB,objWS
'*******************Variable Declaration-Ends***********************

'Killing any Running Excel Processes
SystemUtil.CloseProcessByName "Excel.exe"
'Killing Browser Instance of Chrome or IE
'We can add other browsers also like firefox
SystemUtil.CloseProcessByName ("iexplore.exe")
SystemUtil.CloseProcessByName ("chrome.exe")
'Saving the Total Row counts in Test Data sheet into Enviornment Variable
Environment("TotalRowCount") = fn_ExcelGetRowCount(sTestFilename,sSheetName)

'Setting the Value of Starting ROW = 2
'We have taken 1 row for header fields in the KeywordSheet
Environment("StartRow") = 2
'Execute Each row till the End of Test Data
Do While Environment("StartRow") <=  Environment("TotalRowCount")
 'Function call to handle the Keyword Sepearation 
 fn_SeperateKeywords
Loop

'Killing the working Excel Processes
'It is closing the Our Testcase Excel sheet
SystemUtil.CloseProcessByName "Excel.exe"



Explanation:-
  • Driver script fetches the input FilePath and SheetName from input parameters of the test(As explained above)
  • Closes any opened instance of Excel or browser(chrome or IE).We have various techniques to kill a browser instance from task manager.
  • It further calls the Excel lib function to fetch the number of rows in the Keyword sheet, then it iterates from the 2nd row of the sheet(1st is for headers) and Calls Main Lib to work with keywords.
  • When run is completed for all the rows, it closes the working excel (Keyword Sheet, which is opened while fetching data)
How to fetch date from a Excel file.

Object Repository:-
Common_OR, it is our shared object repository which contains the objects for the above Test scenario.

Object Repository view in Keyword Framework
OR View
We have followed the below naming conventions for objects:-
Note:- it is crucial to use the naming conventions as it is implemented in the framework to segregate the object type based in the first 2 characters of the object name.

Keyword
Object
br
Browser
pg
Page
im
Image
ln
Web Link
bt
Web Button
ed
Web Edit
el
Web Element
rd
WebRadioGroup


Function Libraries:-
It is the container for our reusable functions, we would be calling these functions to do action on the object in our AUT(Application under Test)

Keyword Lib :-

Toolbox view of Functions in UFT
Keyword Functions
Code:-


'*******************************************Function*********************************
'Function Name:-        fn_Launch
'Function Description:- Opens a given browser type and redirects to given URL
'Input Parameters:-     Browser exe, URL
'Output Parameters:-    N/A
''*********************************************************************************** 
Public Function fn_Launch(sBrowser,sURL)
 'Launching Browser 
 systemutil.Run sBrowser,sURL,"","Open",3
End Function

'*******************************************Function*********************************
'Function Name:-        fn_Close
'Function Description:- To close the running Application
'Input Parameters:-    Application Image Name (like chrome.exe)
'Output Parameters:-    N/A
''***********************************************************************************
Public Function fn_Close(sProcess)
 'Killing the running process
 systemutil.CloseProcessByName(sProcess)
End Function

'*******************************************Function*********************************
'Function Name:-        fn_InputData
'Function Description:- Doing Keyword level input action on the Application 
'      like Set,Click
'Input Parameters:-     Mainwindow,Sub screen,Keyword(like Set),Main object
'      (like webedit), Value
'Output Parameters:-    N/A
''***********************************************************************************
Public Function fn_InputData(sMainWindow,sScreen,sKeyword,sObject, sValue)
Dim oObject, oParent
On Error Resume Next
Err.Clear
 Set oObject = Nothing
 Set oParent = Nothing
 'Creating the Parent object Heiarchy
 'Example :- browser("brGoogle").page("pgGoogle") 
 Set oParent = fn_CreateObjMain(sMainWindow, sScreen)
 'Creating the child object Heiarchy,i.e. our object on which action is taken
 'Example:-browser("brGoogle").page("pgGoogle").webedit("edTest")
 Set oObject = fn_CreateObjTree(oParent, sObject)
 'Adding Sync incase of Page object
 If oParent.GetROProperty("micclass") = "Page" Then
  oParent.Sync
 End If 
 'Doing the operation on the Object  
 Select Case UCase(sKeyword)
   Case "CLICK":      oObject.Click   
   Case "SUBMIT":     oObject.Submit   
   Case "SET":          oObject.Set Cstr(sValue)
   Case "SET_SECURE":     oObject.SetSecure Cstr(sValue)
   Case "SELECT":       oObject.Select Cstr(sValue)
   Case "EXTENDSELECT":   oObject.ExtendSelect Cstr(sValue)
   Case "SELECTINDEX":    oObject.Select Cstr("#"&sValue)
   Case "TYPE":          oObject.Type Cstr(sValue)
   Case "FIRE_EVENT":   oObject.FireEvent Cstr(sValue)
   Case "SEND_KEYS":     oObject.Click : Wait 1:SendKeys Cstr(sValue)
   Case "CLOSE":         oObject.Close : Wait 2
   Case Else     
       Reporter.ReportEvent micFail,"Input type is not recognised,"&_
       "Inside fn_InputData function ", sInputOperation
       'ExitTest
 End Select
 'Incase of Error
 If Err.Number <> 0 Then
  Reporter.ReportEvent micFail, "Error Happened inside fn_InputData "_
  , Err.Description
  On Error GoTo 0
  'Exit test run
  'ExitTest
 End If
 
Set oParent = Nothing
Set oObject = Nothing
End Function

'*******************************************Function*********************************
'Function Name:-        fn_CheckData
'Function Description:- To check the Expected property of the object like innertext 
'      should match for the object 
'Input Parameters:-    Mainwindow,Sub screen,Keyword(like value,innertext),Main object
'      (like webedit),Value,comparision type (=,<>,>)
'Output Parameters:-    N/A
''***********************************************************************************
Function fn_CheckData(sMainWindow,sScreen,sProperty,sObject, sValue,sParam1)
Dim sExpectedValue,sActualValue,sCompareType
'Expected value to be compared
sExpectedValue = sValue
'Comparison factor like '=','<>'
sCompareType = sParam1
On Error Resume Next
Err.Clear
 Set oObject = Nothing
 Set oParent = Nothing
 'Creating the Parent object Heiarchy
 'Example :- browser("brGoogle").page("pgGoogle") 
 Set oParent = fn_CreateObjMain(sMainWindow, sScreen)
 'Creating the child object Heiarchy,i.e. our object on which action is taken
 'Example:-browser("brGoogle").page("pgGoogle").webedit("edTest")
 Set oObject = fn_CreateObjTree(oParent, sObject)
 'Adding Sync incase of Page object
 If oParent.GetROProperty("micclass") = "Page" Then
  oParent.Sync
 End If
  
 'Actual value of the object
 sActualValue = oObject.getroproperty(sProperty)
 
 'Taking the comparision based on the comparison Type
 Select Case sCompareType
  Case "=":
   If Ucase(Trim(sExpectedValue)) = Ucase(Trim(sActualValue) )Then
   Reporter.ReportEvent micPass,"Checkpoint Passed.","Expected value of '"_
   &sProperty&"' = '"& sValue&"' found in the application"
   End If
  
  Case "<>":
   If Ucase(Trim(sExpectedValue)) <> Ucase(Trim(sActualValue) )Then
   Reporter.ReportEvent micPass,"Checkpoint Passed.","Expected value of '"_
   &sProperty&"' = '"& sValue&"' Not found in the application"
   End If
  Case ">":
   If Ucase(Trim(sExpectedValue)) > Ucase(Trim(sActualValue) )Then
   Reporter.ReportEvent micPass,"Checkpoint Passed.","Expected value of '"_
   &sProperty&"' = '"& sValue&"' found greater in the application"
   End If
  Case else
   Reporter.ReportEvent micPass,"Error Happened inside 'fn_CheckData'",_
   "Invalid Comparator"&"Type = '"&sCompareType&"'"
 End Select
 'Incase of Error
 If Err.Number <> 0 Then
  Reporter.ReportEvent micFail, "Error Happened inside 'fn_CheckData' "_
  ,Err.Description
  On Error GoTo 0
  'Exit test run
  'ExitTest
 End If
fn_CheckData = True
End Function

Main Lib :-

Keyword functions in UFT
Main Functions
Code:-


'*******************************************Function*********************************
'Function Name:-        fn_SeperateKeywords
'Function Description:- Function to fetch the cell data from Test Sheet
'Input Parameters:-     N/A
'Output Parameters:-    N/A
''*********************************************************************************** 
'Function to separate the Keywords
Public Function fn_SeperateKeywords
'Variable Declaration
Dim sTData
Dim sTestStep, sMainWindow, sScreen,sKeyword,sObject,sValue 
Dim sParam1, sParam2
 'Creating an Array from data in each Row
 sTData = fn_ExcelReadRowData(objWS,sTData, Environment("StartRow"))     
 'Taking the values from the Array sTData
 sTestStep =     sTData(0)
    sMainWindow =     sTData(1) 
 sScreen =      sTData(2)
 sKeyword =         split(sTData(3),":")
 sObject =       sTData(4)
 sValue =      sTData(5)
 sParam1 =      sTData(6)
 sParam2 =      sTData(7)
 
 'Incase Keyword is SKIPME, UFT will skip that Row Run 
 If sKeyword(0) <>  "SKIPME" Then
  Select Case UCase(sKeyword(0))
   'Keyword to Launch Application
   Case "LAUNCH":    fn_Launch sValue,sParam1
   'Keyword for adding Wait 
   Case "WAIT":   Wait sValue    
   'Keyword for adding Comment in output results
   Case "COMMENT":   Reporter.ReportEvent micInfo, " < Comment given by User:>", sTestStep
   'Keyword for working with Input operations
   Case "IN":       fn_InputData sMainWindow,sScreen,sKeyword(1),sObject, sValue
   'Keyword to check property of the Object
   Case "CHECK":   fn_CheckData sMainWindow,sScreen,sKeyword(1),sObject, sValue,sParam1
   'Keyword to Kill running Process
   Case "CLOSE":     fn_Close sValue    
   'Incase of mismatch of Keyword   
   Case Else :     Reporter.ReportEvent micFail, "UnKnown Keyword" ,_
   "Keyword Not Recognised: " & Cstr(sKeyword)
  End Select
 End If
 'Increasing the Row Counter to fetch data from the next Row in Excel
 Environment("StartRow") = Environment("StartRow")+1
End Function
 
'*******************************************Function*********************************
'Function Name:-        fn_CreateObjMain
'Function Description:- Calls fn_CreateObjTree to get the Parent hierarchy of the object 
'Input Parameters:-     sWindow(Parent Object),sScreen(Child object)
'Output Parameters:-    N/A
''***********************************************************************************
Function fn_CreateObjMain(sWindow, sScreen)
 Dim sObjects, iObjectCount
 Set fn_CreateObjMain = Nothing
 'Creating the Parent tree object 
 'Example:- browser("brGoogle")
 Set fn_CreateObjMain = fn_CreateObjTree(fn_CreateObjMain, Cstr(sWindow))
 'If Screen value is non empty, then creating the sub tree 
 'Example:- browser("brGoogle").page("pgGoogle")   
 If Cstr(sScreen) <> "" Then
  'This is required incase of further node inside a sub tree
  'Example:- browser("brGoogle").page("pgGoogle").frame("frGoogle")
  sObjects = Split(sScreen, ";")
  'Looping till the end of nesting on the Screen column
  For iObjectCount = 0 To Ubound(sObjects)
   'Calling the object tree function
   Set fn_CreateObjMain = fn_CreateObjTree(fn_CreateObjMain, Cstr(sObjects(iObjectCount)))
  Next
 End If
 'Incase of errors 
 If  fn_CreateObjMain Is Nothing Then
  Reporter.ReportEvent micFail ,"Error Happened inside fn_CreateObjMain",_
  "The parent object could not be located" & sWindow & " " & sScreen
 End If
End Function

'*******************************************Function*********************************
'Function Name:-        fn_CreateObjTree
'Function Description:- Finds the childobject and attaches it to the parent hierarchy
'Input Parameters:-     objParent(Parent object),sObjectName(Name of child object 
'      in object repository)sWindow(Parent Object),sScreen(Child object)
'Output Parameters:-    N/A
''***********************************************************************************
Function fn_CreateObjTree(objParent, sObjectName)
 'Taking the left value of the objectname
 'Example:- Taking 'br' from 'brGoogle' object
 Select Case LCase(Left(sObjectName, 2))
  Case "br":  Set fn_CreateObjTree = Browser(sObjectName)
  Case "dl":  If objParent Is Nothing Then
     Set fn_CreateObjTree = Dialog(sObjectName)
  Else
     Set fn_CreateObjTree = objParent.Dialog(sObjectName)
  End If
  Case "pg":     Set fn_CreateObjTree = objParent.Page(sObjectName)
  Case "rd":     Set fn_CreateObjTree = objParent.WebRadioGroup(sObjectName)
  Case "ln":     Set fn_CreateObjTree = objParent.Link(sObjectName)
  Case "im":     Set fn_CreateObjTree = objParent.Image(sObjectName)
  Case "fr":     Set fn_CreateObjTree = objParent.Frame(sObjectName) 
  Case "ed":     Set fn_CreateObjTree = objParent.WebEdit(sObjectName)
  Case "bt":    Set fn_CreateObjTree = objParent.WebButton(sObjectName)
  Case "el":     Set fn_CreateObjTree = objParent.WebElement(sObjectName)
  Case "ls":    Set fn_CreateObjTree = objParent.WebList(sObjectName)
  
  Case Else  
   Reporter.ReportEvent micFail, "Error Happened inside 'fn_CreateObjTree' " ,_
   "Object type is not found: " & sObject
   fn_CreateObjTree = False
  End Select
End Function


Excel Lib :-
Toolbox view of Functions in UFT
Excel Functions


Code:-


'Delcaring common excel objects
Dim objWB,objWS,objRange
'*******************************************Function*********************************
'Function Name:-        ExcelGetRowCount
'Function Description:- Returns No. of rows in the Test Data Sheet
'Input Parameters:-     Excel file path,Sheet Name
'Output Parameters:-    No. of Rows
''***********************************************************************************
Public Function fn_ExcelGetRowCount(sTestFilename,sSheetName)
  'Open Excel Connection
  Set objExcel= CreateObject("Excel.Application")
  objExcel.Visible = False
  objExcel.EnableEvents = False
  objExcel.DisplayAlerts = False 
  'Open WorkBook
  Set objWB = objExcel.Workbooks.Open(sTestFilename)
  'Refering the Sheet
  Set objWS = objWB.Worksheets(sSheetName)
  'Taking the Range
  Set objRange = objWS.Range("A1").CurrentRegion
  fn_ExcelGetRowCount = objRange.Rows.Count
  Set objRange = Nothing
End Function

 
'*******************************************Function*********************************
'Function Name:-        fn_ExcelReadRowData
'Function Description:- Reading the Row and returns Each cell in a Array
'Input Parameters:-     N/A
'Output Parameters:-    N/A
''*********************************************************************************** 
Public Function fn_ExcelReadRowData(objWS, sData, iRow)
  'Variable declaration
  Dim iCount
  'Fetching the Excel range
  Set objRange = objWS.Range("A1").CurrentRegion
  ReDim sData(objRange.Columns.Count)
  For iCount = 1 To objRange.Columns.Count
    sData(iCount-1) = CStr(objRange.Rows(iRow).Columns(iCount).Value)
  Next
  'Destroying object
  Set objRange = Nothing
  fn_ExcelReadRowData = sData
End Function


Recovery Scnearios:-

ApplicationCrash:- we have created Recovery Scenario to handle exceptional crash of our AUT.

How to create Recovery Scenario:-

  • Resources -> Recovery Scenario Manager -> New Scenario

Trigger Event:- Is crashing of any browser (Chrome or IE)

Trigger Event in Recovery Scenario
Trigger Event
RecoveryOpeations:- Close the Browser window

Recovery Operation in UFT
Recovery Operation
Post-Recovery Operation :- Re-run the test 

Post recovery Operation in Recovery Scenarion
Post-Recovery Operation UFT
Understand Keyword Driven Framework by using UFT - (Part 1)
Understand Keyword Driven Framework by using UFT - (Part 3)