SDET- QA Automation Techie

Full Stack QA Automation Testing Blog

  • Home
  • Training
    • Online
    • Self-Paced
  • Video Tutorials
  • Interview Skills
    • HR Interview Questions Videos
    • Domain Knowledge
  • Career Guidance
  • Home
  • Software Testing
    • Manual Testing Tutorials
    • Manual Testing Project
    • Manaul Testing FAQS
    • ISTQB
    • AGILE
  • Web Automation Testing
    • Java Programmng
    • Python Programmng
    • Selenium with Java
    • Selenium with Python
    • Robot Framework(Selenium with Python)
    • selenium with Cucumber
    • TestNG+IntelliJ
    • Mobile App Testing(Appium)
    • JMeter
  • API Automation Testing
    • Rest Assured API Testing (BDD)
    • Rest Assured API Testing (Java+ TestNG)
    • Robot Framework(Rest API Testing with Python)
    • Postman
    • SoapUI
    • API Testing(FAQ's)
  • SDET|DevOps
    • Continuos Integration
    • SDET Essentials
    • AWS For Testers
    • Docker
  • SQL
    • Oracle(SQL)
    • MySQL for Testers
    • NoSQL
  • Unix/Linux
    • UNIX TUTORIALS
    • Linux Shell Scripting
  • ETL Testing
    • ETL Data warehouse Tutorial
    • ETL Concepts Tools and Templates
    • ETL Testing FAQ's
    • ETL Testing Videos
  • Big Data Hadoop
  • Video Tutorials
  • ApachePOI Video Tutorials
  • Downloads
    • E-Books for Professionals
    • Resumes
  • Automation Essencials
    • Cloud Technologies
      • Docker For Testers
      • AWS For Testers
      • Sub Child Category 3
    • Java Collections
    • Selenium Locators
    • Frequently Asked Java Programs
    • Frequently Asked Python Programs
    • Protractor
    • Cypress Web Automation

VB Script Procedures (UDF's)

 Descriptive Programming, QTP, UFT, vb scripting   

In VBScript, there are two kinds of procedures available; the Sub procedure and the Function procedure.


1) Sub Procedures

A Sub procedure is a series of VBScript statements (enclosed by Sub and End Sub statements) that perform actions but don't return a value.

A Sub procedure can take arguments (constants, variables, or expressions that are passed by a calling procedure).

If a Sub procedure has no arguments, its Sub statement must include an empty set of parentheses ().

Syntax:

Sub Procedure name ()
Statements
-----------
-----------
End Sub

Or

Sub Procedure name (argument1, argument2)
Statements
-----------
-----------
End Sub

Example: 1

Sub ConvertTemp()
temp = InputBox("Please enter the temperature in degrees F.", 1)
MsgBox "The temperature is " & Celsius(temp) & " degrees C."
End Sub

Example: 2

2) Function Procedures


A Function procedure is a series of VBScript statements enclosed by the Function and End Function statements.

A Function procedure is similar to a Sub procedure, but can also return a value.

A Function procedure can take arguments (constants, variables, or expressions that are passed to it by a calling procedure).

If a Function procedure has no arguments, its Function statement must include an empty set of parentheses.

A Function returns a value by assigning a value to its name in one or more statements of the procedure. The return type of a Function is always a Variant.

Syntax:

Function Procedure name ()
Statements
-----------
-----------
End Function

Or

Function Procedure name (argument1, argument2)
Statements
----------
----------
End Function

Example: 1

Function Celsius(fDegrees)
Celsius = (fDegrees - 32) * 5 / 9
End Function

Example: 2

Function cal(a,b,c)
cal = (a+b+c)
End Function

3) Getting Data into and out of Procedures

o Each piece of data is passed into our procedures using an argument.

o Arguments serve as placeholders for the data we want to pass into our procedure. We can name our arguments any valid variable name.

o When we create a procedure using either the Sub statement or the Function statement, parentheses must be included after the name of the procedure.

o Any arguments are placed inside these parentheses, separated by commas.

4) Using Sub and Function Procedures in Code

A Function in our code must always be used on the right side of a variable assignment or in an expression.

For example:

Temp = Celsius(fDegrees)

