Right Click Disabled

Sunday, February 26, 2012

VBScript code in QTP to create a dictionary object to access a dictionary, to store five pairs of data into that dictionary and then to find total marks stored in that dictionary.

Option explicit
Dim dico, i, sn, m, lm, tot
'Here     i       for loop
'            sn     for subject name
'            m     for marks
'            lm    for list of marks
'            tot   for total
'Create dictionary object and add pairs of data
Set dico=CreateObject("Scripting.Dictionary")
For i=1 to 5 step 1
      sn=inputbox("Enter Subject Name : ")
      m=inputbox("Enter Marks : ")
      dico.Add sn,m
Next
'Find total marks in that dictionary
tot=0
lm=dico.Items
For each m in lm
      tot=tot+m
Next
Print("Total Marks is :"&tot)
Set dico=nothing

Thursday, February 23, 2012

Dictionary Object


Dictionary is used to store pairs of data and every pair first value is called as Key and second value is called as Item. To access this dictionary pairs we can use an object called as dictionary object.



The corresponding dictionary object can create an interface between QTP tool and a dictionary in memory (RAM). To create dictionary object and access dictionary content using that object, we can use below code in VBScript in QTP tool:

Option explicit
Dim dico
Set dico=CreateObject("Scripting.Dictionary")

In the above code createobject() function is used to create an object for specified data structure. Here “dico” is an object for a dictionary.

To store data into dictionary as pairs, dictionary object is providing a function or method like shown below:

Option explicit
Dim dico
Set dico=CreateObject("Scripting.Dictionary")
dico.Add "English", 78
dico.Add "Hindi", 65
dico.Add "Maths", 98
dico.Add "Computers", 90
dico.Add "Physics", 80

While adding pairs of data to dictionary using dictionary object, corresponding test automater can maintain unique values for Keys.

VBScript code in QTP for to display addition of two arrays


Option explicit
Dim array1(4), array2(4), array3(4), i
For i=0 to 4 step 1
      array1(i)=inputbox("Enter value for Array 1 :")
Next
For i=0 to 4 step 1
      array2(i)=inputbox("Enter value for Array 2 :")
Next
For i=0 to 4 step 1
      array3(i)=cint(array1(i))+cint(array2(i))
      print(array3(i))
Next

VBScript code in QTP to display given value is Palindrome


Option explicit
Dim val, res
val=inputbox("Enter any value : ")
res=strreverse(val)
If val=res Then
   msgbox(val&" is a Palindrome.")
   else
      msgbox(val&" is not a Palindrome.")
End If

OR

Option explicit
Dim val, res
val=inputbox("Enter any value : ")
res=strreverse(val)
If strcomp(val,res)=0 Then
   msgbox(val&" is a Palindrome.")
   else
      msgbox(val&" is not a Palindrome.")
End If

VBScript code in QTP to display given value in reverse


Option explicit
Dim val, res
val=inputbox("Enter any value : ")
res=strreverse(val)
msgbox("Reverse of  "&val&" is : "&res)

VBScript code in QTP to display last four characters in given value


Option explicit
Dim val, lastfour
val=inputbox("Enter any value : ")
lastfour=right(val,4)
msgbox("Last four characters in "&val&" is : "&lastfour)

Wednesday, February 22, 2012

VBScript code in QTP to display first four characters in given value


Option explicit
Dim val, firstfour
val=inputbox("Enter any value : ")
firstfour=left(val,4)
msgbox("First four characters in "&val&" is : "&firstfour)

VBScript code in QTP to display number of words in given sentence


Option explicit
Dim sentence, nw
sentence=inputbox("Enter any sentence : ")
nw=split(sentence," ")
msgbox("Number of words in given sentence is : "&ubound(nw)+1)

VBScript code in QTP to create five elements array, to store five values in to that array in any type, display alphabets and alphanumerics in that array.


Option explicit
Dim val(4), i
For i=0 to 4 step 1
     val(i)=inputbox("Enter any values :")
Next
For i=0 to 4 step 1
     If not isnumeric(val(i)) Then
        print(val(i))
     End If
Next

VBScript code in QTP to create five elements array , to store five values in any type and display numbers only.


Option explicit
Dim val(4), i
For i=0 to 4 step 1
     val(i)=inputbox("Enter any values :")
Next
For i=0 to 4 step 1
     If isnumeric(val(i)) Then
         print(val(i))
     End If
Next

VBScript code in QTP to create an array with five elements to store a student five subject marks and display minimum marks


Option explicit
Dim subject(4), i, min
For i=0 to 4 step 1
     subject(i)=inputbox("Enter marks :")
Next
min=subject(0)
For i=0 to 4 step 1
     If min>subject(i) Then
        min=subject(i)
     End If
Next
msgbox("Maximum marks : "&min)

VBScript code in QTP to create an array with five elements to store a student five subject marks and display maximum marks


Option explicit
Dim subject(4), i, max
For i=0 to 4 step 1
     subject(i)=inputbox("Enter marks :")
