Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

How to compare arrays after sort data in Array using VBScript in QTP

In this article, we will discuss how to work with arrays explaining the below concepts:
  • How to sort data in the array.
  • How to compare two arrays.
  • How to view elements in an array


'''''''''''''''''''''''''''''''''''''''''''''''''Test Data for the example''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
arrayDataA = Array(43,54,65,76,87)
arrayDataB = Array(87,65,54,43,7)


'''''''''''''''''''''''''''''''''''''''''''''''''Calling the functions for arrays''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
call funcArrayComparision(arrayDataA, arrayDataB)
arrayData = sortArray(arrayDataA)
ViewsortArray(arrayDataA)

'''''''''''''''''''''''''''''''''''''''''''''''''Function to sort data in an array'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

public function sortArray(arrayData)
For i = LBound(arrayData) to UBound(arrayData)
  For j = LBound(arrayData) to UBound(arrayData)
    If j <> UBound(arrayData) Then
      If arrayData(j) > arrayData(j + 1) Then
         TempValue = arrayData(j + 1)
         arrayData(j + 1) = arrayData(j)
         arrayData(j) = TempValue
      End If
    End If
  Next
Next
sortArray = arrayData
End Function


'''''''''''''''''''''''''''''''''''''''''''''''''Function to view data in an array'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

public function ViewsortArray(arrayData)
For i = LBound(arrayData) to UBound(arrayData)
 msgbox arrayData(i)
Next
End Function


'''''''''''''''''''''''''''''''''''''''''''''''''Function to compare two arrays'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function funcArrayComparision(arrayA, arrayB)
''Firstly we will check whether the size of array matches, In case, It does not match, we can conclude values do not match 
   If ubound(arrayA) <> ubound(arrayB) Then
msgbox ("The array size is not same, so it is not possible array will match")
   else
   ''Now first of all we need to sort the array content, since we are compring array value by value, we are sorting the data without taking as/desc order in focus
  arrayA = sortArray(arrayA)
  msgbox ("Sorted data in the ArrayA")
  arrayB = sortArray(arrayB)
msgbox ("Sorted data in the ArrayB")
  boolflag = 0
For i = 0 to ubound(arrayA)-1
If arrayA(i) = arrayB(i) Then
msgbox arrayb(i)
boolflag = 1
Exit For
End If
Next
If (boolflag > 0) Then
msgbox ("congratulation ! array content in both the files match")
else
msgbox ("array content in both the files does not match")
End If
End If
End Function

What is the difference between ByRef and ByVal? –QTP Interview question

ByRef and ByVal are two ways to pass arguments to a function or subroutine in VBScript. Understanding the difference between two is simple.

Let us start with ByVal. Suppose a function or subroutine has an argument which accepts a variable with byval,suppose a variable x is passed as argument to the function, The value of variable does not change once the function is executed successfully.

Now let us move to ByRef. ByRef means passing value as a reference. Suppose a function or subroutine has an argument which accepts a variable with byref, suppose variable x is passed as argument to the function, The value of variable changes once the function is executed successfully.

Writing the below function in a notepad and running as a vbscript will help to differentiate ByVal and ByRef


By Ref Code:


Dim x
x= 5
call squareofNumber(x)
msgbox x
Function squareofNumber(ByRef varx)
        varx = varx*varx
        msgbox varx
End function


ByVal Code:


Dim x
x= 5
call squareofNumber(x)
msgbox x
Function squareofNumber(Byval varx)
        varx = varx*varx
        msgbox varx
End function
 By default, if we do not provide ByVal or Byref, it takes the argument as ByRef.


Tips to be followed for a successful test Automation

We associate a lot of Return on Investment with software automation. There is high expectation from test automation that it will reduce the long regression cycles. But more often than not, we see a lot of maintenance cost associated with the test automation.


In this article, we will discuss why does automation fails and what needs to be done to ensure test automation pass. I have collected the information from feedback received from multiple test automation developers and personal experience.


  • Wait and Study application First –In daily life, we learn is to understand the problem and then react. Similarly, we should never rush into software automation. First step before starting automation is to say hello to the application or system of applications which needs to be automated. Ask questions on the technologies in which the application is developed. E.g.: Is it a web application. Are different technologies used in the application, or there any web services used in the application and so on.
  • Understand the expectation from the client on the scope for the automation.
  • Choose the best tool for automation – Based on the technology used in the application, objects in the application, Choose the best tool for automation. E.g.: Tool A is an open source tool supporting Web application only. Tool B supports both Web Application and web Services both and Tool C supports only Web Services. We have to understand the limitations and benefits of different tools and choose the best suited tool for automation.
  • Do a small Proof of concept on the application to understand whether automation is feasible and we are able to cover the complex scenario in the application with focus mainly on interaction with application, e.g.: Object Identification, Interaction with external cards and systems. Another focus area should be which framework approach will be best suited for the automation, whether to go for Keyword, hybrid, data driven or BDD framework.
  •  Get an initial closure on the scope of the automation with the client in the project and the possible estimate to complete the automation, and the expected maintenance cost for the automation.

Right, we have reached a stage, where we as well client feel automation is possible. Now comes the real part, creating the framework for the Project.


Framework is like the initial building blocks. If it is strong, the building will be strong and will sustain for a longer period of time. Below are the key features of a robust framework structure:


  •  Key Component of an automation framework should be :

    • Error handling

    • Test Reporting – Test Reporting should be clean and easy for a tester to interpret which all tests fail or Pass.

    • Different classes/libraries for different types of methods or functions. E.g. suppose we are creating a project in Selenium. We can create different classes for reporting, common functions, database interaction, and different classes for selenium scripts where WebDriver interacts with application.

    • Creating different libraries helps in better maintenance of automation as we need to change the specific library code. Also suppose we move from Selenium to any other tool in future, the framework will be intact and change required in few classes only.

    • Test data Management for test data, global constant and environment variables

    • Maintaining constants and description properties in property file or separate location. In case property of object changes, we will make changes in the file without going in the scripts.

  • One of the reason for automation failing is the automation suite grows too bulky; Try to divide the test suite into logical units with flexibility to end users to easily select the subset of test suites to be executed.
  • With increasing popularity of agile, the code should be continuously integrated and run with CI.
  • Maintain Version control of automation code to ensure we maintain history of automation code and test artifacts.
  • Reviews and dry run for both positive and negative scenario should be done in the dev phase.
  • Never try to automate the application 100%. Automating one time tests scenario cause load of the automation code growing it larger and making it difficult to maintain.
  • Comments as much as possible in the code. Understanding code of another person or own code, if revisited after long time is very difficult, it becomes more difficult if there are no or very less comments in the code

The list can be huge, but again as we discuss, as we should not try to cover 100% of scenarios in automation. On similar line, creating a post with very large information will fail the purpose of the post. Hope you like the post. Many thanks