TESTEVERYTHING

Friday 2 December 2011

Selenium disable add-ons pop-up for Custom firefox profile

Here is the way to disable add-ons window which appears every time when selenium scripts are run on Custom Firefox Profile.


Close all instances of Firefox browser and delete the following files from the Custom Profile folder, this should reset Extension Manager and disable add-ons pop-up:
  • extensions.cache
  • extensions.ini
  • extensions.rdf
  • compatibility.ini
This Add-ons pop-up will not displayed the next time you run selenium scripts.

To find the Firefox profile,  type in cmd run prompt "%APPDATA%\Mozilla\Firefox\Profiles\"  press enter

Thursday 1 December 2011

Tips to Decide What Test Cases to Automate

It is impossible to automate all testing; the first step to successful automation is to determine what test cases should be automated first.

The benefit of automated testing is correlated with how many times a given test can be repeated. Tests that are only performed a few times are better left for manual testing. Good test cases for automation are those that are run frequently and require large amounts of data to perform the same action.


You can get the most benefit out of your automated testing efforts by automating:

  •       Repetitive tests that run for multiple builds
  •    Tests that are highly subject to human error
  •      Tests that require multiple data sets
  •        Frequently-used functionality that introduces high risk conditions
  •        Tests that run on several different hardware or software platforms and configurations
  •        Tests that take a lot of effort and time when doing manual testing

Saturday 15 October 2011

Vi - Linux Editor Commands

Common vi Commands
Have a look at this list of common vi commands (there are many more, but these will at least allow you to get some basic work done). Then we'll do one more exercise before moving on.
Note: As with all of Linux, vi commands are case sensitive.
Positioning the Cursor
Move cursor one space right.
Move cursor one space left.
Move cursor up one line.
Move cursor down one line.
ctrl-F Move forward one screen.
ctrl-B Move backward one screen.
$ Move cursor to end of line.
^ Move cursor to beginning of line.
:1 Move to first line of file
:$ Move to last line of file
/ Search for a character string.
? Reverse search for a character string.
x Delete the character at the cursor position.
dd Delete the current line.
p Paste data that was cut with x or dd commands.
u Undo.

Basic UNIX Commands

Directory
::
Show current directory
pwd
Show content of directory
ls -al
Changing directory
cd <newdir>
Creating directory
mkdir <dir>
Deleting directory if empty
rmdir <dir>
Deleting directory if full
rm -r <dir>
Moving directory
mv <olddir> <newdir>
Copy directory
cp -r <olddir> <newdir>
Files
::
Show file entry
ls -al <file>
Delete file
rm -i <file>
Move file
mv <file> <path>
Copy file
cp <file> <newfile>
Rename file
mv <oldfile> <newfile>
Show file content at once
cat <file>
Show file content page wise
more <file>
Show file with long lines
cat <file> | fold
Show first 20 lines of file
head -20 <file>
Show last 20 lines of file
tail -20 <file>
Edit file
<editorname> <file>
Edit file with vi
vi <file>
Give all file permissions to yourself
chmod 700 <file>
The above even into subdirectories
chmod -R 700 <dir>
Open file for reading and executing for all
chmod 644 <file>
Starting file as program
<filneame> <arguments>
Find word in file
grep <word> <file>
Find all files which contain a word
grep -l <word> *
Find abstract pattern: ab 2 digits cd
grep 'ab[0-9][0-9]cd' <file>
Comparing two files
diff <file1> <file2>
Updating the date of a file
touch <file>
Giving a specific date to a file
touch 0101010199 <file>
Help
::
Getting help about a command
man <command>
Find command related to a term
man -k <term>
Where is a particular program if it is in the path
which <commandname>
Is a <name> a unix command or an alias in ksh
whence <commandname>
Aliases
::
Making an alias in csh/tcsh
alias <aliasname> '<long_command>'
Making an alias where the arguments go in the middle
alias <aliasneme> '<command> \!* <other>'
Making an alias in sh/bash/ksh
alias <aliasname>='<long_command>'
Using an alias
<aliasname> <arguments>
Use command instead of it's alias
\<command>
Showing all aliases
alias
Remove an alias
unalias <aliasname>
Adjustments
::
See environment variables
env
Setting the term variable if vi doesn't work
setenv term vt100
Opening the X-server for X-clients
xhost +
Setting the display for X-clients
setenv display <computer>:0.0
Internet
::
Telnet to another computer
telnet <computername>
Rlogin to another computer
rlogin -l <username_there> <computername>
Browsing the net with netscape
netscape
Check whether someone is logged in somwhere
finger user@host.domain
Check for all people on another computer
finger @host.domain
Talk to another person on another computer
talk user@host.domain
Ftp building up connection
ftp <computername>
Ftp adjusting for binary transfer
>bin
Ftp showing directory
>dir
Ftp changing directory
>cd /<path>/<path>
Ftp getting a file
>get <file>
Ftp getting multiple files
>mget <filenamecommon>*
Ftp searching for a file
>quote site find <filename>
Get the ip number of a computer
nslookup <computername>
Check whether another computer is up
ping <computername>
Check the pathway to another computer
traceroute <computername>
Info about Unix System
::
See who is logged on
who ... w ... what
Get the date
date
See who logged in lately
last -20
See what operating system is there
uname -a
See who you are
whoami
Get the name of your computer
hostname
See the disk space used
df -k
See you quota usage
quota -v
See how much space all your files need
du -k
Mail
::
Check for mail
from
Read mail
Mail
Compose mail
Mail -s <subject> <mailaddress>
Mail a whole file ( one "<" is real )
Mail -s <subject> <mailaddr> < <file>
Compressing Files
::
Compress 50%
compress <file>
Uncomress the above file.Z
uncompress <file>.Z
Compress 70%
gzip <file>
Uncompress the above file.gz
gzip -d <file>.gz

