Monday, August 18, 2008

The WSH Object Model

The WshArguments Object

The WshArguments object is a collection object returned by the Arguments property of the WScript object

Example:

Dim oShell, oArgs

Set oArgs = WScript.Arguments

The WshEnvironment Object

The WshEnvironment object is a collection object returned by the Environment property of the WshShell object

Dim wsh, env

Set wsh = WScript.CreateObject("WScript.Shell")

Set env = wsh.Environment


The WshNetwork object

The WshNetwork object represents network resources that are available to a client computer.

Dim oNet

Set oNet = WScript.CreateObject("WScript.Network")


The WshShell Object

The WshShell object provides access to a wide variety of shell services, such as registry access, access to environment variables and to the location of system folders, the ability to create shortcuts

Dim wsh
Set wsh = WScript.CreateObject("WScript.Shell")


The WshShortcut Object

The WshShortcut object represents a shortcut—that is, a non-Internet link to a file or other resource on the local system or local network. A new or existing WshShortcut object is returned by the CreateShortcut method of the WshShell object,

Set WshShell = WScript.CreateObject("WScript.Shell")

Set oSCut = WshShell.CreateShortcut("Startup Script.lnk")


The WshSpecialFolders Object

WshSpecialFolders is a collection object that stores string variants that indicate the location of Windows system folders, like the Desktop folder of the Windows System folder. The collection is returned by the SpecialFolders property of the WshShell object,

Dim oShell, oSpFolders

Set oShell = WScript.CreateObject("WScript.Shell")

Set oSpFolders = oShell.SpecialFolders


The WshUrlShortcut Object

The WshUrlShortcut object represents an Internet shortcut—an Internet link to an Internet resource. A new or an existing WshUrlShortcut object is returned by the CreateShortcut method of the WshShell object

Set WshShell = WScript.CreateObject("WScript.Shell")

Set oURL = WshShell.CreateShortcut("Favorite Website.url")

Thursday, July 24, 2008

Frame work for Automation - Using BPT in Quality Centre



Import Excel sheet or Files

Datatable.import(“C:\sheet.xls”)

Import sheet method
Datatable.importsheet(Filename, sheetsource, Sheetdest)
Filename = File location
Sheetsource = sheet name (Start from index 1)
Sheetdesignation = Particular location (Start from index 1)
DataTable.ImportSheet "C:\sheet.xls" ,1 ,"name"

GetRowCount Method

rowcont = DataTable.GetSheet("MySheet").GetRowCount

Reporter.ReportEvent 2, "There are " &rowcont, "rows in the data sheet."

Call the Excel Sheet in to Test Script:

Add sheet
DataTable. Addsheet(“Mysheet”).Add Parameter(“Time”,”8.00”)
Delete sheet
DataTable. Deletesheet(“Mysheet”)
SheetID : Index value begin’s with 1
Export file
DataTable.export(“FileName”)
Export sheet
DataTable.exportsheet(“FileName”,SheetID)
FileName: String location
SheetID: Index values begin with 1

Saturday, July 19, 2008

Load the Web Application

Public Function OpenWeb (SampleUrl)
Dim SampleUrl = http://mdvdebugger.blogspot.com
SystemUtil. Run SampleUrl
If (Browser(“title:=Automation Testing, QTP”).Exist(0)) Then
SampleUrl = True
Reporter.reportevent micPass” Page is loaded”
Else
SampleUrl = False
Reporter.reportevent micPass” Page is not loaded”
End if
End Function

Testing Automation Life Cycle


Preparation:
The following activities will be carried out during the preparation.
· Project kick off
· Prepare Execution Plan
· Identify the core team
· Identify key business and division representations
· Core Team will develop processes in coordination with the division representatives.

Design & Development:
The following activities will be carried out during the design of the Test Automation framework.
· Develop Test Automation framework plan
· Set up Infrastructure – Hardware, Software & Tools
· Define the components of the Repository
· Develop the Framework
· Devise a training plan for Divisions about the repository

Implementation:
The implementation activities are
· Implement the project using the test automation framework

Function for RowValid,ObjectExist,ColumnValid and SetTextValue

'Function ObjectExist
Public function ObjectExist ( objExpected )
boolnObjExist = false
if (objExpected.Exist) Then
boolnObjExist = True
End if
IsObjectExist = boolnObjExist
End function

'Function RowValid

