Search

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

Tuesday, 26 November 2013

How to launch Application from Command Prompt in UFT?

Scenario:- How we can launch our application to be automated from 'Command Prompt' in UFT/QTP?

Solution:- Today we faced the situation, where we were not able to launch application 
from 'SystemUtil.Run'.Problem was that our application was not directly in the form of .exe, 
but rather it was expecting parameters based on the Region for which we want this to be launched.

To overcome this problem and coming with  reusable function, we adopted an alternate approach of launching our region specific applications from 'Command Prompt'. 

We hope following code will definitely help our automation lovers, in solving there problem 
of launching. Here we have taken "Notepad" application for launching example.
Created "Shell Script" code for sending keyboard commands.

Please feel free to share your comments and experiences on this.



Command Prompt in UFT

Wednesday, 16 October 2013

Why we Automate Testing ?

Lot number of times it happens that we start with things what we never realized that why we are doing it .Same happened with me, when i was  a newbie to automation, I never thought why we are going for it , and only thought that came it my mind was that it is just a mundane task like any other assignments in IT world.But slowly and steadily as things progressed, i thought of asking WHY ? .



Thus i thought of sharing on this topic in my 100th Post, please feel free to add your expert comments.


Why we Automate
  • Speed”, we automate the manual flow, thus it performed better than the manual person visiting the test cases(Test steps) and running each step individually.
  • Repeat ability”, thus resulting in greater “Return on Investment”, as tasks can automated and ran as many number of time as it is required.
  • Coverage”, it helped us to ran the same scripts on different environment thus increasing the coverage of testing like various OS versions, Microsoft Office versions and even localization's.
  • Reliability”, as same task is ran again and again, it was very monotonous for manual person testing the same thing again and again , and it resulted in errors (like Skipping the flow, to shorten the task) .
  • Re usability”, we reused most of the coding part like Login functions,global functions to connect to databases.
  • Time Saving”, as it was automation, so no manual effort was required thus it saved the effort of that person
  • Convenient”, our team worked on projects where it was required to test the application in non-working hours (PST timings), thus automation was more convenient rather than person sitting in night shifts and doing the testing(We scheduled our tasks to be automatically triggered)
  • "Program ability", As automation uses a coding language, thus we are able to leverage this to automate sophisticated program steps and to bring out the hidden information.
Above points are mostly interlinked, on the whole we can say that, why we automate? so as to  make testers life easier :)