Saturday 17 September 2011

How to Use the VBScript RegExp Object

 

Hi All,

I faced a situation where I had to update the field’s value from another file. I can not use the string replace method because It will replace the all the matches value, While I want to replace the first match with the first value of another file.  Here I am trying to explain

First File Contents:

This blog refers to QTP.
I want to get first line value "="  from another file.
Here I am using Rexexp
with global property value false
Now I want to get Second line value "="  from another file.
Global property false will serach only first match
If regexp global property true then it search all the matches
Now I want to get Third line value "="  from another file.


Second File Contents:

Rajiv
Kumar
Nandvani


I want output like this:

This blog refers to QTP.
I want to get first line value "Rajiv"  from another file.
Here I am using Rexexp
with global property value false
Now I want to get Second line value "Kumar"  from another file.
Global property false will serach only first match
If regexp global property true then it search all the matches
Now I want to get Third line value "Nandvani"  from another file.



Here is the code that I used to solve this problem

Function GetReplaceFirstMatch(PatternToMatch, byref StringToSearch,valuetoreplace)
 Set myRegExp = New RegExp
 myRegExp.IgnoreCase = True
 myRegExp.Global = False
 myRegExp.Pattern = PatternToMatch

 GetReplaceFirstMatch = myRegExp.Replace(StringToSearch,valuetoreplace)

end Function
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")


Set objFile = objFSO.OpenTextFile("C:\FirstFile.txt", ForReading)
subjectString= objFile.ReadAll

Set objTestFile = objFSO.OpenTextFile("C:\SecondFile.txt", ForReading)


Do Until objTestFile.AtEndOfStream

    strLineRead = objTestFile.ReadLine
            subjectString = GetReplaceFirstMatch("=",subjectString,strLineRead)
           

Loop
const ForWriting = 2
Set objResultFile = objFSO.CreateTextFile("C:\resultTestfile.txt", ForWriting)

objResultFile.write subjectString

How to Use the VBScript RegExp Object

You can use regular expressions in VBScript by creating one or more instances of the RegExp object. This object allows you to find regular expression matches in strings, and replace regex matches in strings with other strings. The functionality offered by VBScript's RegExp object is pretty much bare bones. However, it's more than enough for simple input validation and output formatting tasks typically done in VBScript.
The advantage of the RegExp object's bare-bones nature is that it's very easy to use. Create one, put in a regex, and let it match or replace. Only four properties and three methods are available.
After creating the object, assign the regular expression you want to search for to the Pattern property. If you want to use a literal regular expression rather than a user-supplied one, simply put the regular expression in a double-quoted string. By default, the regular expression is case sensitive. Set the IgnoreCase property to True to make it case insensitive. The caret and dollar only match at the very start and very end of the subject string by default. If your subject string consists of multiple lines separated by line breaks, you can make the caret and dollar match at the start and the end of those lines by setting the Multiline property to True. VBScript does not have an option to make the dot match line break characters. Finally, if you want the RegExp object to return or replace all matches instead of just the first one, set the Global property to True.
'Prepare a regular expression object
Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = "regex"
After setting the RegExp object's properties, you can invoke one of the three methods to perform one of three basic tasks. The Test method takes one parameter: a string to test the regular expression on. Test returns True or False, indicating if the regular expression matches (part of) the string. When validating user input, you'll typically want to check if the entire string matches the regular expression. To do so, put a caret at the start of the regex, and a dollar at the end, to anchor the regex at the start and end of the subject string.
The Execute method also takes one string parameter. Instead of returning True or False, it returns a MatchCollection object. If the regex could not match the subject string at all, MatchCollection.Count will be zero. If the RegExp.Global property is False (the default), MatchCollection will contain only the first match. If RegExp.Global is true, Matches> will contain all matches.
The Replace method takes two string parameters. The first parameter is the subject string, while the second parameter is the replacement text. If the RegExp.Global property is False (the default), Replace will return the subject string with the first regex match (if any) substituted with the replacement text. If RegExp.Global is true, Replace will return the subject string with all regex matches replaced.
You can specify an empty string as the replacement text. This will cause the Replace method to return the subject string will all regex matches deleted from it. To re-insert the regex match as part of the replacement, include $& in the replacement text. E.g. to enclose each regex match in the string between square brackets, specify [$&] as the replacement text. If the regexp contains capturing parentheses, you can use backreferences in the replacement text. $1 in the replacement text inserts the text matched by the first capturing group, $2 the second, etc. up to $9. To include a literal dollar sign in the replacements, put two consecutive dollar signs in the string you pass to the Replace method.

