Thursday, 30 November 2017

Vbscript: Multiple uneven spaces to single space


Input string has uneven spaces. 

sInput = "uftHelp=  User Firendly      Techy Help    additional                  string for               you"

Do while instr(1,sinput,"  ")>0
 
If instr(1,sinput,"  ")>0 Then
   
    x= replace(sInput,"  "," ")
   
    sInput=x
   
End If

Loop
   
print x

O/P:uftHelp= User Firendly Techy Help additional string for you

Vbscript: Err Object

On Error Resume Next
Err.Clear

REM Notice No Value passed in Set Method
Browser("Login | Salesforce").Page("Login | Salesforce").WebEdit("username").Set

Print  err.Number&" "&err.description
REM O/P: 450 Wrong number of arguments or invalid property assignment




On Error Resume Next
Err.Clear

REM Notice Value passed in not having " "
Browser("Login | Salesforce").Page("Login | Salesforce").WebEdit("username").Set x
Print  err.Number&" "&err.description

REM 0



On Error Resume Next
Err.Clear

REM Notice Value passed in not having " "
Browser("Login | Salesforce").Page("Login | Salesforce").WebEdit("username").Set  "x"
Print  err.Number&" "&err.description

REM 0




Vbscript Dictionary: Deleting Particular Keys based on Item Value condition

Dim odic
 
Set odic=CreateObject("Scripting.Dictionary")
odic.Add "Shilpa",1
odic.Add "Amit",2
odic.Add "Sumit",3

For each x in odic.Keys

If odic.item(x)=2 Then
odic.Remove(x)
End If

Next

For each x in odic.Keys
print x 
Next

Set odic=nothing

'Shilpa
'Sumit

Vbscript: Finding Unique Items from space separated string


str="IBM CG CITI IBM CG"

arr=split(str," ")

final=""
 
For each x in arr

If instr(1,final,x)=0 Then

final=final&" "&x

End If
   
Next

msgbox final  'IBM CG CITI

Tuesday, 28 November 2017

Checkpoint: Find Webelement

set opage=Browser("Certificate Error: Navigation").Page("SafetyDirect : Login")

Function VerifyWebElement(objpage,strwebelement)

Dim owebelement
Set owebelement=Description.Create
owebelement("micclass").Value="WebElement"
owebelement("innertext").Value=strwebelement
 
set allwebelement=opage.Childobjects(owebelement)
For i=0 to allwebelement.Count-1

If trim(allwebelement(i).Getroproperty("innertext"))=trim(strwebelement) Then
   
VerifyWebElement=True
Reporter.ReportEvent micPass,"Checkpoint for "&strwebelement," "&strwebelement&" is Present on the webpage"

   
Else

  VerifyWebElement=False
  
End If
   
Next
End Function

Checkpoint for Verifying WebObjects

set opage1=Browser("Certificate Error: Navigation").Page("SafetyDirect : Login")
VerifyWebObj opage1,"WebEdit","ctl00\$ContentPlaceHolder1\$TextBoxUser"

Function VerifyWebObj(objpage,strobjclass,strobjname)

Dim WebObj
Set WebObj=Description.Create
WebObj("micclass").Value=cstr(strobjclass)
WebObj("name").Value=strobjname



set allwebobj=opage1.Childobjects(WebObj)
'msgbox allwebobj.Count

For i=0 to allwebobj.Count-1
If trim(allwebobj(i).Getroproperty("name"))=trim(strobjname) Then

VerifyWebObj=True
Reporter.ReportEvent micPass,"Checkpoint for "&strobjname," "&strobjname&" is Present on the webpage"
'msgbox "yes"
   
Else

 VerifyWebObj=False
   Reporter.ReportEvent micFalse,"Checkpoint for "&strobjname," "&strobjname&" is NOT Present on the
  ' msgbox "false"
  
End If
   
Next

End Function

Saturday, 18 November 2017

Vbscript: Reading XML file

'Sample File ####################################
'Const XMLDataFile="C:\Users\sunshine\Desktop\vbscriptprgm\samplexmlnanda.xml"

<Resources>
<Module1>

 <Function_Libararies>
 <Library>module1lib1.vbs</Library>
 <Library>module1lib1</Library>
 <Library>module1lib1</Library>
 </Function_Libararies>

 <Repositories>
 <Repository>module1repo.tsr</Repository>
 <Repository>module2repo.tsr</Repository>
   </Repositories>
</Module1>

