Welcome to Automation Fraternity!

Interview Q & A Part 1

1.What is an Automation Framework?

There are three basic types:
a. Keyword Driven
b. Data Driven
c. Hybrid
Apart from these we have two more which I can Quote:
d. Modular
e. Function Driven
Framework is nothing but a blue print of how you create script, manage script, log, report and share result. However, basic components of a FW remains constant, they mostly differ in the layout of the blueprint. But like any other blue print, if its flawed, it could lead to havoc later on.
A FW should be
1. Robust
2. Modular
3. Maintainable
4. Scalable.

FW should have a good ROI. (Which is supposedly very rare, only and only because of ill designed Framework, where above mentioned fundamentals are not taken in mind.)
Components:
Basic components of a FW which are similar for nearly all types of FW
1. Driver
2. Data
3. Tests
4. Repository
5. Log
6. Reporting

Different implementations might overlap one or the other.

In automation and not alone in QTP, Frameworks have been categorized based on some specific traits.
Based on these traits we can tag our framework as Keyword, Data or Hybrid FW.
Data Driven:
Data Driven is mostly used where we have to test same set of functionality with different data.
Best example here is to test calculators SUBTRACT functionality. In order to test calculator functionality like SUBTRACT, we can have a single script created for the operations and keep the data outside in an excel sheet. Excel sheet would contain columns like TC_ID, INPUT_1, INPUT_2, EXPECTED_RESULT.
Script will iterate through this data and compare the expected with actual and report.
In the above case, data is driving our test and therefore it is called as a Data driven FW. However, its implementation could vary like instead of excel we could use datatable, DB, XML etc. Folder structure could vary too. But still it would be called as Data Driven, since its the data corresponding to a test case which is driving the test.
Please be aware that in nearly all the FWs external data is used, but that does not make it a data driven framework.

Key word Driven:

A mystical KW driven FW is nothing but the way of writing the script and running the scripts.
In KW automation tester creates the simple keyword resembling the operations of the Application under test. All KWs are mapped with a function.
For example, in the case of our calculator, coder can create 4 Keywords,
Add, Subtract, Multiply and Divide. These Keywords would then be wired with the appropriate functions. Coders then create a Driver script such that whenever these Keywords are sent, corresponding functions would get invoked.

So if we try to implement keywords approach in the calculator automation, we could have another column added in excel file called as KEYWORD and pass the relevant KW with the input values. Corresponding function will get invoked and does the operation.

This sort of FW could be called as KW driven FW with Data Driven Feature and it could also be called as Data Driven FW with KW driven Features. Both descriptions aptly define the FW.

In short a data driven function can also be KW driven FW, without being called as a Hybrid FW.

In KW driven FW Keywords can be of two types:
a. Generic KWs: like ClickLink, SetString, MouseHover, VerifyText etc
b. Business Keywords: which are business specific operations. For example: if flipkart is our AUT, we will have a KW called as SearchProduct which will search any product or PlaceOrder etc.

A KW driven has advantages like:
1. Faster Test Case Script Creation
2. Standardization i.e. everyone has to stick to the same KW or functions and no custom code is allowed. So when modification is required, only KWs functions are to be modified reflecting the change in all the scripts or new KWs are created to incorporate new operation.
3. Readability for user. It is more readable as it does abstraction on the underlying code and maps it with the more readable keyword.
4. If well documented can be handed over to SME and manual Testers to operate and create test scripts.
Disadvantages:
1. Costly in terms of time and efforts because generic as well as business KWs require good coding and thorough application knowledge.

Note: QTP itself promotes KW driven by providing generic keywords name spaces called as Actions.
We can write our keywords definitions in the Actions and name them appropriately to create a KW, which can then be used in other Tests using Call the Existing Action method of QTP.

Hybrid FW:

As name suggests Hybrid FW is the one which is customized as per the need. It can have keywords and also would have data kept in DB to be used. Typically all the FW are hybrid because it provides more flexibility. User can customize it as per their need.
But this also comes with the risk of spoiling the standardization of the FW as test case script creator will have the liberty to modify it anyway which suits his need and considering he is human he might make mistakes in his understanding.
In KW driven, everyone will have specific set of functions\KWs to be used and process is set to impose those mapped Keywords over the users so that user will only use certain set of KW for all the operations over the application. If new functionality is to be added, automation tester will create new KW to cover it. Person who is writing the script could not add any customized code in the script or excel.
But that does not mean Hybrid driven FW is bad. If properly implemented and with loyal followers of the processes to use it, it outweigh other types of framework. Its sole advantage is that it is very accommodative. It basically incorporates good traits of all types of FW