-Or-

MsgBox "The Celsius temperature is " & Celsius(fDegrees) & " degrees."

To call a Sub procedure from another procedure, type the name of the procedure along with values for any required arguments, each separated by a comma.

The Call statement is not required, but if you do use it, you must enclose any arguments in parentheses.

The following example shows two calls to the MyProc procedure. One uses the Call statement in the code; the other doesn't. Both do exactly the same thing.

Call MyProc(firstarg, secondarg)

MyProc firstarg, secondarg

Notice that the parentheses are omitted in the call when the Call statement isn't used.

5) Examples:

(here, I used Flight Reservation Application for creating Functions, why because, It is the default application for QTP, anybody can practice easily.)

'*******************************************
' Login Operation
'*******************************************

Function Login(Agent,Pwd)
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set Agent
Dialog("Login").WinEdit("Password:").Set Pwd
Dialog("Login").WinButton("OK").Click

If Window("Flight Reservation").Exist(10) Then
Login="Login Operation Sucessful"
'Msgbox Login
else
Login="Login Operation Unsucessful"
Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
Dialog("Login").WinButton("Cancel").Click
'Msgbox Login
End If
End Function

'***************************************
' Closing Application
'***************************************
Function Close_App()
if Window("Flight Reservation").Exist(3) Then
Window("Flight Reservation").Close
End If
End Function

'***************************************
' Open Order
'***************************************

Function Open_Order(ord)
ordnum=0
On Error Resume Next
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set ord
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
ordnum=Window("Flight Reservation").WinEdit("Order No:").GetROProperty ("text")
ordnum=cdbl (ordnum)
If ord=ordnum Then
Open_Order= "Order Number "&ordnum&" Opened Sucuessfully"
'Msgbox Open_Order
else
Open_Order= "Order Number "&ordnum&" Not Opened/ Not Available"
Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("OK").Click
Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click
'Msgbox Open_Order
End If
End Function

'******************************************
' Update Order
'******************************************
Function Update_Order(Tickets)
Window("Flight Reservation").Activate
Window("Flight Reservation").WinEdit("Tickets:").Set Tickets
Window("Flight Reservation").WinButton("Update Order").Click
wait(10)
update=Window("Flight Reservation").ActiveX("Threed Panel Control").GetROProperty ("text")
If update="Update Done..." Then
Update_Order= "Order Updated Sucussfully"
'Msgbox Update_Order
Else
Window("Flight Reservation").Dialog("Flight Reservations").WinButton("OK").Click
Update_Order= "Order Not Updated"
'Msgbox Update_Order
End If
End Function

'******************************************
' Function to send a mail
'******************************************

Function SendMail(SendTo, Subject, Body, Attachment)
Set otl=CreateObject("Outlook.Application")
Set m=otl.CreateItem(0)
m.to=SendTo
m.Subject=Subject
m.Body=Body
If (Attachment <> "") Then
Mail.Attachments.Add(Attachment)
End If
m.Send
otl.Quit
Set m = Nothing
Set otl = Nothing
End Function

Call SendMail(mailto:pavan@pavanworld.net,%22hi%22,%22This is test mail for testing","")
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home
popup

Popular Posts

  • How To Explain Project In Interview Freshers and Experienced
    “ Describe an important project you’ve worked on ” is one of the most common questions you can expect in an interview. The purpose of a...
  • API/Webservices Testing using RestAssured (Part 1)
    Rest Assured : Is an API designed for automating REST services/Rest API's Pre-Requisites Java Free videos: https://www.you...
  • MANUAL TESTING REAL TIME INTERVIEW QUESTIONS & ANSWERS
    1. How will you receive the project requirements? A. The finalized SRS will be placed in a project repository; we will access it fr...

Facebook Page

Pages

  • Home
  • Resumes
  • Job Websites India/UK/US
  • ISTQB
  • Selenium with Java
  • E-Books for Professionals
  • Manual Testing Tutorials
  • Agile Methodology
  • Manual Testing Projects

Live Traffic

YouTube


Blog Visitors

Copyright © SDET- QA Automation Techie | Powered by Blogger
Design by SDET | Blogger Theme by | Distributed By Gooyaabi Templates