Apr 7, 2010

Selenium Interview Questions

Selenium Test Tool

Selenium is a set of tools that supports development of test automation for web-based applications. Selenium supports multiple browser platforms.

Selenium can be used for Functional and Performance Test Automation for web based Applications.

Selenium Components

Selenium is composed of three major tools. Each one has a specific role in aiding the development of web application test automation.

Selenium-IDE

Selenium-IDE is the Integrated Development Environment for building Selenium test cases.

Selenium-RC (Remote Control)

Selenium-RC allows the test automation developer to use a programming language for maximum flexibility and extensibility in developing test logic.
Selenium-RC provides an API (Application Programming Interface) and library for each of its supported languages: HTML, Java, C#, Perl, PHP, Python, and Ruby.

Selenium-Grid

Selenium-Grid allows the Selenium-RC solution to scale for large test suites or test suites that must be run in multiple environments.

Supported Browsers

o        Firefox 3.x, Firefox 3, Firefox 2

o        IE 8, IE 7, IE 6

o        Safari 4, Safari 3, Safari 2

o        Opera 10, Opera 9, Opera 8

              and Google Chrome

* Tests developed on Firefox via Selenium-IDE can be executed on any other supported browser via a simple Selenium-RC command line.
** Selenium-RC server can start any executable, but depending on browser security settings there may be technical limitations that would limit certain features.

Extensibility

Selenium is highly flexible. There are multiple ways in which one can add functionality to Selenium’s framework to customize test automation for one’s specific testing needs.
Selenium-IDE allows for the addition of user-defined “user-extensions” for creating additional commands customized to the user’s needs.

Selenium Interview Questions

1) What does SIDE stand for?
2) What is the difference between an assert and a verify with Selenium commands?
3) What Selenium commands can be used to help debug a regexp?
4) What is one big difference between SilkTest and Selenium, excluding the price?
5) Which browsers can Selenium IDE be run in?
6) If a Selenium function requires a script argument, what would that argument look like in general terms?
7) If a Selenium function requires a pattern argument, what five prefixes might that argument have?
8) What is the regular expression sequence that loosely translates to "anything or nothing?"
9) What is the globbing sequence that loosely translates to "anything or nothing?
10) What does a character class for all alphabetic characters and digits look like in regular expressions?
11)  What does a character class for all alphabetic characters and digits look like in globbing?
12)  What must one set within SIDE in order to run a test from the beginning to a certain point within the test?
13) What does a right-pointing green triangle at the beginning of a command in SIDE indicate?
14)  How does one get rid of the right-pointing green triangle?
15) How can one add vertical white space between sections of a single test?
16) What Selenium functionality uses wildcards?
17) Which wildcards does SIDE support?
18) What are the four types of regular expression quantifiers which we've studied?
19) What regular expression special character(s) means "any character?"
20) What distinguishes between an absolute and relative URL in SIDE?
21) How one access a Selenium variable would named "count" from within a JavaScript snippet?
22) What Selenese command can be used to display the value of a variable in the log file, which can be very valuable for debugging?
23) If one wanted to display the value of a variable named answer in the log file, what would the first argument to the previous command look like?
24)  Where did the name "Selenium" come from?
25)  Which Selenium command(s) simulates selecting a link?
26)  Which two commands can be used to check that an alert with a particular message popped up?
27) What does a comment look like in Column view?
28) What does a comment look like in Source view?
29) What are Selenium tests normally named (as displayed at the top of each test when viewed from within a browser)?
30) What command simulates selecting the browser's Back button?
31) If the Test Case frame contains several test cases, how can one execute just the selected one of those test cases?
32) What globbing functionality is NOT supported by SIDE?
33) What is wrong with this character class range? [A-z]
34) What are four ways of specifying an uppercase or lowercase M in a Selenese pattern?
35) What does this regular expression match?
36) regexp:[1-9][0-9],[0-9]{3},[0-9]{3}
37) What are two ways to match an asterisk within a Selenese regexp?
38) What is the generic name for an argument (to a Selenese command) which starts with //?
39) What Selenese command is used to choose an item from a list?
40) How many matches exist for this pattern?
41) regexp:[13579][02468]
42) What is the oddity associated with testing an alert?
43) How can one get SIDE to always record an absolute URL for the open command's argument?
44) What Selenese command and argument can be used to transfer the value of a JavaScript variable into a SIDE variable?
45) How would one access the value of a SIDE variable named name from within a JavaScript snippet used as the argument to a Selenese command?
46) What is the name of the type of JavaScript entity represented by the last answer?
47) What string(s) does this regular expression match?
48) regexp:August|April 5, 2010
49) What Selenium regular expression pattern can be used instead of the glob below to produce the same results?
50) verifyTextPresent | glob:9512?
51) What Selenium globbing pattern can be used instead of the regexp below to produce the same results?
52) verifyTextPresent | regexp:Hush.*GcReddy

