Wednesday, June 16, 2010

How to run qtp from CMD

Write the Vbs script and execute it from CMD using cscript orWscript

Sample Vbscript as follow

Set qtApp= CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible = True

'And then call your scripts one after another
qtApp.Open "Enter Complete path for script here"
qtApp.Test.Run
'and once you are done then close the QTP with the following :

qtApp.Quit

Monday, June 14, 2010

Vbscript to get detail information of any file

 Vbscript to get detail information of any file

Dim filesys, demofile, createdate
Set filesys = CreateObject("Scripting.FileSystemObject")


Set demofile = filesys.GetFile("e:\TEST.xls")
createdate = demofile.DateCreated
WScript.Echo (createdate)
strHomeFolder = "E:\QTP"
Set objShell = CreateObject("Wscript.Shell")
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FolderExists (strHomeFolder) Then
' Assign user permission to home folder.
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder & " /t /c /g Administrators:F ", 2, True)
WScript.Echo (intRunError)
   If intRunError <> 0 Then
   Wscript.Echo "Error assigning permissions for user " & strUser & " to home folder " & strHomeFolder
   Else
   Wscript.Echo "In inner loop"
   End If
Else
Wscript.Echo "In Outer loop"
End If


WScript.Echo (demofile.Attributes)
'WScript.Echo (demofile.Type)
'WScript.Echo "Date created: " & demofile.DateCreated
'Wscript.Echo "Date last accessed: " & demofile.DateLastAccessed
'Wscript.Echo "Date last modified: " & demofile.DateLastModified
'Wscript.Echo "Drive: " & demofile.Drive
'Wscript.Echo "Name: " & demofile.Name
'Wscript.Echo "Parent folder: " & demofile.ParentFolder
'Wscript.Echo "Path: " & demofile.Path
'Wscript.Echo "Short name: " & demofile.ShortName
'Wscript.Echo "Short path: " & demofile.ShortPath
'Wscript.Echo "Size: " & demofile.Size
'Wscript.Echo "Type: " & demofile.Type




WScript.Quit

Sunday, June 13, 2010

Sample of VB script with class

Class Hello_World

Public Sub Say_Hello(Name)
MsgBox "Hello, " & Name & ", welcome to " & Garden & "."
End Sub
Public Garden
End Class

Dim MyHello_World

Set MyHello_World = New Hello_World

MyHello_World.Garden = "Fountain"
MyHello_World.Say_Hello "Sachin"
MyHello_World.Garden = "Foun" 

VB scripts to play with file

Script to read a file using while loop.

#!/usr/local/ActivePerl-5.8/bin/perl
if (open(MYFILE, "file1")) {
$line = ;
while ($line ne "") {
print ($line);
$line = ;
}
}

Script to write in a file

#!/usr/local/bin/perl
open (MYPIPE, "cat >hello");
print MYPIPE ("Hi, Dave! Your Perl program sent this!\n");

close (MYPIPE); 


Script to search specific word from the file.

#!/usr/local/bin/perl
print ("Word to search for $ARGV[0]\n");
$filecount = 1;
$totalwordcount = 0;

while ($filecount <= @ARGV-1) {
unless (open (INFILE, $ARGV[$filecount]))
{
die ("Can't open input file $ARGV[$filecount]\n");
            }
            $wordcount = 0;
            while ($line = )
            {
                        chop ($line);
                        print ("Before split : $line\n");
                        @words = split(/ /, $line);
                        print ("Content is : @words\n");
                        $w = 1;
                        while ($w <= @words) {
                                    if ($words[$w-1] eq $ARGV[0]) {
                                                $wordcount += 1;
                                    }
                                    $w++;
                                    }
            }         
}

print ("total number of occurrences $totalwordcount\n");

' Script to create a instant of existing file and list out the complete information of the same

Dim filesys, demofile, createdate

Set filesys = CreateObject("Scripting.FileSystemObject")
Set demofile = filesys.GetFile("e:\TEST.xls")

