TESTEVERYTHING

Showing posts with label WScript. Show all posts
Showing posts with label WScript. Show all posts

Friday, 17 June 2011

Read Value from Registory / QTP / WScript

Here an example to get get the location where QTP is installed

REM Create shell script object
  Set WshShell = CreateObject(“WScript.Shell”)
REM in variable store the registry key path
  sKey =”HKLM\SOFTWARE\Mercury Interactive\QuickTest Professional\Configuration_UI\Packages\WebFormsPackage\Settings\ConfigurationFile”

REM here using the shell object we can read the registry key value
sQTPpath= WshShell.RegRead(sKey)

msgbox sQTPpath
set WshShell = nothing


Tuesday, 7 June 2011

Execute a DOS command in QTP / CMD with QTP

REM using "Wscript.Shell" object we can work on command prompt in qtp.
REM create one instance for "wscript.Shell"

set oShell=CreateObject("Wscript.Shell")

REM using run method we can invoke application
REM /k this will display command prompt.we can also use /c but we can not see command prompt.It will disappear after execution.


oShell.Run "cmd /k dir"
REM for wait in ms
WScript.sleep 3000
REM if we want use multiple commands we can use "&"(amp) symbol
oShell.run "cmd /k dir & md qtp"
REM we can use send keys method here {ENTER} will press enter button
oShell.SendKeys "cd{ENTER}"
REM if we want use multiple commands we can use "&"(amp) symbol

oShell.Sendkeys "cd c:\{ENTER} md qtp ~"


REM ~ for enter key {ENTER} = ~
oShell.Sendkeys "cd d: ~"

set oShell=Nothing

Wednesday, 13 April 2011

Use Send Key Method QTP VB

Hi All,
Some time we requre keyboard event in Automation so we can use Send key method

rem **********************************************
rem create shell object
set WshShell = CreateObject(“WScript.Shell”)
SystemUtil.Run “C:\Program Files\HP\QuickTest xcxProfessional\samples\flight\app\flight4a.exe”,”C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe”,”",”"
rem first click in the text box then use send key method
Dialog(“text:=Login”).WinEdit(“attached text:=Agent Name:”).Click
rem enter rajiv in agent name text box
WshShell.SendKeys “rajiv”
rem click Password Edit box
Dialog(“text:=Login”).WinEdit(“attached text:=Password:”).Click
rem enter check in Password text box
WshShell.SendKeys “check “
Dialog(“text:=Login”).WinButton(“text:=OK”).Click
rem press escape using send key method
WshShell.SendKeys “{ESC}”
WshShell.SendKeys “{ESC}”
rem **********************************************************
Use the SendKeys method to send keystrokes to applications that have no automation interface. Most keyboard characters are represented by a single keystroke. Some keyboard characters are made up of combinations of keystrokes (CTRL+SHIFT+HOME, for example). To send a single keyboard character, send the character itself as the string argument. For example, to send the letter x, send the string argument “x”.
Note To send a space, send the string ” “.
You can use SendKeys to send more than one keystroke at a time. To do this, create a compound string argument that represents a sequence of keystrokes by appending each keystroke in the sequence to the one before it. For example, to send the keystrokes a, b, and c, you would send the string argument “abc”. The SendKeys method uses some characters as modifiers of characters (instead of using their face-values). This set of special characters consists of parentheses, brackets, braces, and the:
  • plus sign       ”+”,
  • caret             ”^”,
  • percent sign “%”,
  • and tilde       ”~”
Send these characters by enclosing them within braces “{}”. For example, to send the plus sign, send the string argument “{+}”. Brackets “[ ]” have no special meaning when used with SendKeys, but you must enclose them within braces to accommodate applications that do give them a special meaning (for dynamic data exchange (DDE) for example).
  • To send bracket characters, send the string argument “{[}" for the left bracket and "{]}” for the right one.
  • To send brace characters, send the string argument “{{}” for the left brace and “{}}” for the right one.
Some keystrokes do not generate characters (such as ENTER and TAB). Some keystrokes represent actions (such as BACKSPACE and BREAK). To send these kinds of keystrokes, send the arguments shown in the following table:
KeyArgument
BACKSPACE{BACKSPACE}, {BS}, or {BKSP}
BREAK{BREAK}
CAPS LOCK{CAPSLOCK}
DEL or DELETE{DELETE} or {DEL}
DOWN ARROW{DOWN}
END{END}
ENTER{ENTER} or ~
ESC{ESC}
HELP{HELP}
HOME{HOME}
INS or INSERT{INSERT} or {INS}
LEFT ARROW{LEFT}
NUM LOCK{NUMLOCK}
PAGE DOWN{PGDN}
PAGE UP{PGUP}
PRINT SCREEN{PRTSC}
RIGHT ARROW{RIGHT}
SCROLL LOCK{SCROLLLOCK}
TAB{TAB}
UP ARROW{UP}
F1{F1}
F2{F2}
F3{F3}
F4{F4}
F5{F5}
F6{F6}
F7{F7}
F8{F8}
F9{F9}
F10{F10}
F11{F11}
F12{F12}
F13{F13}
F14{F14}
F15{F15}
F16{F16}
To send keyboard characters that are comprised of a regular keystroke in combination with a SHIFT, CTRL, or ALT, create a compound string argument that represents the keystroke combination. You do this by preceding the regular keystroke with one or more of the following special characters:
KeySpecial Character
SHIFT+
CTRL^
ALT%
Note When used this way, these special characters are not enclosed within a set of braces.
To specify that a combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, create a compound string argument with the modified keystrokes enclosed in parentheses. For example, to send the keystroke combination that specifies that the SHIFT key is held down while:
  • e and c are pressed, send the string argument “+(ec)”.
  • e is pressed, followed by a lone c (with no SHIFT), send the string argument “+ec”.
You can use the SendKeys method to send a pattern of keystrokes that consists of a single keystroke pressed several times in a row. To do this, create a compound string argument that specifies the keystroke you want to repeat, followed by the number of times you want it repeated. You do this using a compound string argument of the form {keystroke number}. For example, to send the letter “x” ten times, you would send the string argument “{x 10}”. Be sure to include a space between keystroke and number.
Note The only keystroke pattern you can send is the kind that is comprised of a single keystroke pressed several times. For example, you can send “x” ten times, but you cannot do the same for “Ctrl+x”.
Note You cannot send the PRINT SCREEN key {PRTSC} to an application.

Translate







Tweet