Apr 5, 2010

VB Script syntax rules and guidelines


VBScript Syntax Rules and Guidelines

1) Case-sensitivity:

By default, VBScript is not case sensitive and does not differentiate between upper-case and lower-case spelling of words, for example, in variables, object and method names, or constants.

For example, the two statements below are identical in VBScript:

Browser("Mercury").Page("Find a Flight:").WebList("toDay").Select "31"
browser("mercury").page("find a flight:").weblist("today").select "31"

2) Text strings:

When we enter a value as a text string, we must add quotation marks before and after the string. For example, in the above segment of script, the names of the Web site, Web page, and edit box are all text strings surrounded by quotation marks.

Note that the value 31 is also surrounded by quotation marks, because it is a text string that represents a number and not a numeric value.

In the following example, only the property name (first argument) is a text string and is in quotation marks. The second argument (the value of the property) is a variable and therefore does not have quotation marks. The third argument (specifying the timeout) is a numeric value, which also does not need quotation marks.

Browser("Mercury").Page("Find a Flight:").WaitProperty("items count", Total_Items, 2000)

3) Variables:

We can specify variables to store strings, integers, arrays and objects. Using variables helps to make our script more readable and flexible

4) Parentheses:

 To achieve the desired result and to avoid errors, it is important that we use parentheses () correctly in our statements.

5) Indentation:

We can indent or outdent our script to reflect the logical structure and nesting of the statements.

6) Comments:

We can add comments to our statements using an apostrophe ('), either at the beginning of a separate line, or at the end of a statement. It is recommended that we add comments wherever possible, to make our scripts easier to understand and maintain.


7) Spaces:

We can add extra blank spaces to our script to improve clarity. These spaces are ignored by VBScript.
*****************************************


qtp real-time script example

QuickTest Professional is an Industry leading and famous Testing Tool for Functional & Regression Testing QTP uses VB Script for scripting
We can use QTP Tool features as well as VB Script Flow Control statements for inserting verification points.
If we want to use VB Script Flow Control statements for inserting flow control statements, then we need to define Test results.
QTP has provided a facility to define Test Results, using ‘Reporter’ Utility Object to define test results.
Using Comments is a best practice in QTP Scripting to understand the code.
Creating functions for modular code is a best practice and intelligent task in scripting /Programming.
using Automation Objects is an useful task in QTP scripting
using Built-in functions and regular expressions is an useful task.

QTP Scripting has several types:

a) GUI scripting: using scripting for GUI based Applications
b) Web scripting: Automation web based applications using vb script
c) Database scripting: Using scripting for Database operations such as data comparisons and validations.
d) Excel scripting: Handling and using Excel files in Test Automation

Excel Scripting Examples-2

1) Data Driven Testing for Login Operation by fetching from an excel file

Dim objExcel, myFile, mySheet
Set objExcel=CreateObject("Excel.Application")
Set myFile=objExcel.Workbooks.Open("C:\Documents and Settings\gcreddy\Desktop\data.xls")
Set mySheet=myFile.Worksheets("Sheet1")
Rows_Count=mySheet.usedrange.rows.count

For i= 2 to Rows_Count step 1
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("text:=Login").Activate
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set mySheet.Cells(i,"A")
Dialog("text:=Login").WinEdit("attached text:=Password:").Set mySheet.Cells(i,"B")
Wait (2)
Dialog("text:=Login").WinButton("text:=OK").Click
Window("text:=Flight Reservation").Close
Next

myFile.Close
objExcel.Quit
Set objExcel=Nothing
-----------------------------------------
2) Data Driven Testing for Login Operation by fetching Test Data from an excel file and Export Result to the Same file

Dim objExcel, myFile, mySheet
Set objExcel=CreateObject("Excel.Application")
Set myFile=objExcel.Workbooks.Open("C:\Documents and Settings\gcreddy\Desktop\data.xls")
Set mySheet=myFile.Worksheets("Sheet1")
Rows_Count=mySheet.usedrange.rows.count

For i= 2 to Rows_Count step 1
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("text:=Login").Activate
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set mySheet.Cells(i,"A")
Dialog("text:=Login").WinEdit("attached text:=Password:").Set mySheet.Cells(i,"B")
Wait (2)
Dialog("text:=Login").WinButton("text:=OK").Click

