[译]ScriptRunner应用程序
By robot-v1.0
本文链接 https://www.kyfws.com/applications/scriptrunner-application-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 6 分钟阅读 - 3000 个词 阅读量 0[译]ScriptRunner应用程序
原文地址:https://www.codeproject.com/Articles/18138/ScriptRunner-Application
原文作者:Ernest Laurentin
译文由本站 robot-v1.0 翻译
前言
An Introduction to ScriptRunner. A scripting tool for user interface Unit Testing.
ScriptRunner简介.用户界面单元测试的脚本工具.
- 下载项目演示-222.22 KB(Download project demo - 222.22 KB)
- 下载源文件-101.15 KB(Download source files - 101.15 KB)
介绍(Introduction)
当今,软件专业人员最需要追求的技能之一是不仅能够编写高质量的代码,而且还能够测试和验证您的代码.这是此工具起作用的地方. ScriptRunner与其他单元测试框架不同.实际上,ScriptRunner是传统单元测试框架的补充,例如(One of the most sought after skills for software professionals today is not only the ability to write good quality code but also the ability to test and validate your code. This is where this tool comes into play. ScriptRunner is different from other unit testing Frameworks. In fact, ScriptRunner is a complement of a traditional unit testing Framework like) CPP单位(CPP Unit) .单元测试框架使您可以测试应用程序中的模块.模块可以是库,类(或对象),也可以是简单函数. ScriptRunner通过模拟用户与软件的交互来补充单元测试,并且可以在程序执行中显示任何错误.(. A Unit Testing Framework lets you test modules in your application. A module can be a library, a class (or an object) or can be a simple function. ScriptRunner complements unit testing by emulating a user interaction with your software and can display any error in the execution of your program.)
描述(Description)
最初,创建ScriptRunner的目的是模拟用户与应用程序的交互.但最终,该工具得到了发展.现在,它提供了一个简单的(Initially, ScriptRunner was created with the intent to simulate a user interaction with an application. But in the end, this tool has evolved. Now, it provides a simple) TRACE
库捕获应用程序状态,当然还可以报告程序中的任何错误.(library to capture the application state and of course, to report any error in your program.)
通常使用CPP单元(或其他框架),编写代码以测试传递正确和错误值的函数,以验证其行为是否正确.这些工具非常有用,如果您选择测试足够的重要功能,则可以很好地覆盖并发现程序中的错误(或损坏的代码).(Typically with CPP Unit (or other Framework), you write the code to test your function passing both correct and error values to verify whether it behaves correctly. These tools are great and if you choose to test enough important functions, you can get very good coverage and find bugs (or broken code) easily in your program.)
但是缺少一个方面,就是如何测试用户界面以达到相同的结果? ScriptRunner可以帮助您做到这一点!您可以编写一个简单的脚本来与您的应用程序进行交互,并使用ScriptRunner(But one aspect that is lacking, is how do you test the User Interface to achieve the same result? ScriptRunner can help you do that! You can write a simple script to interact with your application and use the ScriptRunner) TRACE
库显示任何成功或失败.(library to display any success or failure.)
它是如何工作的?(How Does it Work?)
ScriptRunner是脚本宿主应用程序.它提供了一组界面,以执行应用程序,操纵窗口并将输入提交到用户界面,就像用户通常要做的那样.有几个命令可用于配置和运行测试脚本.我假设每个人都可以识别标准图标并知道它们的用途.现在,让我描述一下其他图标以帮助您入门.(ScriptRunner is a Scripting Host application. It provides a set of interfaces to execute an application, manipulate a window and submit input to your user interface as a user would normally do. Several commands are available to configure and run a test script. I am assuming everyone will recognize the standard icons and know what they are used for. Now, let me describe the other icons to get you started.)
命令(Command) | 描述(Description) |
---|---|
Trace |
您可以使用(You can use the) Trace 按钮以捕获跟踪语句((button to capture the trace statement () OutputDebugString )直接转到此窗口.您的代码可以使用ScriptRunner将输出字符串直接发送到此窗口() directly to this window. Your code can send output strings directly to this window by using the ScriptRunner) TRACE 图书馆.脚本还可以通过使用以下命令发送输出(library. A script can also send an output by using) ScriptHost.DebugOutput function. |
Stop |
Stop 跟踪将停止捕获调试器输出.(Trace will stop the capture of the debugger output.) |
Compare |
Compare 模式可以用来验证程序执行时发送的输出.(mode can be used to verify the outputs being sent when your program executes.) |
Run |
Run 命令将执行一个用户界面JavaScript测试单元(command will execute a User Interface JavaScript Testing Unit) |
还有一些附加功能可用于过滤程序输出.上下文菜单选项也可用于加载和保存程序输出设置.(Several additional features are available to filter your program output. Context menu options are also available to load and save your program output settings.)
ScriptRunner ScriptHost API(ScriptRunner ScriptHost API)
功能(Function) | 描述(Description) |
---|---|
Display(text) |
显示一个消息框(Display a message box) |
DebugOutput(text) |
将输出文本发送到脚本运行器输出(Send output text to script runner output) Window |
FindWindow(class,title) |
搜索特定的(Search for a specific) Window 类和标题(可选).(class and title (optional).) |
SendKey(keyCode,ctrlKey,altKey) |
将虚拟键码发送到活动窗口(具有焦点的控件). (可选)模拟被按下的CTRL和ALT键.(Send a virtual Keycode to an active Window (control with focus). Optionally, simulate CTRL and ALT keys being pressed.) |
SendKeys(text) |
发送击键(用户仿真).(Send keystrokes (User emulation).) |
Sleep(delay) |
等待指定的毫秒数(Wait for specified milliseconds) |
bool LaunchApp(appPath) |
运行一个应用程序(Run an application) |
string GetEnvString(sName) |
获取环境变量字符串(Get an environment variable string) |
ScriptRunner WindowDispatch API(ScriptRunner WindowDispatch API)
功能(Function) | 描述(Description) |
---|---|
Window |
获得的财产(Property to get) Window 处理.由于ScriptRunner负责创建和初始化此对象,因此应将其用作只读.(handle. This should be used as read-only since ScriptRunner is responsible for creating and initializing this object.) |
string GetWindowText() |
获取当前标题文本或编辑文本以进行编辑控制(Get current caption text or edit text for edit control) |
int GetWindowTextLength() |
获取当前字幕文字(或编辑文字)的长度(Get current caption text (or edit text) length) |
bool SetWindowText(text) |
Change Window text |
SetFocus() |
将重点更改为(Change focus to) Window |
ShowWindow(cmdShow) |
显示/隐藏(Show/Hides a) Window |
Window GetDlgItem(dlgItem) |
找个孩子(Get a child) Window handle |
ChildWindowFromPoint(x,y) |
找个孩子(Get a child) Window 从客户坐标处理(handle from client coordinates) |
MoveWindow(x,y,w,h) |
调整大小和位置(Resize and reposition a) Window |
SetWindowPos(x,y,cx,cy,flg) |
调整大小和位置(Resize and reposition a) window |
Window FindWindowEx(class,title,prev) |
找一个孩子(Find a child) Window 根据班级或职称(based on class or title) |
bool SetForegroundWindow() |
Set Window 到前景(to foreground) |
Window GetParent() |
取得最新消息(Get current) Window parent |
MouseHover() |
将鼠标移到上方并居中(Move and Center mouse over) Window object |
MouseLClick(x,y,clickNow) |
将鼠标移至(Move mouse to) Window 客户位置,可选择模拟运动结束时的左键单击.(client position, optionally simulate left click at the end of movement.) |
MouseRClick(x,y,clickNow) |
将鼠标移至(Move mouse to) Window 客户位置,可选择模拟运动结束时的右键.(client position, optionally simulate right click at the end of movement.) |
ScriptRunner示例(ScriptRunner Example)
ScriptRunner仅公开一个事件处理程序(ScriptRunner exposes only one event handler) OnStarted.
建议您运行脚本的主要入口点.在JavaScript中,使用此原型(It is the recommended main entry point to run your script. In JavaScript, use this prototype) function ScriptHost::OnStarted()
.(.)
例:(Example:)
function ScriptHost::OnStarted()
{
LaunchApp("C:\\Windows\\System32\\Notepad.exe");
Sleep(500);
var winObj = FindWindow("Notepad", "Untitled - Notepad");
if (winObj)
{
winObj.SetForegroundWindow();
winObj.SetFocus();
SendKey(0x74); // F5
SendKeys("Hello CodeProject gurus around the world!\r");
SendKeys("1234567890-=\r");
SendKeys("!@#$%^&*()_+\r");
SendKeys("abcdefghijklmnopqrstuvwxyz\r");
SendKeys("ABCDEFGHIJKLMNOPQRSTUVWXYZ\r");
}
else
Display("Untitled - Notepad window was not found...");
}
单元测试输出到ScriptRunner(Unit Testing Output to ScriptRunner)
如前所述,C/C ++应用程序可以将输出发送到ScriptRunner输出窗口.为此,您必须在解决方案中包括一组文件.(As stated before, a C/C++ application can send output to ScriptRunner output window. For this end, you will have to include a set of files in your solution.)
- CTracer.h(CTracer.h):这是用来挂钩(: This is used to hook)
OutputDebugString
从您的程序调用.(calls from your program.) - 套接字句柄(SocketHandle.h),(,)cpp(cpp):用于与ScriptRunner通信的套接字API.(: Socket API used to communicate with ScriptRunner.)
- HookImportFunction.h(HookImportFunction.h),(,)cpp(cpp):PJ Naughter的挂钩导入功能((: PJ Naughter’s Hook Import function () 点击这里(Click here) )(版权所有©1999; PJ Naughter)()(Copyright © 1999; PJ Naughter))
项目信息(Project Info)
该工具使用:(This tool uses:)
- BrainChild编辑器控件(BrainChild Editor control) :(版权所有©2002-2007; Jan van den Baard)(: (Copyright © 2002-2007; Jan van den Baard))
- WTL7.5(WTL7.5) (版权所有©2006; Microsoft Corp.)((Copyright © 2006; Microsoft Corp.))
- XPCommandBarCtrl(XPCommandBarCtrl) (版权©2001-2002; Bjarke Viksoe)((Copyright © 2001-2002; Bjarke Viksoe))
历史(History)
- 2007年3月25日-公开发布(March 25, 2007 - Public release)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VC8.0 C++ VC7.1 WinXP Win2003 Win2K ATL Visual-Studio QA Dev 新闻 翻译