Public function RowValid ( objTable, intRowNumber )
boolnRowValid = false
intTblRows = CInt(objTable.GetROProperty("rows"))
intRowNumber = CInt(intRowNumber)
if ((intRowNumber > -1) and (intRowNumber < intTblRows)) Then
boolnRowValid = True
End if
IsRowValid = boolnRowValid
End function

Function ColumnValid
Public function ColumnValid ( objTable, intColumnNumber )
boolnColnValid = false
intTblCols = CInt(objTable.GetROProperty("cols"))
intColumnNumber = CInt(intColumnNumber)

If ((intColumnNumber > -1) and (intColumnNumber < intTblCols)) Then
boolnColnValid = True
End if

IsColumnValid = boolnColnValid
End function

Function SetTextValue
Public function SetTextValue ( objEdit,strData )
boolSuccess = True
on Error Resume Next
objEdit.Object.requestFocus
objEdit.Object.setText strData
objEdit.Object.nextFocus
If Err.Number <> 0 then
Reporter.ReportEvent micFail, "General Java Functions: SetTextValue" , Err.Description
Err.Clear
boolSuccess = false
End if
SetTextValue = boolSuccess
End function

Basic Object Functions

These are very basic functions and can be called on any common standard GUI Object. Commonly used in automation for verifying a value, verifying an object is enabled or disabled, checking whether the object exists and getting value of an object can be classified in to Basic Object function category.

1) VerifyEnabled: To verify an object is enabled.
2) VerifyDisabled: To verify an object is disabled.
3) IsObjectExist: To find out whether the object exists
4) VerifyValue: To verify a expected value
5) GetValue: To get an object value

Function Verify Enabled
Public Function VerifyEnabled (obj)
Dim enable_property
enable_property = obj.GetROProperty("enabled")
If enable_property <> 0 Then
Reporter.ReportEvent micPass, "VerifyEnabled Succeeded", "The test object is enabled"
VerifyEnabled = True
Else
Reporter.ReportEvent micFail, "VerifyEnabled Failed", "The test object is NOT enabled"
VerifyEnabled = False
End If
End Function

Function VerifyDisabled
Public Function VerifyDisabled (obj)
Dim enable_property
enable_property = obj.GetROProperty("disabled")
If enable_property = 0 Then
Reporter.ReportEvent micPass, "VerifyDisabled Succeeded", "The test object is enabled"
VerifyDisabled = True
Else
Reporter.ReportEvent micFail, "VerifyDisabled Failed", "The test object is NOT enabled"
VerifyDisabled = False
End If
End Function

Function Exist Object
Public Function ObjectExist(Obj)
Dim ObjectVisible
ObjectVisible = obj.Exsit
If (ObjectVisible = 0) Then
Reporter.ReportEvent micPass, "Object Visible ", "Succeeded"
ObjectVisible = True
Else
Reporter.ReportEvent micPass, "Object is not Visible ", "Not Succeeded"
ObjectVisible = False
End if
End Function

Automation Approach

The test automation framework provides the function libraries and the skeleton to start automation of an application. As the AUT changes the automation framework also changes. But there are common automation functions that can be applied irrespective of the application under test. In the Generic automation approach the aim is to identify these common functional libraries and utility functions that can be developed once and used for automation of different AUT that may be developed using different programming languages.

The Generic functional libraries can be classified in to
Basic Object Functions: These are the functions that can be called on many different test objects. These functions are common for standard objects.

Language Specific Functions: These are the functions that can be called on the test object specific to AUT development language. There can be a set of functions for each application development language. For Ex: Set of functions for test objects of Java, another set of functions for .NET, VB, etc.

Utility Functions: The utility functions include the string manipulation functions, array manipulation, file handling functions etc. These functions are useful to manipulate input / output data in the test scripts.

Database functions: The database functions are for executing the database queries from the test scripts.

Reporting or Logging functions: The logging functions are helpful for logging any debug / information messages / variable output to either to text file or to a QTP report file. The Reporting functions are to report the results of the test, Pass, Fail, warning and error.

Friday, July 18, 2008

Best Practices in Test Automation