If Window("text:=Flight Reservation").Exist(12)  Then
Window("text:=Flight Reservation").Close
Result="Login Operation Sucessful"
mySheet.Cells(i,"C")=Result
Else
SystemUtil.CloseDescendentProcesses
Result="Login Operation Failed"
mySheet.Cells(i,"C")=Result
End If
Next
myFile.Save
myFile.Close
objExcel.Quit
Set objExcel=Nothing
------------------------------
3) 'Data Driven Testing for Login Operation by fetching Test Data from an excel file
' Export Result and Error message to the Same file
'
Dim objExcel, myFile, mySheet
Set objExcel=CreateObject("Excel.Application")
Set myFile=objExcel.Workbooks.Open("C:\Documents and Settings\gcreddy\Desktop\data.xls")
Set mySheet=myFile.Worksheets("Sheet1")
Rows_Count=mySheet.usedrange.rows.count

For i= 2 to Rows_Count step 1
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("text:=Login").Activate
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set mySheet.Cells(i,"A")
Dialog("text:=Login").WinEdit("attached text:=Password:").Set mySheet.Cells(i,"B")
Wait (2)
Dialog("text:=Login").WinButton("text:=OK").Click

If Window("text:=Flight Reservation").Exist(12)  Then
Window("text:=Flight Reservation").Close
Result="Login Operation Sucessful"
mySheet.Cells(i,"C")=Result
Else

Error_Message = Dialog("Login").Dialog("Flight Reservations").Static("Agent name must be at").GetROProperty("text")
SystemUtil.CloseDescendentProcesses
Result="Login Operation Failed"
mySheet.Cells(i,"C")=Result
mySheet.Cells(i,"D")=Error_Message
End If
Next
myFile.Save
myFile.Close
objExcel.Quit
Set objExcel=Nothing

------------------------------------------------------------------
4) 'Open 1 to 10 Orders in Flight Reservation window and capture Order Numbers and Customer Names

'Export to an Excel File
Dim objExcel,myFile,mySheet,i
Set objExcel = CreateObject("Excel.Application")
Set myFile=objExcel.Workbooks.Open("C:\Documents and Settings\gcreddy\Desktop\data.xls")
Set mySheet = myFile.Worksheets("Sheet2")
row=1
mySheet.Cells(row,"A")="OrderNo"
mySheet.Cells(row,"B")="CustomerName"

If Not Window("Flight Reservation").Exist(3)  Then
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "4d0a254623fcf8d10630f10b6ca8e776fcbc0717"
Dialog("Login").WinButton("OK").Click
End If
For  i = 1  to 10  Step 1
           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 i
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Customer_Name = Window("Flight Reservation").WinEdit("Name:").GetROProperty("text")
row=row+1
mySheet.Cells(row,"A") = i
mySheet.Cells(row,"B") = Customer_Name
Next
myFile.Save
myFile.Close
objExcel.Quit
Set objExcel =Nothing
---------------------------


Dynamic Handling of Object Repositories

Dynamic handling of object Repositories

Loading repositories during running, finding path of the repositories and removing repositories is called Dynamic Handling of Object Repositories.

Using this feature we can increase QTP performance. To do this, QTP is providing an object called “RepositoriesCollection”.

Syntax for Loading a Repository:
RepositoriesCollection.Add “Path of the Repository File”

Syntax for finding Position of the Repository:
Variable=RepositoriesCollection.Find(“Path of the Repository”)

Syntax for Removing the Repository:
RepositoriesCollection.Remove(position)

Syntax for Removing All Repositories:
RepositoriesCollection.RemoveAll

Example:
RepPath="C:\Documents and Settings\Administrator\My Documents\Login.tsr"
RepositoriesCollection.Add (RepPath)
systemutil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "sudhakar"
Dialog("Login").WinEdit("Password:").Set "mercury"
Dialog("Login").WinButton("OK").Click
pos=RepositoriesCollection.Find(RepPath)
RepositoriesCollection.Remove(pos)
RepositoriesCollection.RemoveAll
***********************************
Go to home page for QTP Guide, Script examples, Interview questions and Framework etc.
QTP Home Page

VB Script Properties

 VBScript Classes
 Creating Classes

Classes aren't a new concept in scripting. JavaScript, JScript, and other scripting languages have supported classes or similar elements for years. However, VBScript 5.0 is the first version of VBScript to support classes.