<Module2>

 <Function_Libararies>
 <Library>module2lib2.vbs</Library>
 <Library>module2lib2</Library>
 <Library>module2lib2</Library>
 </Function_Libararies>

 <Repositories>
 <Repository>module2repo.tsr</Repository>
 <Repository>module2repo.tsr</Repository>
   </Repositories>
</Module2>

</Resources>
Dim Modules
Modules=Array("Module1","Module2")

Const XMLDataFile="C:\Users\sunshine\Desktop\vbscriptprgm\samplexmlnanda.xml"
Set oxml= CreateObject("Microsoft.XMLDOM")
oxml.Async = False
oxml.Load(XMLDataFile)

If oxml.Parseerror.Errorcode<>0 Then
   
msgbox "Error Parsing XMl"
   
End If

For i=lbound(Modules) To ubound(Modules) Step 1

parent=cstr(Modules(i))
   
Set Col=oxml.getElementsByTagName(parent).Item(0)

Set olibcol=Col.getElementsByTagName("Function_Libararies").Item(0)

Set lib=olibcol.Childnodes

For each  strlib in lib

msgbox strlib.text
   
Next
Next
'###############################################


'Code For Reading Nodes:

UFT: Combining Reglar Expression


 Window("text:=.*(Report|Graph)").Close

 This will close Window with Text Report or Graph preceded by any alphanumeric characters.

Wednesday, 15 November 2017

UFT: Variable in Descriptive Programming

Variable name in descriptive Programming


If Browser("Login | Salesforce").Page("title:=.*Salesforce.*").WebElement("innertext:="&Acctname,"html tag:=SPAN").Exist(10) Then
Reporter.ReportEvent micPass,"WebElementCheck","Element Apears"
Else
Reporter.ReportEvent micFail,"WebElementCheck","Element Apears"
End If

Sunday, 12 November 2017

How to calculate return on investment (ROI) for automation projects?

How to calculate return on investment (ROI) for automation projects?

Usually we automate the applications to get the benefits like cost saving, faster regression testing, overnight execution, accurate testing etc.

But automating the application also involves some upfront cost involved in it. We need to buy the automation tool like QTP, we need to train people on the tool then design the automation framework.

To measure the benefit of the automation projects, we need to calculate the return on the investments. We measure what all benefits we have got after automation of the project.

Effort Saved = Manual Efforts Required for Execution  - Efforts required for automated Execution.

Once we calculate effort saved for the entire testing cycle of the project, we can find ROI by below formula.

ROI = Total Effort Saved for all regression cycles - (A+B+C+D)

where

A = Total effort required for designing automation framework
B = Effort required for the maintenance of the automation scripts
C = Effort required for the automation of testing 
D = Licensing Cost of the tool

Vbscript: Sorting String Array with Strcomp

a = array("bangalore","surat","Pune",1)

For i=0 to ubound(a)

For j=0 to ubound(a)
If strComp(a(i),a(j),1) < 0  Then
temp = a(i)
a(i) = a(j)
a(j) = temp
End If
Next

Next

For i=0 to  ubound(a)

   print a(i)
  'It will print 1,bangalore, Pune, surat

Next

Vbscript: Print the Pattern

Expected Pattern:
*
**
***


Code:

str=""
For r = 0 To 2 Step 1
   
   
    For c=0 to 2 Step 1
   
   
     If c<=Then
        
         str=str+"*"
        
     End If
       
    Next
   
    str=str+vbnewline
Next

print str

Friday, 10 November 2017

UFT Interview Question: Alternate lowercase and uppercase letter in word: Capegemini==>CaPeGeMiNi

str="Capegemini"

strfinaltext=""
 
For i = 1 To len(str) Step 1
    If i mod 2 <>0 Then
        strfinaltext=strfinaltext+ ucase(mid(str,i,1))
       
    Else
   
        strfinaltext=strfinaltext+lcase(mid(str,i,1))
    End If
Next

msgbox strfinaltext  'CaPeGeMiNi

Vbscript Typename to get type of object

Set Otable=Browser("Sample Page All Page").Page("Sample Page All Page").WebTable("EmpiId")
Set olink=otable.ChildItem(2,7,"link",0)
msgbox typename(olink) 'textlink'

set objdlgbutton=Browser("Sample Page All Page_2").Dialog("Message from webpage").WinButton("OK")
msgbox typename(objdlgbutton) 'stdbutton

set webbtn=Browser("Sample Page All Page_2").Page("Sample Page All Page").WebButton("Submit")
msgbox typename(webbtn) 'htmlbutton