The following best practices should be followed while generating automated test scripts.
? Always document sufficient comments inside test scripts/reusable actions/function libraries
? Make document for each test scenario’s or flow of the test scripts and including with Path of OR, Function library, Parameter data details
? Implement sufficient exception handling steps so that the chances of script failure due to test run errors are reduced
? Never hardcode paths and other similar data. Instead use relative paths.? When modifications are required to the test scripts, save the old script as an older version.
? Creation of a QTP scenario should always be done on a test environment that must be “production-like”.
? Follow naming conventions as specified in the scripting guidelines document.
? A Script Usage Manual should be prepared after the preparation of the automation scripts, to make the user understand the ways of executing the automation scripts.

Exception Handling

Exceptions are unexpected event that occur during the normal execution flow.
Start of Scenario run Test scenarios may be executed in sequences in test sets. There are multiple options to guarantee that each scenario can run in a test set, independent of whether the previous scenario was successful or encountered a Test Run Error.
One option is that in each Scenario before the first reusable action of the scenario an extra Function is inserted. The function navigates the application to the required base state.This will facilitate that in the situation where a previous test in the set has failed, the next test of the set can start anyway by setting the oracle applications to the Navigator form (which is the start screen for each reusable action).
Another option is to create a specific Logon reusable action to be placed at the start of each scenario. This reusable action will first close all Oracle sessions that are open and will then open a new sessions according to a predefined environment and user.
Popup Error screens Handle all expected pop up error messages. Two approaches may be followed
? Close the popup and continue navigating through the scripts. Here the settings should be done to proceed to the next step on error.
? Terminate the test script and print the error log.
Application Errors Due to application errors test scenario execution breaks. When an application error is identified, prepare the error log and terminated the test. Prepare backend validation scripts and use them to validate event status frequently. When an error is noticed execute the exception handlers.

Common Directory Structure - Automation Frame Work


When Quality Center is not available, a common folder would be maintained in a shared network drive. The following directory structure will be used for automated test script development.

Functional Decomposition Model -Automation Frame Work

  1. The main concept behind the "Functional Decomposition" script development methodology is to reduce all test cases to their most fundamental tasks. These tasks/components will be implemented as User-Defined Functions, Sub routine or Utility Scripts. The component scripts should perform these tasks independently of one another based on the data input.

The key modules/components of the test automation architecture for Platform automation will consist of the following:

  1. Test Scripts
  2. Reusable Actions
  3. Library Files
  4. Configuration Files
  5. Utility scripts
  6. Data Files
  7. SQL Queries
  8. Results/Log files

Data Driven Approach - Automation Frame work

It has been decided to follow a data driven approach for test automation of (Project/Platform Name) application. In a data driven approach, data is made independent of the test. Input data is provided from an external data source. MS Excel will be used as the external data input source. During test execution test data would be called inside the test from the external data sheets.
The following are the advantages of a data driven approach.
  1. Ease of data maintenance
  2. Iterate the same test with multiple set of test data
  3. Baseline test data for different type of tests.
The test data used by testing team during manual test case development would be used while automated test script development.
Example:
<> takes input data –Customer Number, Order Type Ordered Items etc. The data would be stored in the excel file named SCN-Supplies_Data.xls. The same would be called inside QTP during test execution.

Plug and play model – Test Automation Architecture

  • Each regression test scenario under will be implemented using a scenario level script (Driver Script). The scenario level test script will implement calls to component level scripts, which will be executed in sequence to complete the test execution flow. Such a plug and play model will enable us to add/remove components from the test scripts as and when modifications are required. Also, component scripts will be reused inside multiple scenario level test scripts.

    Example:
    (Scenario script header)
    (Initializations – Load the OR)
    (Initializations – Load the Excel Sheet)
    (Initializations – Load the Functional Library)
    (Initializations – Load the Expectation handling)
    Call ( login)
    Call (Test1)
    Call (Test2)
    Call (Test3)
    Call (Test4)
    Call (logout)
    (Initializations – Close all Initializations)
  • The component level scripts are usually independent. When a modification is required in the “PO validation” process, the particular components only need to be worked on. Also, the modification will reflect in all scenario level scripts where “PO validation” is called.

Getting Child Object

Dim obj_ChkDesc

Set obj_ChkDesc=Description.Create

obj_ChkDesc(“html tag”).value = “INPUT”

obj_ChkDesc(“type”).value = “checkbox”

Dim allCheckboxes, singleCheckBox

Set allCheckboxes = Browse(“Browser”).Page(“Page”).ChildObjects(obj_ChkDesc)

For each singleCheckBox in allCheckboxes

singleCheckBox.Set “ON”

Next