createdate = demofile.DateCreated
WScript.Echo (createdate)

strHomeFolder = "E:\QTP"

Set objShell = CreateObject("Wscript.Shell")
Set filesys = CreateObject("Scripting.FileSystemObject")

If filesys.FolderExists (strHomeFolder) Then
            ' Assign user permission to home folder.
            intRunError = objShell.Run("%COMSPEC% /c Echo Y
            cacls " & strHomeFolder & " /t /c /g Administrators:F ", 2, True)
            WScript.Echo (intRunError)

            If intRunError <> 0 Then
                               Wscript.Echo "Error assigning permissions for user " & strUser & " to home folder " & strHomeFolder
            Else
       Wscript.Echo "In inner loop"
            End If
End if



WScript.Echo (demofile.Attributes)
WScript.Echo (demofile.Type)
WScript.Echo "Date created: " & demofile.DateCreated
Wscript.Echo "Date last accessed: " & demofile.DateLastAccessed
Wscript.Echo "Date last modified: " & demofile.DateLastModified
Wscript.Echo "Drive: " & demofile.Drive
Wscript.Echo "Name: " & demofile.Name
Wscript.Echo "Parent folder: " & demofile.ParentFolder
Wscript.Echo "Path: " & demofile.Path
Wscript.Echo "Short name: " & demofile.ShortName
Wscript.Echo "Short path: " & demofile.ShortPath
Wscript.Echo "Size: " & demofile.Size
Wscript.Echo "Type: " & demofile.Type

WScript.Quit

' Script to write in the file and read using loop
' Also to get the version detail of vbscript.

Dim filesys, text, readfile, contents

set filesys = CreateObject("Scripting.FileSystemObject")
Set text = filesys.CreateTextFile("c:\test.txt")

text.Write "Find the last character in the text file"
text.Write " '
text.Write "Find the last character in the text fil"
text.Close

Set readfile = filesys.OpenTextFile("c:\somefile2.txt", 1, false)
Do while readfile.AtEndOfLine <> true 'Condition to get end letter of first line'

'Do while readfile.AtEndOfStream <> true 'Condition to get end letter of file'
        contents = readfile.Read(1)
'WScript.Echo contents 'Print all the letter for file'
Loop
readfile.close

'Response.Write "The last character in the text file is '" & contents & "."
WScript.Echo "The last character in the text file is '" & contents & "."
WScript.Echo ScriptEngine
WScript.Echo ScriptEngineBuildVersion
WScript.Echo ScriptEngineMajorVersion
WScript.Echo ScriptEngineMinorVersion
WScript.Echo Second(Time)
WScript.Echo Tan(55.0)

Perl Script to send mail

#!E:\Perl\bin -w
use MIME::Lite;
MIME::Lite->send('smtp', "mailtesthub.gmail.com", Timeout=>90);

my $MailFrom = 'test@gmail.com';
my $to_list = 'john@gmail.com';
my $cc_list = 'frank@yahoo.com';
my $subject = "hello test";
my $message = "This email was generated automatically.";

my $msg = MIME::Lite->new(
From => $MailFrom,
To => $to_list,
Cc => $cc_list,
Subject => $subject,
Type => 'TEXT',
Encoding => '7bit',
Data => $message,
);


$msg->send()

Friday, June 11, 2010

How to specify the environment variables to be loaded when QTP is started

You can either define individual values in the .vbs file or specify an environment file to load.

Example:
Here is what the .vbs file could look like:

Dim App ‘As Application
‘ Launch QTP
Set App = CreateObject(“QuickTest.Application”)
App.Launch
App.Visible = True

‘ Load an INI file with user-defined parameters
App.Test.Environment.LoadFromFile “C:\Test_Params\environment_file1.ini”

‘ Set the value of a specific user-defined Environment variable
App.Test.Environment.Value(“newvariable”) = “new value”

As you can see from the example, the Environment variable file is actually an .ini file. The structure would be:
[Environment]
var1=value1
var2=value2
 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | JCpenney Printable Coupons