Getting Information about Individual Matches

The MatchCollection object returned by the RegExp.Execute method is a collection of Match objects. It has only two read-only properties. The Count property indicates how many matches the collection holds. The Item property takes an index parameter (ranging from zero to Count-1), and returns a Match object. The Item property is the default member, so you can write MatchCollection(7) as a shorthand to MatchCollection.Item(7).
The easiest way to process all matches in the collection is to use a For Each construct, e.g.:
' Pop up a message box for each match
Set myMatches = myRegExp.Execute(subjectString)
For Each myMatch in myMatches
  msgbox myMatch.Value, 0, "Found Match"
Next
The Match object has four read-only properties. The FirstIndex property indicates the number of characters in the string to the left of the match. If the match was found at the very start of the string, FirstIndex will be zero. If the match starts at the second character in the string, FirstIndex will be one, etc. Note that this is different from the VBScript Mid function, which extracts the first character of the string if you set the start parameter to one. The Length property of the Match object indicates the number of characters in the match. The Value property returns the text that was matched.
The SubMatches property of the Match object is a collection of strings. It will only hold values if your regular expression has capturing groups. The collection will hold one string for each capturing group. The Count property indicates the number of string in the collection. The Item property takes an index parameter, and returns the text matched by the capturing group. The Item property is the default member, so you can write SubMatches(7) as a shorthand to SubMatches.Item(7). Unfortunately, VBScript does not offer a way to retrieve the match position and length of capturing groups.
Also unfortunately is that the SubMatches property does not hold the complete regex match as SubMatches(0). Instead, SubMatches(0) holds the text matched by the first capturing group, while SubMatches(SubMatches.Count-1) holds the text matched by the last capturing group. This is different from most other programming languages. E.g. in VB.NET, Match.Groups(0) returns the whole regex match, and Match.Groups(1) returns the first capturing group's match. Note that this is also different from the backreferences you can use in the replacement text passed to the RegExp.Replace method. In the replacement text, $1 inserts the text matched by the first capturing group, just like most other regex flavors do. $0 is not substituted with anything but inserted literally.


VBScript Find First Match By Regular Expression Utility Function


' Get the first regex submatch from the string
' Returns empty string if not found, otherwise returns the matched string
Function GetFirstMatch(PatternToMatch, StringToSearch)
 Dim regEx, CurrentMatch, CurrentMatches

 Set regEx = New RegExp
 regEx.Pattern = PatternToMatch
 regEx.IgnoreCase = True
 regEx.Global = True
 regEx.MultiLine = True
 Set CurrentMatches = regEx.Execute(StringToSearch)

 GetFirstMatch = ""
 If CurrentMatches.Count >= 1 Then
  Set CurrentMatch = CurrentMatches(0)
  If CurrentMatch.SubMatches.Count >= 1 Then
   GetFirstMatch = CurrentMatch.SubMatches(0)
  End If
 End If
 Set regEx = Nothing
End Function

' Example
' Parse out the database name from a SQL server database connection string
Function GetDatabaseName(ByVal DSNString)
 GetDatabaseName = GetFirstMatch(".*Initial Catalog=(.*);", DSNString)
End Function

VBScript Replace All Matches By Regular Expression Utility Function