Delete cookies with a single line of code

  • Cookies are small chunk of information of code placed by the website on the user local/browser cache. QTP provides a way to view/delete cookies. The below mentioned methods can be used for various operation.
  • WebUtil.
  • DeleteCookie Delete specified cookie for the specified domain
  • DeleteCookies Delete all cookies present on the local cache
  • GetCookies for a specified domain
  • AddCookie Add specified cookie for a specified domain
  • There are many other functions available also. But I would not be going into the details of any of these. You can find all the function when you type “webutil.” In the QTP script editor.

Sample Automation Frame Work Diagram



  • Function & Utilities: Collection user Define function based on the application or system
    Test Data & Environment Data: Collection test data
    Test Case Script: Test script for each module or flow of the application or system
    Share Object Repository: Object Repository
    Test Case Log File: Test Result for the test case or script log file

Note: Don’t use Quality centre for this frame work

Wednesday, July 16, 2008

Parameterizing Values

  • You can use the parameter feature in QuickTest to enhance your test by parameterizing the values that it uses. A parameter is a variable that is assigned a value from an external data source or generator.

There are four types of parameters:

  • Test/action parameters. Test parameters enable you to use values passed from your test. Action parameters enable you to pass values from other actions in your test.
  • Data Table parameters. Enable you to create a data-driven test (or action) that runs several times using the data you supply. In each repetition, or iteration, QuickTest uses a different value from the Data Table.
  • Environment variable parameters. Enable you to use variable values from other sources during the run session. These may be values you supply, or values that QuickTest generates for you based on conditions and options you choose.
  • Random number parameters. Enable you to insert random numbers as values in your test.

Using Regular Expressions

  • Regular expressions enable QuickTest to identify objects and text strings with varying values. You can use regular expressions when:
  • Defining the property values of an object in dialog boxes or in programmatic descriptions
  • Parameterizing a step and creating checkpoints with various values
  • QuickTest treats all characters in a regular expression literally, except for the period (.), hyphen (-), asterisk (*), caret (^), brackets ([ ]), parentheses (()), dollar sign ($), vertical line (), plus sign (+), question mark (?), and backslash (\). When one of these special characters is preceded by a backslash (\), QuickTest treats it as a literal character.
    Using the Backslash Character ( \ )
  • Matching Any Single Character ( . )
  • Matching Any Single Character in a List ( [xy] )
  • Matching Any Single Character Not in a List ( [^xy] )
  • Matching Any Single Character within a Range ( [x-y] )
  • Matching Zero or More Specific Characters ( * )
  • Matching One or More Specific Characters ( + )

Analog and Low Level Recording

Analog Recording

  • Use analog recording for applications in which the actual movement of the mouse is what you want to record. These can include drawing a mouse signature or working with drawing applications that create images by dragging the mouse.
  • You can record in Analog Recording mode relative to the screen or relative to a specific window.

Low Level Recording

  • Use low-level recording for recording on environments or objects not supported by QuickTest.
  • Use low-level recording for when you need to record the exact location of the operation on your application screen. While recording in normal mode, QuickTest performs the step on an object even if it has moved to a new location on the screen. If the location of the object is important to your test, switch to Low Level Recording to enable QuickTest to record the object in terms of its x- and y- coordinates on the screen. This way, the step will pass only if the object is in the correct position.
  • Low-level recording supports the following methods for each test object:
  • WinObject test objects: Click, DblClick, Drag, Drop, Type
  • Window test objects: Click, DblClick, Drag, Drop, Type, Activate, Minimize, Restore, Maximize

Tuesday, July 15, 2008

Type of Checkponits

  • Standard Checkpoint checks the property value of an object in your application or Web page. The standard checkpoint checks a variety of objects such as buttons, radio buttons, combo boxes, lists, and so forth,support for all add-in environments
  • Image Checkpoint checks the value of an image in your application or Web page,support for the Web add-in environment
  • Image Checkpoint checks the value of an image in your application or Web page
  • Bitmap Checkpoint checks an area of your Web page or application as a bitmap
    Table Checkpoint checks information within a table
  • Text Checkpoint checks that a text string is displayed in the appropriate place on a Web page or application.
  • Text Area Checkpoint checks that a text string is displayed within a defined area in a Windows application, according to specified criteria.

