Selenium是一个很好用的Web界面测试框架。但它的功能也有不足之处,比如: 在Selenium IDE中不支持程序控制语句。下面介绍如何在Selenium IDE中添加程序控制功能。
1)下载Selenium插件 (sideflow.js):
如果不想下载,直接把下面的代码保存到本机也可。
var gotoLabels= {};
var whileLabels = {};
// overload the original Selenium reset function
Selenium.prototype.reset = function() {
// reset the labels
this.initialiseLabels();
// proceed with original reset code
this.defaultTimeout = Selenium.DEFAULT_TIMEOUT;
this.browserbot.selectWindow("null");
this.browserbot.resetPopups();
}
Selenium.prototype.initialiseLabels = function()
{
gotoLabels = {};
whileLabels = { ends: {}, whiles: {} };
var command_rows = [];
var numCommands = testCase.commands.length;
for (var i = 0; i < numCommands; ++i) {
var x = testCase.commands[i];
command_rows.push(x);
}
var cycles = [];
for( var i = 0; i < command_rows.length; i++ ) {
if (command_rows[i].type == 'command')
switch( command_rows[i].command.toLowerCase() ) {
case "label":
gotoLabels[ command_rows[i].target ] = i;
break;
case "while":
case "endwhile":
cycles.push( [command_rows[i].command.toLowerCase(), i] )
break;
}
}
var i = 0;
while( cycles.length ) {
if( i >= cycles.length ) {
throw new Error( "non-matching while/endWhile found" );
}
switch( cycles[i][0] ) {
case "while":
if( ( i+1 < cycles.length ) && ( "endwhile" == cycles[i+1][0] ) ) {
// pair found
whileLabels.ends[ cycles[i+1][1] ] = cycles[i][1];
whileLabels.whiles[ cycles[i][1] ] = cycles[i+1][1];
cycles.splice( i, 2 );
i = 0;
} else ++i;
break;
case "endwhile":
++i;
break;
}
}
}
Selenium.prototype.continueFromRow = function( row_num )
{
if(row_num == undefined || row_num == null || row_num < 0) {
throw new Error( "Invalid row_num specified." );
}
testCase.debugContext.debugIndex = row_num;
}
// do nothing. simple label
Selenium.prototype.doLabel = function(){};
Selenium.prototype.doGotolabel = function( label )
{
if( undefined == gotoLabels[label] ) {
throw new Error( "Specified label '" + label + "' is not found." );
}
this.continueFromRow( gotoLabels[ label ] );
};
Selenium.prototype.doGoto = Selenium.prototype.doGotolabel;
Selenium.prototype.doGotoIf = function( condition, label )
{
if( eval(condition) ) this.doGotolabel( label );
}
Selenium.prototype.doWhile = function( condition )
{
if( !eval(condition) ) {
var last_row = testCase.debugContext.debugIndex;
var end_while_row = whileLabels.whiles[ last_row ];
if( undefined == end_while_row ) throw new Error( "Corresponding 'endWhile' is not found." );
this.continueFromRow( end_while_row );
}
}
Selenium.prototype.doEndWhile = function()
{
var last_row = testCase.debugContext.debugIndex;
var while_row = whileLabels.ends[ last_row ] - 1;
if( undefined == while_row ) throw new Error( "Corresponding 'While' is not found." );
this.continueFromRow( while_row );
}
下载地址: https://github.com/darrenderidder/sideflow
2)在Selenium中配置插件。如下图所示,添加sideflow.js 到 "Selenium Core extensions (user-extensions.js)" 文本框中,重新启动Selenium IDE。
3) 这样就可以在Selenium中使用流程控制了,例如
- 大小: 49.6 KB
- 大小: 72.5 KB
分享到:
相关推荐
综述Web系统功能测试工—selenium的安装使用及问题.综述Web系统功能测试工—selenium的安装使用及问题.综述Web系统功能测试工—selenium的安装使用及问题.
Web测试:Selenium使用 Web测试:Selenium使用 Web测试:Selenium使用
使用Selenium测试Web项目 测试项目 一个Web项目被测试。 该项目的GitHub存储库位于以下链接: : 。 测试用例设计文档以进行测试 准备用于设计测试用例以进行测试的文档。 该文档可通过以下链接获得: : 测试工具 ...
内含java支持包和服务包 如何使用,还是自己看文档吧 selenium
基于Selenium的web自动化测试
selenium WEB 测试工具,开源工具。 主要是做保存,可以在公司下载。
使用Java+Maven+Selenium+TestNG+Jedis+Jenkins搭建的WebUI自动化测试框架,资源的大体介绍如下链接http://note.youdao.com/noteshare?id=dc564343fd126f497074f6d7560c9f5e&sub=387EB3B1BAC945CEA71A5BDBC6484473
包含:selenium-core-1.0.1.zip、selenium-grid-1.0.4-bin.tar.bz2和selenium-remote-control-1.0.2.zip,欢迎下载!
python selenium 测试报告
web自动化测试框架及实践,应用python+selenium+pytest集成了web页面的功能巡检、写测试报告以及邮件发送测试结果等功能。
基于Selenium的Web自动化测试研究,姜莹,王洪波,随着Web应用的发展普及,Web系统的规模和复杂度不断增加,Web系统的测试面临着巨大的挑战。传统的软件测试技术和方法并不完全适用于
selenium_java.rar 博文链接:https://dtrex.iteye.com/blog/509561
于Selenium的Web自动化测试_P0_环境准
selenium IDE工具界面详解
selenium测试工具搭建,web测试详细讲解
基于Python+Selenium的web自动化测试框架的设计与实现.doc
Python测试驱动开发:使用Django、Selenium和JavaScript进行Web编程
使用selenium进行软件测试,里面有很多常用的方法。
《Selenium测试实践:基于电子商务平台》对开源自动化测试工具Selenium进行了详细介绍,帮助读者熟练掌握Selenium的使用方法。《Selenium测试实践:基于电子商务平台》将电子商务平台下的Selenium测试技巧通过具有代 ...
Selenium (WEB自动化工具/爬虫):本文包含WEB自动化,以及爬虫使用方法 本文详细介绍了Selenium Python版本的自动化测试方法和实践,通过本文学习你将掌握如下内容:Selenium 测试环境搭建单元测试、生成测试报告...