To use classes in your VBScript code, you first need to obtain VBScript 5.0 by downloading the appropriate self-executable file from the Microsoft Developer Network (MSDN) Web site (http://msdn.microsoft.com/scripting) or by installing Microsoft Internet Explorer (IE) 5.0. Then you need to understand what a VBScript class is and learn how to declare, define, initialize, and instantiate a class.

VBScript Classes 

VBScript 5.0 supports two types of objects: COM objects and Class objects (typically referred to as simply classes). VBScript COM objects have basic subtypes, such as an Integer or String. VBScript classes have an abstract subtype that encapsulates data and the functions to work with that data. You can think of a VBScript class as having a souped-up subtype that provides you with more computing power and flexibility. (Other differences exist between these two types of objects. For more information, see the Web-exclusive sidebar "How VBScript Classes and COM Objects Differ" on the Win32 Scripting Journal Web site at http://www.winntmag.com/ newsletter/scripting.

You can use classes to describe complex data structures. For example, if your application tracks customers and orders, you can define two classes for them, each with a unique set of internal data (typically called properties) and functions (typically called methods). You can then manage customers and orders as if they were native VBScript subtypes. More important, because you assign a class its properties and methods (i.e., its programming interface), you have an object-oriented tool to improve VBScript applications.

Declaring a Class 

You use the Class statement to declare a class. This statement's syntax is:

Class name
' Properties and methods go here.
End Class
where name is the name you give that class. You declare the properties and methods for your class between the Class and End Class clauses.

For example, suppose you want to create the VBScript class FileList, which Listing 1 contains. This class manages those files in a folder that meet a filename specification that you provide. You create this class by first specifying the keyword Class followed by the class' name Class FileList. Next, you declare the class' properties and methods. FileList has two properties (FileSpec and FolderPath) and one method (Search).

Declaring the FileSpec Property 

The FileSpec property holds the filename specification. For example, the filename specification might be C:\*.*. You want users to be able to freely read and write values to this property, so you declare FileSpec as an external, or public, variable with the Public statement

Public FileSpec

You can use a public variable in any script, not just the script in which you created the variable. However, if you use a public variable, you have no control over the value that users assign to the variable and no control over the value that the variable returns. Thus, you can't use public variables to hold values that you need to validate.

Declaring the FolderPath Property

The FolderPath property holds the full path to the folder containing the files. After a user sets a folder path, you need to validate that the folder exists, which means you can't use a public variable. Instead, you need to store the folder path in an internal, or private, variable and use two public property procedures to read and write to that variable. (Public property procedures are wrappers that hide the code that gets and sets the values of private variables.)

Prefixing a private variable with the m_ string is a common scripting convention. For example, the private variable for the FolderPath property is m_folderPath. To declare m_folderPath, you use the Private statement

Private m_folderPath

Procedures and variables that have the Private qualifier aren't visible outside the class. In addition, private variables apply only to the script in which you created them.

After you declare m_folderPath, you need to declare the two public property procedures that you'll use to read and write to that variable. The first procedure to declare is the Property Get procedure, which returns the values of properties. The second procedure is the Property Let procedure, which assigns values to properties.

To declare the Property Get procedure, you use the Property Get statement

Public Property Get FolderPath
    FolderPath = m_folderPath
End Property
where FolderPath is the name of that procedure. By including the Public statement with the Property Get statement, you're making the value that the FolderPath procedure returns available for public reading. Thus, by assigning FolderPath to m_folderPath, you make the value of m_folderPath available for public reading.

VB Script Objects

VB Script Objects 
a) FileSystemObject


Scripting allows us to process drives, folders, and files using the FileSystemObject (FSO) object model.

Creating FileSystemObject:

Set Variable=CreateObject("Scripting.FileSystemObject")
Example:

Dim objFso
Set objFso=CreateObject("Scripting.FileSystemObject")
objFso.CteateTextFile("D:\gcreddy.txt")

b) Dictionary


Creating Dictionary Object:

Set Variable=CreateObject("Scripting.Dictionary")
Example:

c) Excel Application



Creating Excel Object:

Set Variable=CreateObject("Excel.Application")
Example:

d) Word Application



Creating Word Object:

Set Variable=CreateObject("Word.Application")
Example:

e) Shell



Creating Shell Object:

Set Variable= WScript.CreateObject("Wscript.Shell")
Example:

f) Network



Creating Network Object:

Set Variable= WScript.CreateObject("WScript.Network")
Example:

g) PowerPoint



Creating PowerPointObject:

Set Variable=CreateObject("PowerPoint.Application")
Example:

h) ADODB Connection



