Saturday, October 14, 2017

QTP Basic

QTP:
VB script:


---commands
msgbox:it displays message
print:it display the o/p in the output space
inputbox:it is used to take input from the user
input (messaga,title of window)
example:
inputbox "enter a number","my window"
inputbox "hello"
---------------------------------------
'&'--used for concadination
z=inputbox ("enter a number","my window")
print "the output entered is: " & z
------------------------------------------
'&_'-->if the string is long use this for example:-
message= "hello how are you doing "&_
"?,how i am doing sexy"&_
"?,how i am doing sexy"
print message
------------------------------------------------------------
&vbcrlf&
--->it is used to print single line in new line for example
message= "hello how are you doing" &vbcrlf& "hello how are you doing"
print message
---------------------------------------------------------------
Optional explicit
'Dim->is used to declare the variable
Optional explicit
Dim a
a=100
print a
-----------------------------------------------------------------
--> using else if
a=200
b=2013
c=434


    If a>b and a>c Then
    print "a is greatest"   
        ElseIf b>c Then
        print "b is greatedt"
        Else
        print "c is greatest"
        End If

---------------------------------------------------------
'while loop

i=1
While i<10
    print i&"----is value of -i "
    i=i+1
Wend
------------------------------------------------
'for loop
printing from 1 to 10
'step 1--> increement by 1
For x = 1 To 10 Step 1
    print x
Next

'print reverse order

For y = 100 To 1 Step -1
    print y
Next


---------------------------------------------------

'debug
'F5--normal exe
'F10---line by line

'here below printing table from 1to 5
For table = 1 To 5 Step 1
    print "printing table for "&table
For x = 1 To 10 Step 1
    print table & " *"& x &" ="& table*x
    Next
Next
----------------------------------------------------------


Array: to store values in an array
syntax:


Dimx(5) --it has 6 elements--Fixed size
x(0)=10
x(1)=12
x(2)=true
x(3)=34.77
x(4)=suhdeer


ubound(x)--> to know the size of the array

Example:
Dim x(5)
x(0)=100
x(1)=true
x(2)=12.98
x(3)="sudheer"
x(4)="hi there "

For i = 0 To ubound(x)
print x(i)
   
Next
----------------------------------------------------

Redimension Array -,ReDim preserve y(4)'4

Dim y()
ReDim preserve y(3)'4
y(0)=34
y(1)=10
y(2)=43435
y(3)=123.00

ReDim preserve y(4)'4

For i = 0 To ubound(y) Step 1
    print y(i)
Next
--------------------------------------------------
'using redim preserve example


Dim chittireddy()
ReDim preserve chittireddy(6)' need to write after dim
chittireddy(0)="gopal"
chittireddy(1)="laxmi"
chittireddy(2)="suresh"
chittireddy(3)="sunil"
chittireddy(4)="sunitha"
chittireddy(5)="sudheer"

ReDim preserve chittireddy(7)
chittireddy(6)="shiva"


ReDim preserve chittireddy(9)
chittireddy(7)="sindu"
chittireddy(8)="jyotshna"

ReDim preserve chittireddy(11)
chittireddy(9)="sai"
chittireddy(10)="veronica"

ReDim preserve chittireddy(12)
chittireddy(11)="bubblu"


For family = 0 To ubound(chittireddy) Step 1
print    chittireddy(family)
Next



Dim  kewl()------------ dynamic array
ReDim preserve kewl(5)
kewl(0)="suhdeer"
kewl(1)="akash"
kewl(2)="reddy"
kewl(3)="cool"
kewl(4)="hot"

For i = 0 To ubound(kewl) Step 1
    print kewl(i)
Next


 -----------------------------------------------------------------------------
mulvalue=multiply(25,25)
    print "the result is"& mulvalue
    If result<10 Then
        print "the resuly is "& mulvalue
    End If 
 
 
    Function multiply(a,b)
        result = a*b
        multiply=result
    End Function
 
--------------------------------------------
 
    'variable with same name as function name
    'put in brackets
 
'    total=sumofThree(10,20,30)


'    print "the total is "&total
'    If total>30 Then
'        print "you are allowed for club as your age is legal:"&total
'    End If
'    
'    Function sumofThree(a,b,c)
'        sumofThree=a+b+c
'    End Function
'    
    ---------------------------------------------------
 
 
    '----------------------------------------
    'sub rountine:- wil not retur any value
    'add
 
    Sub add
        a=10
        b=12
        c=a+b
        print c
    End Sub
 
'------------------------------------
    'functions in QTP
    'LEFT
     str= "Good morning ghyderabad!"
     text=left (str,4)
     msgbox text
     'RIGHT
     rtext=right(str,10)
     msgbox rtext
  
     'MID
     str= "Good morning ghyderabad!"
     midText=mid(str,10)
     msgbox midText
  
     'SPLIT
 '---------------------------------------------
      str= "Good,morning,hyderabad!"
    a=split(str,",")
    msgbox a(0)
    msgbox a(1)
    msgbox a(2)
    msgbox ubound(a)
 
 
   
      For ff = 0 To ubound(a) Step 1
      msgbox a(ff)
      Next
'------------------------------------------------------- 
'ucase
    str= "hi ther ehow are you doing lol"
    ustr=ucase(str)
    msgbox ustr
'------------------------------------------------------------
    'lcase
    lcstr=lcase(str)
    msgbox lcstr
   
'-------------------------------------------------------
      'LTRIM TRIM RTRIM
          str= "           United state of America        "
          print str
          print ltrim(str)
          print rtrim(str)
          print trim(str)
       
          '-------------------------------------
          'cstr----converstig numbers ibnto strings
          a=100
          b=200
          msgbox cstr(a) + cstr(b)
       
'----------------------------------------
'isnumberic---verify it is numeric or not
a=120
b=4001
If isnumeric(a) and isnumeric(b) Then
    msgbox cint(a)+cint(b)
 
End If

'example 2
a=123
msgbox isnumeric(a)'true or false

'-------------------------------------------------
'cint--converting string into number
a="123"
b="345"
msgbox a+B
msgbox cint(a)+cint(b)
'--------------------------------------
'DATE,TIME,NOW FUNCTIONS

print date'10/15/17
print time'0:26:00
print now'10/15/17 0:26:00

'---------------------------------------
'Datevalue--------------11/10/22
d1=datevalue("10 november 2012")
print d1'11/10/22

d2=datevalue("11 january 2018")
print d2


msgbox datediff("s",d1,d2)

msgbox datepart("d",d1)
msgbox datepart("m",d1)
msgbox datepart("q",d1)
msgbox datepart("yyyy",d1)
msgbox datepart("w",d1)
msgbox datepart("ww",d1)

'time
msgbox time
msgbox hour(time)
msgbox minute(time)
msgbox second(time)



Error Reporting :


on Error resume next:
-is used to countine the execution withput popup but error is reported(the error will be there in memeory)


Err.number-->
it will check the number error if any
Err.Description -->it gives the type of error-----if any error on server then it will give description
Err.raise-->we can raise error deliberately
Err.clear---> it will clear the error from the server


 



On error resume next
print "a"& Err.number

cint("a3")
print Err.Description
print "b" &Err.number

If err.number<>0 Then
print    Err.description
End If

Err.clear

print "After Clearning the Errov   -  " &Err.number

On error resume next
Err.raise 10
print Err.description

output:

a0
Type mismatch
b13
Type mismatch
After Clearning the Errov   -  0
This array is fixed or temporarily locked

No comments:

Post a Comment

Description Programming

'==Descriptive Programming language 'creating the common browser and page object  Set  myPage= browser( "creationtime:=0...