' Replace all matches in the string with the replacement text
Sub ReplaceAllByExpression(ByRef StringToExtract, ByVal MatchPattern, _
 ByVal ReplacementText)
 Dim regEx, CurrentMatch, CurrentMatches

 Set regEx = New RegExp
 regEx.Pattern = MatchPattern
 regEx.IgnoreCase = True
 regEx.Global = True
 regEx.MultiLine = True
 StringToExtract = regEx.Replace(StringToExtract, ReplacementText)
 Set regEx = Nothing

End Sub

' Example
' Remove all images from an HTML page
ReplaceAllByExpression HTMLPageData, "<img[^<]*?>", "" 
 

Monday 5 September 2011

VB Script Data Types


VB Script Data Types


What is Data Type?


Data type is a categorization of identifying one of various types of data, such as string, integer, double, date or Boolean etc…

Implicit & Explicit Data types:

Specifying Data types along with variable names is called Explicit declaration of Data types.

Declaring Variables Without specifying Data types is called Implicit declaration of variables.

VB Script Supports Implicit declaration of variables only, doesn’t support Explicit declaration of Data types.

VB Script Data Type:

VB script has only data type called Variant, it can hold any type of data, and based on usage of data it considers data sub types.

Example:

Dim x

X is a Variable and it can hold any type of data (String, integer, double, date etc…)

X= “G C Reddy” ‘String type

X= 100 ‘Integer

X= 10.345 ‘Double


X=#10/10/2010# ‘Date

 How to know Data sub types:

Using VarType Function we can get data sub type

VarType Function

It returns a value indicating a subtype of a Variable

Example:

'Checking Data sub types
-----------------------------
Dim x, y, z(3)
x="Gcreddy"
Msgbox VarType(x) '8 for String


x=500
Msgbox VarType(x) ' 2 for Integer

x="400"
Msgbox VarType(x) '8 for String

x=199.123
Msgbox VarType(x) '5 for double

x="199.123"
Msgbox VarType(x) '8 for string


x=#10/10/2010#
Msgbox VarType(x) '7 for date

Set x =CreateObject("Scripting.FileSystemObject")
Msgbox VarType(x) '9 for Automation Object

x=384322225
Msgbox VarType(x) ‘3 for Long integer

Msgbox VarType(z) ‘8204 for Array

Msgbox VarType(y) '0 for Empty / Uninitialized

-------------------------------------------------------------------------------------
Data sub type and descriptions:

String:

It consists of any type of characters, maximum length up to approximately 2 billion characters.

Boolean:
It Contains either True or False (Logical Result)

Empty:

Uninitialized, Value is 0 for numeric variables or a zero-length string ("") for string variables.

Integer:

Contains integer in the range -32,768 to 32,767

Long Integer

Contains integer in the range -2,147,483,648 to 2,147,483,647

Double:
Contains a double-precision, floating-point number in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.

Date:

Contains a number that represents a date between January 1, 100 to December 31, 9999

Object:

Contains an object


Error:


Contains an error number

Null:

Contains no valid data

Etc…
------------------------------------------------------------------------------------

'Converting the Data from one type to another
-----------------------------------------------
We use Conversion Functions to convert the data from one type to another.


Whenever we read data using input devices, or from files, or from Databases or from Application objects then VB Script considers the data as string type data, we need to convert the data in order to perform operations.

Dim x, y, Tickets, Price
'Read from Input Devices
x=InputBox("Enter a Value")
Msgbox VarType(x) '8 for String
x=Cint(x)
Msgbox VarType(x) '2 for Integer


y=InputBox("Enter a Value")
Msgbox VarType(y) '8 for String
y=Cdbl(y)
Msgbox VarType(y) '5 for double

'Read from Application Objects

Tickets = Window("Flight Reservation").WinEdit("Tickets:").GetVisibleText()
Msgbox VarType(Tickets)'8
Tickets=Cint(Tickets)
Msgbox VarType(Tickets) '2


Price = Window("Flight Reservation").WinEdit("Price:").GetVisibleText()
Msgbox VarType(Price) '8
Price=Cdbl(Price)
Msgbox VarType(Price) '5

----------------------------------------------------------------------
Example: 2
Dim a, b, c

a=”100”
Msgbox VarType(a) ‘ 8 for String

a=Cint(a)
Msgbox VarType(a) ‘2 for Integer

b=”100.345”
Msgbox VarType(b) ‘ 8 for String

b=Cdbl(b)
Msgbox VarType(b) ‘5 for Double

c=”Hyderabad”
Msgbox VarType(c) ‘8 for String

c=Cint(c)
Msgbox VarType(c) ‘Mismatch (Error)


Note: we can’t convert alphabets as integer or double type data

Source...
G C Reddy

Which one is right ?

Translate







Tweet