The ADO Connection Object is used to create an open connection to a data source. Through this connection, you can access and manipulate a database.


Creating Database Connection Object:

Set Variable=CreateObject("ADODB.Connection")
Example:

i) ADODB RecordSet


The ADO Recordset object is used to hold a set of records from a database table. A Recordset object consist of records and columns (fields).


Creating Database RecordSet Object:

Set Variable=CreateObject("ADODB.RecordSet")
Example:

j) ADODB Command


The ADO Command object is used to execute a single query against a database. The query can perform actions like creating, adding, retrieving, deleting or updating records.


Creating Database Command Object:

Set Variable=CreateObject("ADODB.Command")
Example:

k) Error 



Creating Error Object:

l) RegExp 


 Creating RegExp Object:


Set objReg=CreateObject("vbscript.regexp")

m) Internet Explorer




n) Outlook Express


 
a) Dictionary Object

 Dictionary Object that stores data key, item pairs.

A Dictionary object is the equivalent of a PERL associative array/Hash Variable. Items can be any form of data, and are stored in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually an integer or a string, but can be anything except an array.




Creating a Dictionary Object:

Set objDictionary = CreateObject("Scripting.Dictionary") 
Dictionary Objects Methods: 


Add Method 

Adds a key and item pair to a Dictionary object

Exists Method

Returns true if a specified key exists in the Dictionary object, false if it does not.

Items Method

Returns an array containing all the items in a Dictionary object.

Keys Method

Returns an array containing all existing keys in a Dictionary object.

Remove Method

Removes a key, item pair from a Dictionary object.

RemoveAll Method

The RemoveAll method removes all key, item pairs from a Dictionary object.
 

Example:


Dim cities
Set cities = CreateObject("Scripting.Dictionary")
cities.Add "h", "Hyderabad"
cities.Add "b", "Bangalore"
cities.Add "c", "Chennai"



Dictionary Objects Properties:
Count Property

Returns the number of items in a collection or Dictionary object. Read-only.

CompareMode Property
Sets and returns the comparison mode for comparing string keys in a Dictionary object.

Key Property

Sets a key in a Dictionary object.

Item Property
Sets or returns an item for a specified key in a Dictionary object. For collections, returns an item based on the specified key. Read/write.

 

Examples:


1) Add Elements to a Dictionary


Set
objDictionary=CreateObject("Scripting.Dictionary")

objDictionary.Add
"Printer1","Printing"   
objDictionary.Add
"Printer2","Offline"
objDictionary.Add
"Printer3","Printing"

2) Delete All Elements from a Dictionary

Set
objDictionary=CreateObject("Scripting.Dictionary")


objDictionary.Add
"Printer1","Printing"   
objDictionary.Add
"Printer2","Offline"
objDictionary.Add
"Printer3","Printing"
colKeys
=objDictionary.Keys

Wscript.Echo
"Firstrun:"
For
EachstrKeyincolKeys
    Wscript.EchostrKey
Next

objDictionary.RemoveAll
colKeys
=objDictionary.Keys

Wscript.Echo
VbCrLf&"Secondrun:"
For
EachstrKeyincolKeys
    Wscript.EchostrKey
Next

3) Delete One Element from a Dictionary

Set objDictionary = CreateObject("Scripting.Dictionary")

objDictionary.Add "Printer 1", "Printing"  
objDictionary.Add "Printer 2", "Offline"
objDictionary.Add "Printer 3", "Printing"

colKeys = objDictionary.Keys

Wscript.Echo "First run: "
For Each strKey in colKeys
    Wscript.Echo strKey
Next

objDictionary.Remove("Printer 2")
colKeys = objDictionary.Keys

Wscript.Echo VbCrLf & "Second run: "
For Each strKey in colKeys
    Wscript.Echo strKey
Next

4) List the Number of Items in a Dictionary


Set
objDictionary=CreateObject("Scripting.Dictionary")

objDictionary.Add
"Printer1","Printing"   
objDictionary.Add
"Printer2","Offline"
objDictionary.Add
"Printer3","Printing"
Wscript.Echo
objDictionary.Count


5) Verify the Existence of a Dictionary Key

Set objDictionary = CreateObject("Scripting.Dictionary")

objDictionary.Add "Printer 1", "Printing"  
objDictionary.Add "Printer 2", "Offline"
objDictionary.Add "Printer 3", "Printing"

If objDictionary.Exists("Printer 4") Then
    Wscript.Echo "Printer 4 is in the Dictionary."
Else
    Wscript.Echo "Printer 4 is not in the Dictionary."
End If