Next
max=subject(0)
For i=0 to 4 step 1
     If max<subject(i) Then
         max=subject(i)
     End If
Next
msgbox("Maximum marks : "&max)

VBScript code in QTP to create an array with five elements to store a student five subject marks and display total marks


Option explicit
Dim marks(4), i, total
total=0
For i=0 to 4 step 1
    marks(i)=inputbox("Enter marks :")
    total=total+marks(i)
Next
msgbox("Total marks of student : "&total)

VBScript code to display gross salary of an employee


Here, Gross Salary is equal to basic salary plus commission. If basic salary >=15000 then commission is 10% of basic salary. If basic salary <15000 and >=8000 then commission is 5% of basic salary. If basic salary <8000 then commission is 100/-

Option explicit
Dim gross, basic, comm
basic=inputbox("Enter Basic salary of an Employee :")
If basic>=15000 Then
   comm=basic*10/100
   elseif basic<15000 and basic>=8000 Then
       comm=basic*5/100
       else
          comm=100
End If
gross=basic+comm
msgbox("Gross salary of Employee is :"&gross)

VBScript code in QTP to display grade of a student depends on total marks.


Here, Grade is “A” when total marks >=800, Grade is “B” when total marks<800 and >=700, Grade is “C” when total marks <700 and >=600, Grade is “D” when total marks<600.

Option explicit
Dim totalmarks
totalmarks=inputbox("Enter Total Marks of student :")
If totalmarks >=800 Then
   msgbox("Grade is A")
   elseif totalmarks<800 and totalmarks>=700 Then
       msgbox("Grade is B")
       elseif totalmarks<700 and totalmarks>=600 Then
            msgbox("Grade is C")
            else
              msgbox("Grade is D")
End If

VBScript code in QTP to find given number is ever or odd


Option explicit
Dim x
x=inputbox("Enter Number :")
If x mod 2 = 0 Then
    msgbox(x&" is Even number")
    else
       msgbox(x& " is Odd number")
End If

Displaying output in QTP


To display output while running VBScript code on desktop, test automaters are using below syntax.

msgbox(“Welcome to divineQTP”)

Type Casting

Simply type casting is the procedure to convert the data from one type to another in any programming language.

Type casting Functions:

Cint() à Convert to integer
Cdbl() à Convert to double(float)
Clng() à Convert to long integer
Cdate() à Convert to date in format
Ccur() à Convert to currency
Cstr() à Convert to string

Here, default value type is string.

Addition of two numbers get from keyboard in QTP

Option explicit
Dim x, y, z
x=inputbox("Enter First Number :")
y=inputbox("Enter Second Number :")
z=cint(x)+cint(y)
msgbox(z)

Note: In VBScript, Plus(+) operator is overriding operator. It perform addition and concardination. To get addition operation for plus(+) operator, test automaters are using type casting concept.

Multiplication of two numbers get from keyboard in QTP

Option explicit
Dim x, y, z
x=inputbox("Enter First Number :")
y=inputbox("Enter Second Number :")
z=x*y
msgbox(z)

Read input from keyboard in QTP

To read input from keyboard while running VBScript code, test automaters can use below syntax in that code.

Variable=inputbox(“message”)

Multiplication of two numbers in QTP

Option explicit
Dim x, y, z
x=10
y=20
z=x*y
msgbox(z)

Importance of variables declaration in QTP

In QTP, no need to declare variables in VBScript before use, But “to prevent typing mistakes in code” we can use variables declaration concept.

Launching QTP

To write programs in VBScript language in QTP tool, test automaters can follow below navigation.

Go to “Start” à All Programs à  QuickTest Professional àQuickTest Professional.exe à Click “OK” in Add-in Manager window without selecting any Add-in àFile Menu àNew à Test.


Write VBScript program in that pane area and click “Run” to execute that VBScript program.

Friday, February 17, 2012

Before Starting QTP some useful points


  • It is a Functional regression testing tool.
  • QTP 11.0 is recent version released by HP (Nov 2010 to Jan 2011)

  • QTP will be installed in windows client or in windows server based computers and working as stand alone.
  • QTP can automate functional test cases on windows based and web based SUT.
  • QTP doesn’t support command based SUT automation.
  • QTP can automate functional test cases on windows based and web based SUT, when that SUT screens or pages developed in Java, .Net, VB, SAP, PeopleSoft, Oracle Apps, HTML(web), Power Builder, Delphi, Stingray, VisualAge Smalltalk, Siebel, Standard Windows, Terminal Emulators(C, C++, Mainframes) and Silverlight(new support in QTP 11.0).
  • QTP can automate functional test cases on web based SUT, when that site pages are developed in HTML along with Flex, QTP needs Flex Plug-in installation provided by Adobe corporation.
  • To automate functional test cases on mobile based SUT, we can integrate QTP 11.0 with Webneir of Perfectosoft company.
  • QTP can support functional test cases automation on SUT database developed in any technology like Oracle, SQL Server, MS-Access, Sybase, FoxPro, MySql, DB2, TOAD,…etc.
  • QTP have Web Services add-in for SOA testing automation.
  • Using QTP we can automate Data volume testing and also find capacity of SUT database. 

