Thursday, 19 June 2014

How to Search a Numeric value inside a String ?

Hello Automation lovers, during these sweltering summers it is really arduous to share
something with the community. From a long time, I was thinking to share some logic for 
searching numbers in a Text.
Search Me UFT
By the grace of GOD, today is lucky Day :)


Scenario: - How we can search a Numeric Value inside a given Text/String/File?

Solution:-
Note: - Please refer the link on RegularExpression Object for more understanding of the
 code.


'*******************************************Sub***************************************************
'Function Name:-        fn_SearchNumeric
'Function Description:- Used to find the Numeric values inside a string               
'Input Parameters:-     Sting
'Output Parameters:-    Final Search Message
'Created By :-          www.uftHelp.com
'Date:-                 19th June,2014
'****************************************************************************************************
msgbox fn_SearchNumeric("Please search 89766 Numeric values")


Function fn_SearchNumeric(strSearchString)
    Set objRegExp = CreateObject("VBScript.RegExp")
    objRegExp.Global = True 
    'Regular Expression to search Numeric values
    objRegExp.Pattern = "\d"
    Set objMatches = objRegExp.Execute(strSearchString)  
    'Incase match is found 
    If objMatches.Count > 0 Then
       strMessage = "The given string '"&strSearchString&"' 
          has the following numeric values:-" & vbCrlf
       iNumeric = ""
       For Each sMatch in objMatches   
           iNumeric = iNumeric &  sMatch.Value 
       Next 
       fn_SearchNumeric = strMessage & iNumeric
     Else
         fn_SearchNumeric = "Sorry No match found!!Please correct 
         the String to search"
     End If    
End Function

Wednesday, 2 April 2014

Understanding Browser methods,by opening multifarious Tabs of Browser in UFT

To understand the various common methods of Browser Object,we will open 2 tabs in the same browser instance.
Scenario:- How we can open webpage in different Tabs of the same Browser.



Working with Browser

Solution:- We need to launch browser and open a webpage(say "www.uftHelp.com"), within the same instance we'll open another tab and re-direct to a different webpage say "www.Google.com"


For this we will learn and use the following methods of Browser object :- 

Browser object methods UFT
OpenNewTab:-Opens a new tab in the existing opened browser window. 


Navigate:- Redirects to given URL.


FullScreen:-Open the browser in Full-screen mode(F11).


Refresh:-Refreshs the opened page(Like F5).


DeleteCookies:-For deleting the cookies from the browser.


CloseAllTabs:-Close all the opened tab and also the browser instance.


Sync:-Wait for the browser for navigating to the opened URL Application.


Code

'Open a new Browser using Util Object
SystemUtil.Run "iexplore.exe", "www.uftHelp.com"
'Browser Sync
Browser("CreationTime:=0").Sync
'Delete cookies from the Browser
Browser("CreationTime:=0").DeleteCookies
'Refreshes the Opened Page
Browser("CreationTime:=0").Refresh
'Opening  a new tab within the same browser
Browser("CreationTime:=0").OpenNewTab()
'Opening Browser in FullScreen mode
Browser("CreationTime:=0").FullScreen
'Sync for new tab
Browser("CreationTime:=1").Sync
'Navigate to perticular URL in the new tab
Browser("CreationTime:=1").Navigate "www.Google.com"
'Find total number of tabs in the browser window
iTabs = Browser("CreationTime:=0").GetROProperty("number of tabs")
msgbox iTabs 'Displays the value 2
'Close all the tabs in the browser window
Browser("CreationTime:=0").CloseAllTabs()

Sunday, 16 February 2014

Working with Regular Expression Object in UFT /QTP.

Today we are going to touch the key concept in Regular Expression i.e "Creation
of  Regular Expression object" and using this we'll search a given pattern in a string.
Regular expression is a frequently used concept in Automation WORLD.

Scenario:- To find the existence of a pattern inside a string which is present in Your 

application (AUT).

Solution:-

Let’s break the code into smaller steps:-
Step1:- Creating regular expression object
Method1:- Set objRegExp = CreateObject("VBScript.RegExp")
Method2:- Set objRegExp = New RegExp