Understanding Checkpoint

  • QuickTest enables you to add checks to your test. A checkpoint is a verification point that compares a current value for a specified property with the expected value for that property. This enables you to identify whether your Web site or application is functioning correctly.
  • You can also use the CheckProperty method and the CheckItemProperty method to check specific property or item property values
  • Example : a = Browser("MyBrowser").Page("MyPage").Check (CheckPoint("MyProperty"))

Understanding Object Repository

  • Test objects can be stored in two types of object repositories—a shared object repository and a local object repository. A shared object repository stores test objects in a file that can be accessed by multiple tests (in read-only mode).
  • A local object repository stores objects in a file that is associated with one specific action, so that only that action can access the stored objects.

Adding Other Types of Steps to Your Test

  • You can insert a checkpoint and output value
  • You can insert comments in steps to separate parts of an action
  • You can insert Report events, commentsline and Synchronizes Call Qtp Script and Winrunner test/function
  • You can control the flow of your test by using conditional and Loop statements

Define the Keyword View

  • You can use the Keyword View to add new steps to your test and to view and modify existing steps. When you add or modify a step, you select the test object or other step type you want for your step.
  • select the method operation you want to perform, and define any necessary values for the selected operation or statement.
  • Working in the Keyword View does not require any programming knowledge. The programming required to actually perform each test step is done automatically behind the scenes by QuickTest.
  • The following columns: Item, Operation, Value, Assignment, Comment, and Documentation

How QuickTest Learns Objects While Recording

  • First, it "looks" at the object on which you are recording and stores it as a test object, determining in which test object class it fits
  • For each test object class, QuickTest has a list of mandatory properties that it always learns;
  • When you record on an object, QuickTest always learns these default property values, and then "looks" at the rest of the objects on the page, dialog box, or other parent object to check whether this description is enough to uniquely identify the object. If it is not, QuickTest adds assistive properties, one by one, to the description, until it has compiled a unique description

Get Value from Note or Mesage in Orale Apps

Dim id,stchr,endchr
id = OracleNotification("Decisão").GetROProperty( "message")
stchr = instr(1,id,"= ")
endchr = instr(1,id,")")
id = mid(id,stchr+2,endchr-stchr-2)

Query the Data in Oracle Form Window

OracleFormWindow("NFFs").OracleTextField("Tipo").InvokeSoftkey "ENTER QUERY"

OracleFormWindow("NFFs").OracleTextField("Fornecedor").Enter Parameter("Fornecedor")OracleFormWindow("NFFs").OracleTextField("Local").Enter Parameter("Local")OracleFormWindow("NFFs").OracleTextField("Data da NFF").Enter Parameter("data_NFF")OracleFormWindow("NFFs").OracleTextField("Fornecedor").InvokeSoftkey "EXECUTE QUERY"

Cancel the Note Function in Oracle Apps

function note()
Dim Message
If OracleNotification("title:=Note").Exist Then
Message = OracleNotification("title:=Note").GetROProperty("message")
reporter.ReportEvent micWarning, "Note Message: ", ""&Message OracleNotification("title:=Note").Approve
note = 1
Else
note = 0
End If
End Function

Compare Date Function

Function Compare_Date(InacDate,CurrentDate)
If int(year(InacDate) ) > int(year(CurrentDate) )Then
Comp = 0
Else If int(year(InacDate) ) = int(year(CurrentDate) )Then
If int(month(InacDate) ) > int(month(CurrentDate) )Then
Comp = 0
Else
If int(month(InacDate) ) = int(month(CurrentDate) )Then
If int(day(InacDate) ) > int(day(CurrentDate) )Then
Comp = 0
Else
Comp = 1
End If
Else
Comp = 1
End If
End If
Else
Comp = 1
End If
End If
End Function

Open the browser

Function OpenBrowser(StartURL) strTestDrive=getTestDrive()
loadRepository("Test.tsr")
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = true
If Browser("Browser").Exist Then
Browser("Browser").Close End If SystemUtil.Run "iexplore.exe","","","" Wait (2)
hwnd = extern.GetForegroundWindow()
hwnd = extern.GetForegroundWindow()
Window("HWND:=" &hWnd).Maximize
IE.Navigate StartURL Browser("Browser").Navigate StartURL
End Function

Function to open the data sheet

