[译]网络重播2-自动化的网络测试
By robot-v1.0
本文链接 https://www.kyfws.com/applications/web-replay-2-automated-web-testing-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 7 分钟阅读 - 3486 个词 阅读量 0[译]网络重播2-自动化的网络测试
原文地址:https://www.codeproject.com/Articles/11332/Web-Replay-2-Automated-Web-Testing
原文作者:Emmanuel Kartmann
译文由本站 robot-v1.0 翻译
前言
This article presents an automated software testing tool for web applications (Internet/Intranet) based on Internet Explorer.
本文介绍了一种基于Internet Explorer的针对Web应用程序(Internet/Intranet)的自动化软件测试工具.
- 下载网络重播二进制可执行文件-171 Kb(Download web replay binary executable - 171 Kb)
- 下载源-281 Kb(Download source - 281 Kb)
介绍(Introduction)
Web Replay 2是(Web Replay 2 is an)Web应用程序的自动化软件测试工具(automated software testing tool for Web applications).通过重播场景以测试应用程序,它有助于检测Web应用程序中的错误和回归.使用Web Replay 2,您可以(. It helps in detecting bugs and regressions in web applications by replaying scenarios to test the application. Using Web Replay 2, you can)**自动地(automatically)**导航(navigate)**到网页(to a web page,)**填写(fill in)**表格栏位(form fields,)**点击(click)**单击提交(确定)按钮,然后继续到另一个网页.要使用Web Replay 2,(on the Submit (OK) button, and then continue to another web page. To use Web Replay 2,)生成一个JavaScript场景文件(build a JavaScript Scenario File)(请参见下文),在编辑框中输入文件名,然后单击"重播"按钮.((see below), type the name of the file in the edit box and click on the Replay button.)
背景(Background)
Web Replay 2基于Microsoft的Internet Explorer 6.0,(Web Replay 2 is based on Microsoft’s Internet Explorer 6.0,) DHTML行为(DHTML behaviors) 和JavaScript(与(and JavaScript (unlike) 网络重播1(Web Replay 1) 在C ++/COM中实现).(that was implemented in C++/COM).)
Web Replay 2使用FRAMESET并将DHTML行为附加到(Web Replay 2 uses a FRAMESET with a DHTML behavior attached to the) onload
底部框架的事件,以执行一些JavaScript代码来播放场景.它仅在脚本中实现(在Internet Explorer中运行的客户端JavaScript和在ASP页面中运行的服务器端JavaScript).(event of the bottom frame to execute some JavaScript code to play back a scenario. It’s implemented in script only (client-side JavaScript running in Internet Explorer and server-side JavaScript running in ASP pages).)
因此,Web Replay 2为您提供了(As a consequence, Web Replay 2 gives you)*完全访问Microsoft Internet Explorer文档对象模型(DOM)(full access to the Microsoft Internet Explorer Document Object Model (DOM))*在您的方案文件中.并且由于该场景是JavaScript程序,因此您几乎可以实现任何测试用例.(within your scenario files. And since the scenario is a JavaScript program, you can implement virtually any test case.)
使用功能(Using the function) WebReplay_Navigate()(WebReplay_Navigate()) ,您可以调用服务器端代码在测试用例上实现前提条件和后置条件(例如,建立数据库或检查创建/修改的记录是否正确).(, you can call the server-side code to implement pre-conditions and post-conditions on your test cases (e.g. setting up a database or checking whether the created/modified records are correct).)
使用代码(Using the code)
Web重播提供以下功能:(Web Replay provides the following features:)
-
从JavaScript文件重播场景.(Replay scenarios from a JavaScript file.)
-
支持Microsoft Internet Explorer支持的所有功能(包括Windows集成身份验证).(Support every feature supported by Microsoft Internet Explorer (includes Windows Integrated Authentication).)
-
支持HTML表单,HTML输入元素,HTML超链接(锚).(Support HTML forms, HTML input elements, HTML hyperlinks (anchors).)
-
支持(Support)对JavaScript中可用的HTML元素的任何操作(any action on HTML elements available in JavaScript)(改变价值,引发事件等).((changing value, raising events, etc…).)
-
支持未命名的HTML元素:可以找到具有关联值和/或innerText和/或HREF的元素(可以基于ANY属性的值找到HTML元素).(Support unnamed HTML elements: elements can be found with their associated value and/or innerText and/or HREF (an HTML element can be found based on the value of ANY attribute).)
-
支持动态生成的网站(客户端):如果您的网站在浏览器中生成HTML(使用JavaScript命令,例如"(Support dynamically-generated Web Sites (client-side): If your web site generates HTML within the browser (using JavaScript’s commands like “)
document.write
“),Web Replay 2仍然可以播放给定场景-它使用超时机制来查找动态生成的控件.("), Web Replay 2 can still play back a given scenario - it uses a timeout mecanism to find the dynamically-generated controls.) -
基于JavaScript正则表达式模式匹配来检测HTTP错误和/或应用程序错误.(Detect HTTP errors and/or Application errors based on JavaScript regular expression pattern matching.)
-
支持简单的对话框("(Support simple dialog boxes (") 警报(alert) “和”(” and “) 确认(confirm) “方法).网络重播会覆盖(” methods). Web Replay overrides the)
window.alert
和(and)window.confirm
具有实现场景播放的自定义实现的方法.(methods with custom implementations which handles scenario playback.) -
仅适用于同一域中的服务器的重播方案(被测试的网站必须与Web Replay应用程序位于同一域中).这是由于Internet Explorer(跨站点脚本)中的安全限制所致.有关此限制的更多信息,请参考以下MSDN文章:(Replay scenarios for servers on the same domain only (the tested web site must be on the same domain as the Web Replay application). This is due to a security limitation in Internet Explorer (cross-site scripting). For more on this limitation, please refer to the following MSDN articles:)
一个JavaScript方案文件包含一个名为的函数的定义(A JavaScript scenario file consists of a definition of a function named) WebReplayScenario();
它看起来像这样:(it looks like this:)
function WebReplayScenario()
{
switch (gintState)
{
case 0:
// Open a web page (LOCALHOST only due
// to cross-site scripting limitations)
<A href="http://perso.wanadoo.fr/replay.grasse/freeware/WebReplay2/WebReplay2/WebReplaySDK.htm#WebReplay_Navigate" target=_blank>WebReplay_Navigate</A>(
"http://localhost/WebReplay2/WebReplay2Scenario1_step1.asp");
break;
case 1:
// Type in some text in a form field
<A href="http://perso.wanadoo.fr/replay.grasse/freeware/WebReplay2/WebReplay2/WebReplaySDK.htm#WebReplay_SimulateTextInput" target=_blank>WebReplay_SimulateTextInput</A>("Text1", "NewValue1");
break;
case 2:
// Submit form by clicking on a submit button
<A href="http://perso.wanadoo.fr/replay.grasse/freeware/WebReplay2/WebReplay2/WebReplaySDK.htm#WebReplay_SimulateHTMLElementClick" target=_blank>WebReplay_SimulateHTMLElementClick</A>("OK");
break;
default:
// Automatically exit from scenario
<A href="http://perso.wanadoo.fr/replay.grasse/freeware/WebReplay2/WebReplay2/WebReplaySDK.htm#WebReplay_SetStateNext" target=_blank>WebReplay_SetStateNext</A>(-1);
break;
}
}
该功能实现了(This function implements a)状态机(state-machine)基于全局变量(based on the global variable) gintState
;每次请求的操作成功(例如,单击按钮)时,状态都会增加1(状态从0开始).状态设置为(; every time the requested action is successful (e.g. clicking on a button), the state is increased by 1 (state starts at 0). The state is set to)-1(-1)方案完成时.如果发生任何错误,则将状态设置为(when the scenario is finished. In case of any error, the state is set to)-2(-2).(.)
实用功能(The utility function) WebReplayScenarioAuto()(WebReplayScenarioAuto()) 可以简化构建方案的过程-其输入是简单的状态数组(状态机已经实现-无需管理状态机(can ease the process of building scenario - its input is a simple array of states (the state-machine is already implemented - no need to manage the) switch
和州号):(and state numbers):)
function WebReplayScenario()
{
<A href="http://perso.wanadoo.fr/replay.grasse/freeware/WebReplay2/WebReplay2/WebReplaySDK.htm#WebReplayScenarioAuto" target=_blank>WebReplayScenarioAuto</A>(
[
// State 1: Navigate to the test Page
// (uses an anonymous function definition)
[ null, function () { <A href="http://perso.wanadoo.fr/replay.grasse/freeware/WebReplay2/WebReplay2/WebReplaySDK.htm#WebReplay_Navigate" target=_blank>
WebReplay_Navigate</A>(
"http://localhost/WebReplay2/WebReplay2Scenario1_step1.asp") }],
// State 2: Type in some text in a form field named Text1
[ "Text1", "NewValue1" ],
// State 3: Submit form by clicking on a submit button named "OK"
[ "OK" ],
// State 4: Type in some text in a form field named Text21
[ "Text1", "NewValue2" ],
// State 5: Submit form by clicking on a submit button named "OK"
[ "OK" ],
// State 6: Wait for next page's title:
// <h2>Form Submit Debugger</h2>
// Set state to -1 (end) when the control is found.
[ null, function () { <A href="http://perso.wanadoo.fr/replay.grasse/freeware/WebReplay2/WebReplay2/WebReplaySDK.htm#WebReplay_WaitForHTMLControl" target=_blank>
WebReplay_WaitForHTMLControl</A>("h2", "innerText",
"Form Submit Debugger", -1) } ]
]
);
}
一种(A) 完整的JavaScript SDK(complete JavaScript SDK) 可用于构建方案文件;当然,您可以使用自己的JavaScript代码扩展SDK …(is available to build the scenario files; and of course, you can extend the SDK with your own JavaScript code…)
要构建场景文件,您需要基本了解Web应用程序中HTML元素的名称(或ID)(使用函数(To build a scenario file, you need to basically know the names (or ids) of the HTML elements within your web application (using the function) WebReplay_FindHTMLControlWithName(WebReplay_FindHTMLControlWithName) ).或者,您可以使用控件的内容(文本)与其进行交互(使用功能(). Alternatively, you can use the content (text) of a control to interact with it (using functions) WebReplay_FindAnchorWithText(WebReplay_FindAnchorWithText) ,(,) WebReplay_FindButtonWithText(WebReplay_FindButtonWithText) , 要么(, or) WebReplay_FindHTMLControlFromText(WebReplay_FindHTMLControlFromText) ).().)
您可以使用以下三个功能与HTML控件进行交互:(You can interact with the HTML controls using these three functions:)
- WebReplay_SimulateCheckboxInput(WebReplay_SimulateCheckboxInput) :选中或取消选中(: to check or uncheck a)
Checkbox
控制.(control.) - WebReplay_SimulateHTMLElementClick(WebReplay_SimulateHTMLElementClick) :单击任何控件.(: to click on any control.)
- WebReplay_SimulateTextInput(WebReplay_SimulateTextInput) :在文本输入中键入一些文本.(: to type some text in a text input.)
兴趣点(Points of interest)
尽管是完全重写(v2.1与(Although it’s a complete re-write (v2.1 has nothing to do with) 网络重播v1.0(Web Replay v1.0) ),TODO清单仍然很长.(), the TODO list is still long.)
Web Replay 2 TODO列表(Web Replay 2 TODO list)
- 自动记录方案文件.(Automated recording of scenario files.)
- 多次播放场景(甚至无限循环以对您的Web应用程序进行压力测试).(Play scenarios multiple times (even infinite loops to stress-test your web application).)
- 批量播放场景文件.(Batch playback of scenario files.)
- 支持身份验证(NTLM,基本,https)和多个登录帐户.(Support authentication (NTLM, basic, https) and multiple login accounts.)
- 支持框架(多框架文档)或顶级框架网站.一些网站,例如(Support FRAMES (multi-frame documents) or top-FRAME web sites. Some web sites, like) 代码项目(CodeProject) ,请使用一段JavaScript来确保在顶级框架中对其进行查看; Web Replay 2与这些网站不兼容…(, use a piece of JavaScript to make sure that they are viewed within a top-level frame; Web Replay 2 is incompatible with those sites…)
- 使用事件日志文件(csv格式?)进行错误/跟踪/调试.(Use event log file (csv format?) for errors/tracing/debugging.)
- 支持复杂的对话框(基于方法(Support complex dialog boxes (based on methods) window.open(window.open) ,(,) window.showModalDialog(window.showModalDialog) 和/或(and/or) window.showModelessDialog(window.showModelessDialog) ).().)
历史(History)
- 2005-08-19,08:09:13 +0200(ven.,19août2005)-V2.1.(2005-08-19, 08:09:13 +0200 (ven., 19 août 2005) - V2.1.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# Javascript C++ Windows .NET .NET1.0 Visual-Studio ASP QA Dev 新闻 翻译