Wednesday, November 1, 2017

Test Automation Estimation guidelines

Hi,

I found good article on below page.

https://www.stepinforum.org/Test_Automation/TA_finaltalk/PDFs/Papers/TEST%20AUTOMATION%20EFFORT%20ESTIMATION.pdf

Regards,
Trupti

Tuesday, October 31, 2017

Key design activities and component for framework

Folks,

Following are key design activities for create robust automation framework

1. Define standard project folder hierarchy
2. Define standard configuration and launcher script.
3. Design standard format for automation component
4. Define reusable modules to reduce development and maintenance cost
5. Define layered architecture of reusable modules
6. Design standard flow control module
7. Design standard data storage, loading, sharing mechanism
8. Define standard reporting mechanism
9. Design standard error or exception handling mechanism

Components
1. Controller
2. Reusable component
3. Event Handler
4. Reporter

Regards, Trupti 

Read, write and delete a key from windows system registry

Dim owshell, skeypath, Skeyval, skeytype
Skeypath= "hkey_current_user\mycustomekey\mycustomedata\myvalue"
Skeyval="this is UFT made registry"
Skeytype="reg_sz"

Set owshell= createobject("wscript.shell")
Owshell.RegWrite skeypath,Skeyval ,skeytype

Skeyval = owshell .RegRead(skeyPath)
Print Skeyval

Owshell .RegDelete skeypath
 'To run application
SApp="notepad.exe"
Owshell .run sApp
Set owshell = nothing

Delete Cookies

Cookies are files containing data that is used by websites to remember user preferences and other relevant information ,such as authentication credentials. In some cases, we may need to delete cookies in order to do following.
1. Test if a site detects that the cookies are missing
2. Test if a site responds accordingly to the browser's configuration for example it prompt for approval, and then stores the selection
3. Test if a site responds according to application requirements for example, prompts for login if an authentication cookie is missing.

Simple way to achieve cookie deletion as follow.

To delete all cookie
Webutil.deletecookies()

To delete specific cookie from a domain
Webutil.deletecookie(domain,cookie)

Monday, October 30, 2017

File Rename, invalid extension and modify file data using UFT

'Invalid file extension
Public Function fnFileInvalidExtn(strfolderSourcePath,strfolderdestnPath,strFile)
   
        Set FSO=CreateObject("Scripting.FileSystemObject")
        strfolderSourcePath_mod=strfolderSourcePath&"\"&strFile
        strTestFileName1=Split (strFile,".")
        strTestFileNameFir=strTestFileName1(0)
        strTestFileName_extn_chg=strTestFileNameFir&"."&"d"
        strfolderdestnPath_mod=strfolderdestnPath&"\"&strTestFileName_extn_chg
        FileEx=FSO.FileExists(strfolderSourcePath_mod)
   
        If FileEx=True Then
            FSO.MoveFile strfolderSourcePath_mod,strfolderdestnPath_mod
            Call fnDoneResult("File Extension changed is Sucessful","File is renamed to " & strfolderdestnPath)    
        else
            Call fnFailResult("File Extension changed is UnSucessful ","Unable to renamed file to " & strfolderdestnPath)
        End If
        fnFileInvalidExtn=strTestFileName_extn_chg
                               
End Function

'File Rename

Public Function fnFileRename(strfolderSourcePath,strfolderdestnPath,strFile)
        Set FSO=CreateObject("Scripting.FileSystemObject")
        strfolderSourcePath_mod=strfolderSourcePath&"\"&strFile
        strTestFileNamemsg=Split (strFile,".")
        strTestFileNameFir=strTestFileNamemsg(0)
        strNewTestFileName=Left(strTestFileNameFir,5)&"_"&"Data"& "_" & year(Date) & Right("00" & Month(Date),2) & Right("00" & Day(Date),2) & Right("00" & Hour(Time),2) & Right("00" & Minute(Time),2)  & Right("00" & Second(Time),2) & ".dat"
        strfolderdestnPath_mod=strfolderdestnPath&"\"&strNewTestFileName
        FileEx=FSO.FileExists(strfolderSourcePath_mod)
   
    If FileEx=True Then  
        FSO.MoveFile strfolderSourcePath_mod,strfolderdestnPath_mod
        Call fnDoneResult("File Rename is Sucessful","File is renamed to " & strfolderdestnPath)    
      else
        Call fnFailResult("File Rename is UnSucessful ","Unable to renamed file to " & strfolderdestnPath)
    End If
