【Katalon recorder】
katalon主页:Katalon | Simplify Web, API, Mobile, Desktop Automated Tests
katalon文档:Welcome to Katalon Docs | Katalon Docs
sample suite下载页面: https://github.com/katalon-studio/katalon-recorder-samples
常用关键字:
location@class:获取元素class属性,通过长度判断是否点击。
storeEval javascript:输入文本text包含当前时间,年月日。
if elseif else endif:通过变量长度(数字类型不加引号),判断是否执行代码。
if endif:0是false,1是true,通过变量值(数字类型不加引号),判断是否执行代码。
while endwhile:循环执行while代码。
if else endif:(数字判断不加引号)通过查询条件,判断页面是否有数据,并保存打印数据列表。
if else endif:(文本判断需要加引号)通过识别页面的文本值,判断文本是否相同,执行代码块。
label goto if:通过判断文本内容,跳过某个代码块,或者跳到某个代码块。
获取页面文本值,开始判断
①如果不等于待结算,就判断是否等于已创建;
②如果不等于已创建,就切换已创建和全部页面,用于更新状态,更新完,再次判断是否等于待结算;
①如果等于待结算,就跳过(切换状态判断、已创建判断)
②如果不等于待结算,等于已创建,就跳到(已创建判断模块)
write tocsv | loadVars:创建并写入内容到.csv文本,读取文本,依次取出,循环使用。
获取文本text,内容:
【seleniumIDE】
标题:RFide,SeleniumIDE使用Store-while-endwhile循环执行case,注册账户
环境:办公测试环境。
背景:测试过程中,需要很多新数据做差异化测试任务,手动注册耗时长且枯燥,循环执行注册脚本有利于身心健康。
方法:通过前置条件,准备好注册必填项(如身份证、银行卡、手机号等信息),然后通过判断+递增的方式循环注册新用户。
步骤:手动注册一次,记录好必填项(如身份证、银行卡、手机号等信息),通过Store-while-endwhile循环执行case,注册账户
关键字:store 10 j,store 1 j,while ${i}<=${j},fireEvent id=XXX blur/focus,type改为typekeys,storeEval ${i}+1 i,end while
命令:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://www.yidai.co/" />
<title>PC注册新用户</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">PC注册新用户</td></tr>
</thead><tbody>
<tr>
<td>store</td>
<td>10</td>
<td>j</td>
</tr>
<tr>
<td>store</td>
<td>1</td>
<td>i</td>
</tr>
<tr>
<td>while</td>
<td>${i}<=${j}</td>
<td></td>
</tr>
...//(此句为分隔线,不用复制,代替中间内容省略一万字)
<tr>
<td>fireEvent</td>
<td>id=smsCode</td>
<td>blur</td>
</tr>
<tr>
<td>pause</td>
<td>1000</td>
<td></td>
</tr>
<tr>
<td>fireEvent</td>
<td>xpath=.//*[@id='reg_step2']</td>
<td>focus</td>
</tr>
<tr>
<td>click</td>
<td>xpath=.//*[@id='reg_step2']</td>
<td></td>
</tr>
...//(此句为分隔线,不用复制,代替中间内容省略一万字)
<tr>
<td>storeBodyText</td>
<td>comment</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${comment}</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>${i}+1</td>
<td>i</td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
...//(此句为分隔线,不用复制,代替中间内容省略一万字)
贴图:
备注:
1.问题一,注册页面提交按钮超时,手动执行可以点中,却怎么也无法执行自动连贯点击,导致变成半自动case。
处理办法是使用fireEvent id=XXX blur/focus,激活并失去提交按钮之前的文本框焦点后,聚焦定位到需要点击的提交按钮,加入Pause后执行成功。
2.问题二,文本框输入密码后,原设计是输入第六位自动提交密码,通过type无法触发提交状态。
处理办法是将type改为typekeys关键字,即刻成功触发。
3.问题三,由于链接地址重定向导致页面弹出的安全警告,由于获取不到地址,无法定位和点击。
处理办法是改掉源头问题,把重定向提示框屏蔽,将地址栏中的S去掉。
4.问题四,由于注册时,姓名不能写阿拉伯数字,IDE自带关键字不能转换数字为中文大写汉子,需要扩展js文本。
处理办法,如下列附件~
user-extention.js文本源码如下(文件来自小七大神,给小七点赞):
标题:user-extention.js
Selenium.prototype.doStoreRandom = function(variableName,value){
var dic = new Array(); //注意它的类型是Array
dic[0] = "零";
dic[1] = "一";
dic[2] = "二";
dic[3] = "三";
dic[4] = "四";
dic[5] = "五";
dic[6] = "六";
dic[7] = "七";
dic[8] = "八";
dic[9] = "九";
var sValue = value.toString()
ll = sValue.length
if(ll == 1)
{
storedVars[variableName] = dic[value];
}
else if(ll > 1) {
var tt = ''
for(var i=0;i<ll;i++)
{
tt = tt + dic[parseInt(sValue[i])];
}
storedVars[variableName] = tt;
}
}
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 );
}