Step2:-Using the above object to set the Search pattern
objRegExp.Pattern = “Test Pattern”

Step3:- Ignore Case insensitivity (By default it is enabled)
objRegExp.IgnoreCase = False

Step4:- To check pattern should match all occurrences in an entire search string or 
just the first one.( (By default it is True)
 objRegExp..Global = True
Note:- Regular expression object has Pattern,IgnoreCase and Global property.

Step5:-We will use the Test method, which returns Boolean value, based on the
pattern match in the given string.
objRegExp.Test(v_String)
Note:- Regular expression has Test, Execute and Replace methods.

Code:

'*******************************************Sub***************************************************
'Function Name:-        fnPatternMatch
'Function Description:- Used to check the particular pattern inside 
                         a given string
'Input Parameters:-     Pattern to be searched , String 
'Output Parameters:-    None
'Created By :-          www.uftHelp.com
'Date:-                 17th Feb,2014
'****************************************************************************************************

Function fnPatternMatch(v_String,v_Pattern)
 ' Create variable.
   Dim objRegExp
   
   ' Create regular expression object 
    Set objRegExp = New RegExp
	'Set objRegExp =  CreateObject("VBScript.RegExp")
	With objRegExp	
		.Pattern = v_Pattern  ' Set pattern.
		.IgnoreCase = False ' Set case insensitivity.
                .Global = True   ' Set global applicability.
	End with
	 ' Test the occurence of pattern inside the string
         v_Flag = objRegExp.Test(v_String)
	'Check whether pattern is found 
	If v_Flag Then
		fnPatternMatch = "Match is Found"
	Else
		fnPatternMatch = "Sorry! No match found"
	End If
	Set objRegExp = Nothing 
End Function

msgbox fnPatternMatch("uftHelp.com Your first TestingHelp","uftHelp.com")
msgbox fnPatternMatch("uftHelp.com Your first TestingHelp","uftHelp.in")


Tuesday, 31 December 2013

Hello Hello 2014,with a Snoozy Scenario of a Automation

Hello Automation Lovers,I just wanted to thanks a bunch for associating with uftHelp.com throughout 2013, and hope we further enrich this relationship in 2014.

Nothing much to share on the last eve of 2013, just an idea that how automation can be a boon for lethargic people like me :).

Coming to Scenario:-

We created Test Sheets for our "Keyword Driven Framework",it was more than 
20 sheets and each having lot number of test steps.Now as are moving into Agile world, so are our clients, thus all of a sudden  they wanted each test step in test sheet to have a 
Test case-ID column with increasing values.

Solution:-
Manual Approach:- Go to each sheet and add Test Case ID to each Test step, and it is very monotonous and tedious task at least for a automation engineer.

So we created one simple script that  added TC-ID to all the Test Steps, which are
 added as comments to the test sheet(Comments begin with some symbol like in our case 
it was 'X').
Learn about Excel automation here...

Logic:- 
Add TC-ID in increment fashion where we are having comments.

Enjoy testing :) and Happy New Year, 2014 ...Cheers!!!!

Code:-

AddingRowToExcel Using UFT

Test Sheet:- ?, is where we needed the TC-ID to be added


Test Sheet for KeywordDriven Framework

Tuesday, 3 December 2013

How to append zero(0) to user defined date?

Scenario:- Creating date in user defined format like MM/DD/YYYY?

Solution:- In one of our application automation, we came across a situation, where we 
wanted to validate the date displayed on the AUT, for that we created the logical date to match with Actual Result .

But our validation was failing, reason being, for the single digit dates like 2nd month it was coming as '2' but in our AUT it was getting displayed as '02'.

Logic:-To overcome this situation we created very agile and simple function.
We separated the required date into month,day and year part, concatenated '0' to all the 
parts and took the right most 2 digits, to create the required date format .We created date 
in the format of 'MM/DD/YYYY',and the given function can be modified to return date 
in any of the required patterns.


Date Formatting in UFT or QTP