fnFileRename=strNewTestFileName  
End Function

'Function to modify the file data
Public Function fnModifyFile(strFilePath,strOrignalString, strmodifiedString)
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFilePath, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, strOrignalString, strmodifiedString)
Set objFile = objFSO.OpenTextFile(strFilePath, ForWriting)
objFile.WriteLine strNewText
objFile.Close
End Function

Cute FTP connect, disconnect and file upload

'function to connect cute FTP
public function fnConnectCuteFTP(strHost,strUploadUserID,strUploadPwd)
Dim Flag
If Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").Exist Then
       Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").Close
    End If
Systemutil.Run "C:\Program Files (x86)\Globalscape\CuteFTP\cuteftppro.exe"
Wait (5)
Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").Dialog("regexpwndclass:=#32770","regexpwndtitle:=Tip of the Day").WinButton("regexpwndclass:=Button","regexpwndtitle:=&Close").Click
Wait(1)
Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").WinEdit("regexpwndclass:=Edit","attached text:=Host:").Type trim(strHost)
Wait(1)
Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").WinEdit("nativeclass:=Edit","attached text:=Username:").Set trim(strUploadUserID)
Wait(1)
Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").WinEdit("nativeclass:=Edit","attached text:=Password:").Set trim(strUploadPwd)
Wait(1)
Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").WinToolbar("regexpwndclass:=ToolbarWindow32","regexpwndtitle:=Quick Connect").Press 1
Wait (5)
If Window("regexpwndclass:=#32770","regexpwndtitle:=File Transfer Log").Exist Then
       Window("regexpwndclass:=#32770","regexpwndtitle:=File Transfer Log").Close
       Call fnFailResult("CuteFTP Connection Failure ","Unable to connect to CuteFTP")
Flag=False      
    Else
       Call fnDoneResult("CuteFTP Connection Sucessful ","CuteFTP connection is sucessful")
Flag=True      
    End If
    fnConnectCuteFTP=Flag
End function

Public function fnDisconnectCuteFTP()
If Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").Exist Then
       Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").Close
Call fnDoneResult("CuteFTP DisConnection","CuteFTP Disconnected sucessful")      
    Else
Call fnFailResult("CuteFTP is not launched","Unable to close as CuteFTP is not launched")  
    End If

End function

Public Function fnCuteFTPFileUpload(strFileSourcePath,strTestFileName)
Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").WinEdit("regexpwndclass:=Edit","window id:=132").Set trim(strFileSourcePath)
Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").WinEdit("regexpwndclass:=Edit","window id:=132").Type micReturn
Count=Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").WinListView("regexpwndclass:=SysListView32","window id:=1200").GetItemsCount
For i = 0 To Count
        FileName=Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").WinListView("regexpwndclass:=SysListView32","window id:=1200").GetItem(i)
        If FileName=trim(strTestFileName) Then
           Window("regexpwndtitle:=Globalscape","regexpwndclass:=Afx:").WinListView("regexpwndclass:=SysListView32","window id:=1200").Activate i
           Exit For
        End If
Next
Call fnDoneResult("CuteFTP Fileupload done","CuteFTP File upload sucessful")
End Function

Validate Environment Variable value

Environment is global object in UFT, it can be used to store and retrieve both run time and design time data.
Two type of environment variables
1. User defined-it has two types
- internal variable-- referred as default values
-external variable-- referred as constant value
2. Built in-give two type of information
- static data such as OS,OS version,local host name, test name, test fir etc
-Runtime data such as test iteration ,action name,action iteration etc

function for Validate_EnvironmentVar
Public function fnVerifyEnvironmentVar(strTestCaseID,strVarName,strVarValue)
Dim Flag
Set Obj = CreateObject("wscript.shell")
set objEnv = Obj.Environment("System")
sVarValue = objEnv.Item(strVarName)
If Trim(ucase(sVarValue))=Trim(ucase(strVarValue)) Then
Call fnDoneResult("Environment variable verify successfully", strVarName & " variable have value " &strVarValue& " match successfully.")
Flag=True
else
Call fnFailResult("Environment variable verify unsuccessfully",strVarName & " variable have value " &strVarValue& " not match successfully.")
Flag=False
End If
fnVerifyEnvironmentVar=Flag

End function