To Summarize. Any kind of Framework could turn in to a Hybrid FW if its Terms of Use is altered. Any type of FW if not properly used could turn in to a disaster later on. So always keep in mind while creating or altering a FW:
1. FW should be user friendly (by user I mean one who creates and run scripts)
2. FW should be maintainable and scalable.
3. Creation of script and running them should be easy.
4. Proper Error handling should be in place.
5. FW logs should be maintained. Every event in the FW should be logged for later debugging. For example: This could be achieved by inserting a fso calls to write a Log text file, in all the functions, so as to track what happened when batch of tests ran.
6. Reporting should be very lucid. This is the most important component of any FW. Reporting should be client\stakeholder friendly. HTML reporting is considered the best as it gives options for decorative canvassing, but excel can also be used for an effective reporting.
Use of QTP default viewer should be discouraged as it is not client\stake holder friendly.
It could be used internally though where non-technical guys are not involved, but thats very very rare.

Disclaimer: Above mentioned analysis is just a simple answer to the usual question Explain QTP Automation FW.

For Detailed Information on QTP FW follow the below link:
It has a very detailed analysis and explanation of all sorts of Framework by anish pillai.
http://www.automationrepository.com/2012/03/qtp-framework-types-an-introduction/


2. How does vbscript function returns an array?
function ReturnArrayFunc()

	Dim aData(3)
	aData (0)="A"
	aData (1)="b"
	aData (2)="c"

	'populate  aData  with strings

	ReturnArrayFunc  = aData

End Function


val1=  ReturnArrayFunc ()
For i=0 To UBound(val1)
  MsgBox val1(i)
Next

3 .why do we use 'option explicit' ?
It is used to force the programmer to declare every variable before using it.
If you try to use an undeclared variable name, an error occurs at compile time i.e. when program is run.
If used, the Option Explicit statement must appear in a file before any other source code statements.
Reason for this forceful declaration is to avoid making any use of the variable which is not supposed to be used and is being used by mistake.

When it is used it warns programmer that a variable is being used somewhere in the code and it is unintentional, i.e. it has not been declared.

However there is one case where even after Option explicit is mentioned, vbs interpreter will not generate an error.
If a variable is being used inside a Execute statement, Option explicit will not be able to see it as it will be in the string format.
Example:
Option Explicit
Dim thisVar
thisVar = 10
'The following assignment produces 
'a run time error because 
'the variable ‘thisInt ‘ is not 
'declared and Option Explicit is used.
thisInt = 10 ' causes ERROR

'Variable used inside “execute” statement:
Option Explicit
Dim var1, var2, Sum
var1 = 1
var2 = 2
sum = var1 +var2
'even though temp is not declared, 
'no error will be generated
Execute "temp = Sum"
Execute "msgbox(temp)" 'Output as 3

4. How can we count the occurrence of one string into other string?
Dim myString, tempString, iHowManyTimes
myString ="This is a test is"
tempString = Split(myString, "is")
iHowManyTimes = UBound(tempString)
msgbox "There are " & iHowManyTimes & " occurences."

5. How will you know which addin should be selected for specific application?
1. Ask developer about the technology used for the Application under test.
2. If above is not possible than try to use all the available addins and see if QTP is able to identify.

6. What should be the Regular expression pattern to validate DOB field in format mm/dd/yyyy?
This covers any date with date format as mm/dd/yyyy, mm.dd.yyyy or mm-dd-yyyy

(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d

| pipe symbol indicates conditional or
[] indicates subset
\d indicates any digit
Lets break the segments for better explanation:

Month: (0[1-9]|1[012]) : month can be from 01 to 12.
Expression indicates:
That first digit can be a 0 and second digit of the month between 1-9.
To cover months: 01 till 09
Or
First digit can be 1 and second digit will be 0, 1 or 2
To cover months 10, 11 and 12.
[- /.] : To cover the date format i.e. mm/dd/yyyy, mm.dd.yyyy and mm-dd-yyyy

Date: (0[1-9]|[12][0-9]|3[01]

If first digit is 0 then second digit can be from 1-9
Or
If first digit is 1 or 2 then second digit can be from 0-9
To cover: 10-19 and 20 to 29
Or
If first digit is 3 than second digit can be 0 or 1
To cover 30 and 31

Year: (19|20)\d\d

First two digits as either 19 or 20 and second 2 digits can be any number
To cover year 1900 till 2099

7. How to convert objects from local OR to shared OR?
Using export option in local OR file.
Open Local OR. Click on File - Export Local Objects

Continued...