Public Function OpenDataTable(strFileName,strSheetName)
CurPath=environment("TestDir")
pathArr=split(CurPath,"\") CurDrive=pathArr(0) pathFile="\nxc Automation\Data Table\"
dataTablePath=CurDrive + pathFile strFilePath=dataTablePath+ strFileName
DataTable.ImportSheet strFilePath,strSheetName,"Global"
End Function

String without Spaces

public function Stringtrim(in str)

Dim len,ret,start,end; len=length (str)

for(start=1;start<=len;start++) if(substr(str,start,1)!=" ")

break

for(end=len;end>1;end--)

if(substr(str,end,1)!=" ")

break

return substr(str,start,len-start-(len-end)+1)

End Function

Friday, July 11, 2008

Edit/View the Same Object

1) For i=0 to 9
Browser("b1").Page("p1").WebEdit(name:="Text1","index:=" & i).Set Value
NextEnd Loop
2)Browser("Welcome: Mercury Tours").Page("Book a Flight: Mercury").WebEdit("text" & i).Set "name" & iNextHere objects need to be present in the OR
FOr the below one
For i=1 to 2Browser("Welcome: Mercury Tours").Page("Book a Flight: Mercury").WebEdit("text" & i).Set "name" & i Next

Declare the Array

1) Dim Variable1Array()Public varOne as Integer
Redim variable1Array(varone)
variable1Array(1) = "Sample1"variable1Array(2) = "Sample2"
2) Dim myarray(30)
myarray(0) = "raj"myarray(1) = "singh"

Load the .Vbs File

1) Executfile(" Path of file ")
2 ) Call Functionname(arg list)
3) Dim qtApp Dim qtLibraries
Set qtApp = CreateObject("QuickTest.Application")
Set qtLibraries = qtApp.Test.Settings.Resources.Libraries ' Get the libraries collection object
If qtLibraries.Find("C:sai1.vbs") = -1 Then ' If the library cannot be found in the collectionExecuteFile "C:sai1.vbs"
End If
Call test1()
Function In File Sai1.vbs Function test1()MsgBox "Hi Manish"End Function
4) sPath = "D:/Files/Functions.vbs"
Executfile (sPath)(OR) Executfile ("D:/Files/Functions.vbs")

Convert the Date Format like : 30-May-2004

Function date_ddmonyyyy(vDate)

' return the date in the DD-MON-YYYY format, ex. 31-Aug-2004

If vDate = "" Then

vDate = Date()

End If
a = MonthName(Month(CDate(vDate)), true) b = Day(Date()) c = Year(Date())
If b<10 b="0">

End If
date_ddmonyyyy = b & "-" & a & "-" & c

End Function

Remove the OR in to QTP

Public Function remove_obj_repository(Action_Name)

Dim qtAppDim qtRepositories

'As QuickTest.ObjectRepositories

' Declare an action's object repositories collection variable

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application

objectSet qtRepositories = qtApp.Test.Actions(Action_Name).ObjectRepositories

' Get the object repositories collection object of the "Login" action
' Removes the Object Repository Associated with the given Actionqt

Repositories.RemoveAll
End Function

Load the OR In QTP

Public Function load_obj_repository(ObjRepPath,Action_Name)

Dim qtAppDim qtRepositories

'As QuickTest.ObjectRepositories

' Declare an action's object repositories collection variable

Set qtApp = CreateObject("QuickTest.Application")

' Create the Application

objectSet qtRepositories = qtApp.Test.Actions(Action_Name).ObjectRepositories

' Get the object repositories collection object of the "Login" action
' Add MainApp.tsr if it's not already in the collection

If qtRepositories.Find(ObjRepPath) = -1 Then ' If the repository cannot be found in the collection
qtRepositories.Add ObjRepPath, 1 ' Add the repository to the collection

End If

End Function

Close all Browser

Public Function close_all_browsers()
SystemUtil.CloseDescendentProcesses
On error resume next
End Function

Thursday, July 10, 2008

Use of Windows Shell Script (WSH)

set WshShell = CreateObject("WScript.Shell")

WshShell.AppActivate Parameter("ipURL")

Browser("title:=Test.*").Page("title:=Test.*").Frame("title:=WebFrame.*").WebElement("WebElement").Click

WshShell.SendKeys "{DOWN}"

WshShell.SendKeys "{DOWN}"

WshShell.SendKeys "{DOWN}"

WshShell.SendKeys "{DOWN}"

Log into Web Application

Public Function login(Url,UserName,Password)
Browser("title:=about:blank").Page("url:=[a-z].*").Sync

