WendyPu 发表于 2011-1-6 16:04:20

SystemUtil.Run跟双击打开不一致

今天遇到了一个奇怪的问题。
SystemUtil.Run跟双击打开不一致。
我需要打开的程序中有些参数是要在打开的过程中从注册表中Load的,奇怪的是我双击打开,这些参数能Load进去,但是如果用SystemUtil.Run打开的程序就没有参数。
PS:如果我把程序添加到QTP的WindowApplication中,运行也是可以正确打开的。但这样用在我的测试里不合适,我的测试是需要经常打开和关闭程序的。
大家有没有解决办法呢?或者是换另外的打开程序的方法。

zzxxbb112 发表于 2011-1-6 16:35:01

DIR参数加上文件父目录试试,或者用InvokeApplication也可以。再不行用Wsh。

WendyPu 发表于 2011-1-6 17:36:09

我之前的DIR参数就是一直到父目录的,还是不行。
我再试下InvokeApplication和Wsh,看看行不行。

skyzhu 发表于 2011-1-7 11:06:40

SystemUtil.Run ... 运行参数需要是自己写的。要是只有一个程序地址是没用的

风雪夜归人 发表于 2011-1-7 11:17:02

对的,同意楼上,SystemUtil.Run 的运行参数是传进去的那些

WendyPu 发表于 2011-1-7 11:39:38

也试过InvokeApplication,现象跟用SystemUtil一样。
而用Wsh时会出General run error.的错。
4楼,5楼的说法不太明白。能否举例呢?、
我用的时候都只是写了个地址

gztester 发表于 2011-1-7 11:48:23

把你的代码贴出来看看

WendyPu 发表于 2011-1-7 12:44:26

就是很简单的一句话,启动NXConfig.exe
SystemUtil.Run "C:\Program Files\Harris\NEXIO Config (x64)\NXConfig.exe"
换成InvokeApplication就把SystemUtil换了一下。

下面是Wsh的
Dim MyShell
Set MyShell= CreateObject ("Wscript.shell")
MyShell.Run "C:\Program Files\Harris\NEXIO Config (x64)\NXConfig.exe" ‘运行时出错General run error,但如果换成calc.exe就可以运行
Set MyShell = Nothing

gztester 发表于 2011-1-7 12:53:17

查一下帮助文档SystemUtil.Run函数的用法,可能要设置一下工作目录

风雪夜归人 发表于 2011-1-7 14:48:11

Run Method
Collapse All Expand All
Description
Runs a file or application.
Important Information
When specifying a non-executable file, the file opens in the associated application.

Note: A SystemUtil.Run statement is automatically added to your test when you run an application from the Start menu or the Run dialog box while recording a test.

Tip: You can also use this method to perform operations on the specified file, similar to the usage of the Windows ShellExecute command.

Syntax
object.Run file, , , ,

Syntax Details
Argument Description
object A test object of type SystemUtil.
file Required. A String value.
The name of the file you want to run.
params Optional. A String value.
If the specified file argument is an executable file, use the params argument to specify any parameters to be passed to the application.
dir Optional. A String value.
The default directory of the application or file.
op Optional. A String value. The action to be performed. If this argument is blank ( ""), the open operation is performed.
The following operations can be specified for the op argument: Operation
Description

openOpens the file specified by the FileName parameter. The file can be an executable file, a document file, or a folder. Non-executable files are open in the associated application.
editLaunches an editor and opens the document for editing. If the FileName argument does not specify an editable document file, the statement fails.
exploreExplores the folder specified by the FileName argument.
findInitiates a search starting from the specified folder path.
printPrints the document file specified by the FileName argument. If the specified file is not a printable document file, the statement fails.

mode Optional. An Integer value.
Specifies how the application is displayed when it opens. You can specify one of the modes in the table below.
Default = 1

Mode
Description

0Hides the window and activates another window.
1   Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. Specify this flag when displaying the window for the first time.
2   Activates the window and displays it as a minimized window.
3   Activates the window and displays it as a maximized window.
4   Displays the window in its most recent size and position. The active window remains active.
5   Activates the window and displays it in its current size and position.
6   Minimizes the specified window and activates the next top-level window in the Z order.
7   Displays the window as a minimized window. The active window remains active.
8   Displays the window in its current state. The active window remains active.
9   Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. Specify this flag when restoring a minimized window.
10   Sets the show-state based on the state of the program that started the application.


Return Type
None
Example


自己F1一下就可以了啊,比如我启动IE,打开网址:
SystemUtil.Run "iexplore.exe", "https://10.11.102.178", "", "Open", "3"

WendyPu 发表于 2011-1-7 16:08:03

问题应该就是9楼说的工作目录的设置的问题。
因为我把EXE添加到Automation->Record and Run Settings->Windows Application.添加完后会显示Application的地址和Working folder两项。
如果这时Run QTP的话,我添加的程序可以正确打开。
但是如果我手动把Working folder给删掉,再运行QTP,程序打开的时候就没有自动从注册表读参数。

但是,我用脚本应该怎么样设置这个Working folder呢?这个不在SystemUtil.Run的5个参数里吧。

WendyPu 发表于 2011-1-7 16:08:46

我现在临时的方法是在QTP中用CMD语句来打开我的程序,没有问题。

iamfeiyu1009 发表于 2011-1-15 23:58:56

就是很简单的一句话,启动NXConfig.exe
SystemUtil.Run "C:\Program Files\Harris\NEXIO Config (x64)\NXC ...
WendyPu 发表于 2011-1-7 12:44 http://bbs.51testing.com/images/common/back.gif
SystemUtil.Run相当于:开始菜单里运行某程序,录制出来的脚本就是SystemUtil.Run……,如果运行里可以打开,该语句就可以执行,是带工作目录的
页: [1]
查看完整版本: SystemUtil.Run跟双击打开不一致