To use QTP tools on specified type of SUT, testing team needs knowledge on VBScript/Jscript, QTP Script, .Net Factory, XML and SQL.



Need for Automation in Software testing


In Software testing automation testing teams are following below conditions or limitations.
  • In Functional testing automation was needed for Regression and Final Regression to finish repetitions of tests as early as possible.
  • In Performance testing automation was needed at every level, because manually performance testing is costly and complex to conduct.
  • To automate Data volume testing and Intersystem/SOA testing, we can use functional testing tools(QTP).
  • The remaining non-functional testing topics like Compatibility, Configuration, Usability, Multi-longevity, Installation, Security and Parallel testing are conducting by testers manually due to lack of well known testing tools in market. 


Manual Software Testing Vs Automation Software Testing


In an organization, a project process is having multiple stages of development and multiple stages of testing. A separate testing team is involving in software testing stage to validate corresponding software w.r.t  customer requirements(Functional Testing) and w.r.t customer expectations(Non-Functional Testing). During this software testing testers are testing software functionalities and characteristics by following Black box testing techniques and valid matrices in manual style or in automation style.

In general, tester can write test cases in english by following Black box testing techniques in IEEE829 formate, in MS-Excel or QC like management tool. Those cases in english will be converted to automated test scripts in computer languages by using testing tools.

From the above VV Model a software tester can study SRS to understand project requirements(domain knowledge). Software tester can conduct different types of tests on software to detect defects(testing knowledge). During software testing, testers can use some testing tools to finish testing as early as possible(programming knowledge).
Software tester needs programming knowledge for automation to integrate with corresponding SUT(software under testing) front-end screens and corresponding SUT back-end database.

Why Automation for Software Testing?

Manual software testing is performed by a human sitting in front of a computer carefully going through application screens or pages, trying various cases and input combinations, comparing the results to the expected results. Manual tests are repeated often during development cycles for source code changes and other situations like multiple operating environments and hardware configurations.
An automated software testing tool is able to playback pre-recorded and predefined actions, compare the results to the expected behavior and report the success or failure of these manual tests to a test engineer. Once automated tests are created they can easily be repeated and they can be extended to perform tasks impossible with manual testing. Because of this, automated software testing is an essential component of successful development projects.
Automated software testing has long been considered critical for big software development organizations but is often thought to be too expensive or difficult for smaller companies to implement.
Automated Software Testing Saves Time and Money
Software tests have to be repeated often during development cycles to ensure quality. Every time source code is modified software tests should be repeated. For each release of the software it may be tested on all supported operating systems and hardware configurations. Manually repeating these tests is costly and time consuming. Once created, automated tests can be run over and over again at no additional cost and they are much faster than manual tests. Automated software testing can reduce the time to run repetitive tests from days to hours. A time savings that translates directly into cost savings.
Automated Software Testing Improves Accuracy
Even the most conscientious tester will make mistakes during monotonous manual testing. Automated tests perform the same steps precisely every time they are executed and never forget to record detailed results.
Automated Software Testing Increases Test Coverage
Automated software testing can increase the depth and scope of tests to help improve software quality. Lengthy tests that are often avoided during manual testing can be run unattended. They can even be run on multiple computers with different configurations. Automated software testing can look inside an application and see memory contents, data tables, file contents, and internal program states to determine if the product is behaving as expected. Automated software tests can easily execute thousands of different complex test cases during every test run providing coverage that is impossible with manual tests. Testers freed from repetitive manual tests have more time to create new automated software tests and deal with complex features.
Automated Software Testing Does What Manual Testing Cannot
Even the largest software departments cannot perform a controlled web application test with thousands of users. Automated testing can simulate tens, hundreds or thousands of virtual users interacting with network or web software and applications.
Automated Software Testing Helps Developers and Testers
Shared automated tests can be used by developers to catch problems quickly before sending to QA. Tests can run automatically whenever source code changes are checked in and notify the team or the developer if they fail. Features like these save developers time and increase their confidence.
Automated Software Testing Improves Team Morale
This is hard to measure but we’ve experienced it first hand, automated software testing can improve team morale. Automating repetitive tasks with automated software testing gives your team time to spend on more challenging and rewarding projects. Team members improve their skill sets and confidence and, in turn, pass those gains on to their organization.

Thursday, February 16, 2012

Testing Tools Generations

Testing tools are classified in to four generations.
  • First generation tools are commercial and support inbuilt languages. For example WinRunner is licensed tool and support TSL(Test Script Language).
  • Second generation tools are also commercial but they can support development languages to prepare test scripts. For example QTP is licensed and support VB-Script language.
  • Third generation tools are opensource(Free of cost) and they can support development languages. For example Selenium is opensource and support core java.
  • Fourth generation tools are not tools and they are direct programming languages like PERL, PYTHON, RUBY and REXX.
Twitter Bird Gadget