Browser("title:=about:blank").Navigate urlBrowser("title:=Login").Page("title:=Login").Sync
If not Browser("title:=Login").Page("title:=Login").Exist(TIMEOUT) Then

report_result "FAIL","Login","Login Page is not Displayed" login = -1

Exit Function

End If
Browser("title:=Login").Page("title:=Login").WebEdit("outerhtml :=.*username.*","name:=username").Set username

Browser("title:=Login").Page("title:=Login").WebEdit("outerhtml := .*password.*", "name:=password").Set password
If Browser("title:=Login").Page("title:=Login").Image("alt:=.*Login.*").Exist(OBJ_TIMEOUT) Then

Browser("title:=Login").Page("title:=Login").Image("alt:=.*Login.*").Click

Else

Browser("title:=Login").Page("title:=Login").WebButton("name:=.*Login.*").Click

End If
Browser("title:=Test.*").Page("title:=Test.*").Sync
If Browser("title:=Test.*").Page("title:=Test.*").Exist(TIMEOUT) Then

report_result "PASS","Login","Login Is Successful with the user : "+ username login = 0

Else

report_result "FAIL","Login","Login Is UnSuccessful with the user : "+ username + " User details may not be right. look at the Global data Table" login = -1

Exit Function

End If

End Function

Delete the Cookies in Web Page

Public Function Open_Browser()
SystemUtil.Run "iexplore.exe","about:blank"
Webutil.deletecookies
End Function

Find the Cookies in Web Page

Dim Sample Sample = Browser("name:=Google").Page("title:=Google").Object.cookie
msgbox Sample

'Dim Sample 'Sample = Browser( "Name:=&[A-Za-z]").Page( "title:=&[A-Za-z]").Object.cookie
msgbox Sample

Find the Radio Button in Web page

Set RadBtn_Desc = Description.Create()
RadBtn_Desc("micclass") = "RadioButton"
Set RadBtn_Coll = Browser(B).Page(P).ChildObjects(RadBtn_Desc)
MsgBox RadBtn_Coll.Count

String Compare Function

Value1 = Browser("").Page(""). Webedit("").Get RO Property("Value")
Value2 = Browser("").Page(""). Webedit("").Get RO Property("Value")
Variable have value and now we want to compare the value.
String Compare function:
Dim Value1,Value2, MyCompare
Mycompare = strcomp(Value1,Value2,1)
string1 is less than string2 = 1string1 is equal to string2 = 0 string1 is greater than string2

Add Date to Current Date

Dim Mydate
Mydate = Dateadd("D",4,Date)
Msgbox Mydate

Define the Object Value

Dim RadBtnDesc
Set RadBtnDesc = Description.Create()
RadBtnDesc("Class Name") = "WebEdit"
Set RadBtnColl = Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").ChildObjects(RadBtnDesc)
MsgBox RadBtnColl.Count

Write the Data Into Notepad

Dim a, b
Const ForReading = 1, ForWriting = 2, ForAppending = 8
set a = createobject ("Scripting.FileSystemObject")
Set b = a.Getfile("c:\Vinodh.txt")
Set b = a.opentextfile("c:\Vinodh.txt",ForWriting, True)
b.write "Vinodh from Bangalore"
Set b = a.opentextfile("c:\Vinodh.txt",ForReading, True)
filespec = ("c:\Vinodh.txt")
ShowFileAccessInfo(filespec)
print ShowFileAccessInfo
Function ShowFileAccessInfo(filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
s = f.Path & "
" s = s & "Created: " & f.DateCreated & "
" s = s & "Last Accessed: " & f.DateLastAccessed & "
" s = s & "Last Modified: " & f.DateLastModified ShowFileAccessInfo = s
End Function

Write the Excel

Function WriteToFile
Const ForReading = 1, ForWriting = 2
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
f.Write "Hello world!"
Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)
WriteToFile = f.ReadLine
End Function

Open the Notepad

Dim a
set a = wscript.createobject ("wscript.shell")
a.run "notepad.exe"

Copy the excel File

DataTable.ExportSheet(filePath)
DataTable.Import ( FilePath)

Data base Connection

Dim objConn,objRecSet
Set objConn= CreateObject("ADODB.connection")
Set objRecSet = CreateObject("ADODB.recordset")
objConn.open " Server: , Database: , User Name , Password " ' connection string about ur Datanbase objRecSet.open "Select * from Table Name "
objConn.close
objRecSet.close