Set oradio=otable.ChildItem(2,7,"link",0)
msgbox typename(oradio) 'textlink'

set oweblist=Browser("Sample Page All Page_2").Page("Sample Page All Page").WebList("Country")
msgbox typename(oweblist) 'htmllist'


set objradio=Browser("Sample Page All Page_2").Page("Sample Page All Page").WebRadioGroup("gender")
msgbox typename(objradio) 'htmradiogroup'


set owebedit=Browser("Sample Page All Page_2").Page("Sample Page All Page").WebEdit("browser")
msgbox typename(owebedit) 'htmledit'

Sunday, 5 November 2017

QTP Interview Questions:

Listing All the questions I faced in interviews so far:

UFT:

1)Explain Framework used in your project
2) Explain your roles and responsibilities
2)How do you do Error Handling
3) How many cases are there in your test suite
4)How do you do reporting
5) Open test from present in ALM using AOM
6)If hierarchy if object present in OR changes and its affecting 50 scripts, how would you deal with it
7) If I give yo something to automate how would you automate. What will be the steps.
8)what is virtual Objects
9)What is Visual Relation Identification works
10) How object Identification works






VBSCRIPT: Questions:

1)How to covert number to string ( 123 should be shown as One Two Three)
2) Explain On Error Resume Next
3) If function had 3 arguments and I want to pass 4th argument how would you deal with it
4) Count occurrence of each character in a string
5) How to handle xml files. If I want to get particular node value in xml file how can I get it.
6) Can function return multiple values
7) If I want to return multiple values from subroutine how can i do it
8) Separate xls,txt,csv files from folder
9)


Vbscript: Instr() or Regular Expression

 sString = “Welcome User, You have 5 New Mails”
 sSubString = “Welcome .*, You have .* New Mails”‘Check if the string pattern matches – using 

RegExp object
Set objRE = New RegExp
objRE.Global = True
objRE.Pattern = sSubString
msgbox objRE.Execute(sString).Count ‘ — msgbox returns the value 1 as the RegExp object returns 1 match 

‘Check if the string pattern matches  – using InStr
msgbox InStr(1, sString, sSubString, 1)  ‘ — msgbox returns the value 0  as it is not able to find the match using InStr

Thursday, 2 November 2017

Using ReadyState in UFT

The readyState property in QTP returns the loading status of the current browser . This property Will be of immense help if the AUT under test has a lot of sync issues while running the script .

This property returns one of four values :
1. uninitialized(1) Has not started loading yet.
2. loading(2) Is loading
3.Interactive(3) Has loaded enough and the user can interact with it
4.complete(4) Fully loaded

close the browser once the page is loaded completely.

    If Browser (Google).object.ReadyState=4 Then
     Browser(Google).Close
    End If

Wednesday, 1 November 2017

System lock during QTP Automation Test Script Execution

system lock during QTP Automation Test Script Execution

There are few ways to prevent windows to lock the system:
Way1:
Download the software Caffeine 1.4 and install on the machine where u run the scripts.
Way 2:
Create a .vbs file (with the below mentioned code) and a task in task scheduler
Const DELAY_MINUTES = 10
Wscript.Sleep DELAY_MINUTES * 60000
Do
CreateObject(“Wscript.Shell”).SendKeys “+”
Wscript.Sleep DELAY_MINUTES * 60000
Loop
Way 3:
Create a .vbs file (with the below mentioned code) and a task in task scheduler
Const micVoid = 0
Const micByte = 26
Const micLong = 3
Const KEYEVENTF_KEYUP = &H2
Set Extern = CreateObject("Mercury.ExternObj")
extern.Declare micVoid, "keybd_event", "user32", "keybd_event", micByte, micbyte, miclong, micLong
Extern.Declare micVoid, "Sleep", "kernel32", "Sleep", micLong
While True
extern.keybd_event 0, 0, KEYEVENTF_KEYDOWN, 0
Extern.Sleep 20000
Wend
-********************-*****************-*****************************-*********************************-*****************************
We can even run the scripts when the system is locked, but QTP may not replay constantly on a locked machine
The Quick Test Professional computer is locked or logged off.
Quick Test Professional was launched without permission to interact with the desktop.
The following registry key which enables you to run tests on a remote computer, even on an incompatible execution environment:
HKEY_CURRENT_USERSoftwareMercury InteractiveQuick Test ProfessionalMicTestSkipEnvironmentChecks
Set the registry key to 1 to prevent the remote execution checks, and 0 to perform the checks.

Spring Boot : Exception Handler 14