Saturday, 10 August 2013

Overview of Common Unix - Shell Features

Overview of common shell features. The following features are standard in every shell. List is as follows -
Command Meaning
> Redirect output
>> Append to file
< Redirect input
<< "Here" document (redirect input)
| Pipe output
& Run process in background.
; Separate commands on same line
* Match any character(s) in filename
? Match single character in filename
[ ] Match any characters enclosed
( ) Execute in subshell
` ` Substitute output of enclosed command
" " Partial quote (allows variable and command expansion)
' ' Full quote (no expansion)
\ Quote following character
$var Use value for variable
$$ Process id
$0 Command name
$n nth argument (n from 0 to 9)
$* All arguments as a simple word
# Begin comment
bg Background execution
break Break from loop statements
cd Change directories
continue Resume a program loop
echo Display output
eval Evaluate arguments
exec Execute a new shell

How to Format Floppy on a Linux

Command to format floppy drive –
emma:~> fdformat /dev/fd0H1440
Double-sided, 80 tracks, 18 sec/track. Total capacity 1440 kB.
Formatting … done
Verifying … done
emma:~>
fdformat is the low-level floppy disk formatting tool. It has the device name of the floppy disk as an option. fdformat will display an error when the floppy is write-protected.
The mformat command (from the mtools package) is used to create DOS-compatible floppies which can then be accessed using the mcopy, mdir and other m-commands.
After the floppy is formatted, it can be mounted into the file system and accessed as a normal, be it small, directory, usually via the /mnt/floppy entry.

How to Dump Data in Linux System (dd Command)

The dd command can be used to put data on a disk, or get it off again, depending on the given input and output devices. An example:
gaby:~> dd if=images-without-dir.tar.gz of=/dev/fd0H1440
98+1 records in
98+1 records out
gaby~> dd if=/dev/fd0H1440 of=/var/tmp/images.tar.gz
2880+0 records in
2880+0 records out
gaby:~> ls /var/tmp/images*
/var/tmp/images.tar.gz
Note that the dumping is done on an unmounted device. Floppies created using this method will not be mountable in the file system, but it is of course the way to go for creating boot or rescue disks. For more information on the possibilities of dd, read the man pages.

Converting Object Repository Based Scripts to Descriptive Programming

Here we discuss how we can convert an Object repository based script to DP based script. For this we will do a simple recording of entering some text on Google.com search text box and clicking the
Google search button
The QTP generated script would look something like below
SystemUtil.Run “C:\Program Files\Internet Explorer\IEXPLORE.EXE”
Browser(”Browser”).Page(”Page”).Sync
Browser(”Browser”).Navigate “http://www.google.com”
Browser(”Browser”).Page(”Google”).WebEdit(”q”).Set “KnowledgeInbox”
Browser(”Browser”).Page(”Google”).WebButton(”Google Search”).Click
All the names used between “” are logical name of the objects in the Object Repository (”Browser”, “Page”, “Google”, “q”, “Google Search”) and are stored in object repository.
Now let’s look the below statement and try and convert it to DP
Browser(”Browser”).Page(”Google”).WebButton(”Google Search”).Click
Converting WebButton(”Google Search”)
The Google Search object present in the OR has following properties
type = submit
name = Google Search
html tag = INPUT
Now to conver the WebButton(”Google Search”) to its DP counterpart we can use two different methods
Method 1 – Using String Description
In this we use string parameters to specify the object properties
Browser(”Browser”).Page(”Google”).WebButton(”type:=Submit”, _
“name:=Google Search”, “html tag:=INPUT”).Click
Method 2 – Using Object Description
In this we first create a description of the object and then use it in the statement
Set oGoogleSearch = Descrition.Create
oGoogleSearch(”type”).Value = “Submit”
oGoogleSearch(”name”).Value = “Google Search”
oGoogleSearch(”html tag”).Value = “INPUT”
Browser(”Browser”).Page(”Google”).WebButton(oGoogleSearch).Click
Difference between string description and Object Description -
String Description
– Uses less memory as strings are used
– Increases statement length in case more than one property is to be used.
– Preferred when property value have regular expression characters which needs to be treated
literally
Object Description
– Requires more memory as objects are created.
– Object creation is as such a overhead
– Increase lines of code due to object creation overhead and property
assignment
DP Converted script
SystemUtil.Run “C:\Program Files\Internet Explorer\IEXPLORE.EXE”
Browser(”micclass:=Browser”).Page(”Page”).Sync
Browser(”micclass:=Browser”).Navigate “http://www.google.com”
Browser(”micclass:=Browser”).Page(”micclass:=Page”).WebEdit(”name:=q”).Set _
“KnowledgeInbox”
Browser(”micclass:=Browser”).Page(”micclass:=Page”) _
.WebButton(”type:=Submit”, “name:=Google Search”, “html tag:=A”).Click

QTP and Python Training Materials

Please visit http://www.onestopqa.com for tutorials on QTP and Python.