多测师是一家拥有先进的教学理念,强大的师资团队,业内好评甚多的接口自动化测试培训机构!

17727591462

联系电话

您现在所在位置:接口自动化测试培训 > 新闻资讯

在Silktest中自动添加打印机-自动化测试

更新时间:2022-06-08 09:06:36 作者:多测师 浏览:118

  首先来看一个动态连接库文件: Printui.dll

  点击开始->运行,输入:

  rundll32 printui.dll,PrintUIEntry [options] [@commandfile]

  Rundll32.exe 可以帮助我们运行dll文件,printui.dll后面的逗号,其实说明的是入口点:PrintUIEntry。

  后面的选项以及@commandfile详情只要输入

  rundll32 printui.dll,PrintUIEntry /?

  即可

在Silktest中自动添加打印机-自动化测试

  在自动测试的过程中,我们经常会遇到这样一种情况:

  在遍历dialog的时候,需要测试有/无安装打印机时软件的反馈。

  那么在Silktest中怎么实现呢?

  在Silktest中,有一个命令:Sys_Execute:

  Syntax

  iReturn = SYS_Execute (sCmdLine [, lsOutput])

  iReturn :The return value of the command. INTEGER.

  sCmdLine :The command to execute. STRING.

  lsOutput :[Optional.] A variable to hold any text written to stdout when sCmdLine runs. LIST OF STRING.

  这个命令执行一个命令行命令。并且把退出结果返回给返回值。所有的命令输出被写入IsOutput。简单的说,你可以把这个命令完全当作windows的命令行工具来用,他就和Windows键+R 一个效果。

  说道这里大家肯定都想到了:利用这个命令,利用Windows Rundll32.dll,调用Printui.dll的函数,就可以拉。于是非常简单的:

  [-] void AddNetworkPrinter (string printername)

  [ ]SYS_Execute("Rundll32 printui.dll,PrintUIEntry /in /n {printername}")

  这个函数将调运Rundll32 通过它访问printui.dll的PrintUIEntry函数,传递 /in /n {printername} 其中{printername}是你在定义里给出的string pritername

  当然,除了Sys_Execute我们还有其他的方法。(实际情况是,SYS_EXECUTE这个函数,不怎么完善...) 我们可以在silktest的脚本中,直接加载dll,因此有如下方法:

  [-] dll "kernel32.dll"

  [ ] //INT WinExec (String sPath, int iWinType)

  [ ] INT WinExec (LPCSTR sPath, UINT iWinType)

  [-] void AddNetworkPrinter (string printername)

  [ ] // Example: AddNetworkPrinter("\\printserver\printer")

  [ ] Winexec("rundll32 printui.dll,PrintUIEntry /in /n{printerName}", SW_SHOWMINIMIZED)

  以上内容为大家介绍了自动化测试中的在Silktest中自动添加打印机,本文由多测师亲自撰写,希望对大家有所帮助。了解更多自动化测试相关知识:https://www.aichudan.com/xwzx/

联系电话

17727591462

返回顶部