Selenium TestRunner和Core扩展

[b]Selenium Test Runner[/b]
当我们建立了大量的Suite文件和Test文件,要进行大规模的测试执行时,采用Selenium IDE的方式就不怎么方便了,这是可以采用Selenium Test Runner模式。

再Selenium IDE工具栏中点击(play with selenium testrunnner)进入Selenium Test Runner
观察地址栏,发现其中有几个参数
chrome://selenium-ide-testrunner/content/selenium/TestRunner.html?test=/content/PlayerTestSuite.html&userExtensionsURL=&baseUrl=

test: 指定存放再本地或服务器上的Suite文件,本地文件可以用file://协议打开,服务器上的用http://协议打开
userExtensionsURL
baseUrl: 相对URL地址,在此设置www.google.cn后,open命令‘/’,打开的是www.google.cn页面。

selenium_suite.html文件
<?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://cn.calendar.yahoo.com/" />
<title>selenium_1</title>
</head>
<body>
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium">
<tbody>
<tr><td><b>Example one</b></td></tr>
<tr><td><b><a href="/home/xace/coding/selenium_case1.html">test case1</a></b></td></tr>
</tbody></table>
</body>
</html>


selenium_case1.html文件
<?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://cn.calendar.yahoo.com/" />
<title>selenium_case1</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">selenium_case1</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>username</td>
<td>zhangyc.beijing</td>
</tr>
<tr>
<td>type</td>
<td>passwd</td>
<td>不知道</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//input[@value='登录']</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>[登出, 我的帐户]</td>
<td></td>
</tr>

</tbody></table>
</body>
</html>


url地址:
chrome://selenium-ide-testrunner/content/selenium/TestRunner.html?test=file:///home/xace/coding/selenium_suite.html&userExtensionsURL=,&baseUrl=http://cn.calendar.yahoo.com


再selenium/selenium-core/tests目录中,有更多的例子,可以通过
chrome://selenium-ide-testrunner/content/selenium/TestRunner.html?test=file://xxx/selenium/selenium-core/tests/TestSuite.html&userExtensionsURL=,&baseUrl=



/home/xace/.mozilla/firefox/tmug0k1u.default/extensions/{a6fd85ed-e919-4a43-a5af-8da18bda539f}
chrome://selenium-ide-testrunner/content/selenium/TestRunner.html


[b]Selenium Core扩展及其应用[/b]

在实际应用中,我们会发现selenium core提供的命令不能完全满足深层次的需求。每个公司的业务和产品都或多或少存在差异,绝大多数外部的测试工具都不能完全满足深层次的测试需求,这时selenium提供了很好的扩充机制就派上用处了。

[b]Seleniun的基本机制[/b]

[b]1 核心代码在哪?[/b]
Selenium core是一个jar包,位于/home/{user}/.mozilla/firefox/xxxxxxx.default/extensions/{a6fd85ed-e919-4a43-a5af-8da18bda539f} ; C:\Documents and Settings\{user}\Application Data\Mozilla\Firefox\Profiles\xxxxxxx.default\extensions\{a6fd85ed-e919-4a43-a5af-8da18bda539f}。{user}是当前的系统用户,xxxxxx.dufault是序列。
用rar解压selenium-ide.jar,可以在contents\selenium\script\目录下找到一个文件selenium-api.js,我们之前用的命令(click select check等)就在此处,对应关键字doClick doSelect doCheck。

[b]2 代码分析[/b]
do开头的命名方式表示该API是一个动作(action)命令。
Selenium.prototype.doClick = function(locator) {
// 找到相应的DOM节点,通过id name xpath document等方式查找
var element = this.browserbot.findElement(locator);
// 实现点击DOM节点操作
this.browserbot.clickElement(element);
};

browserbot的方法再在 selenium-browserbot.js中

[b]3 对selenium命令进行扩展[/b]
动作命令API
在 selenium-api.js中加入
Selenium.prototype.doHello = function() {
throw new SeleniumError("hello");
// 执行到hello关键字时,在表格的第3列写入hello,并标红
};
测试文件
<tr>
<td>hello</td>
<td></td>
<td></td>
</tr>


断言命令API
Selenium.prototype.isHello = function(text) {
var originalText = "hello";
if(originalText == text){
return true;
}
return false;
};
测试文件
<tr>
<td>verifyHello</td>
<td>hello</td>
<td></td>
</tr>
<tr>
<td>verifyHello</td>
<td>hi is not hello</td>
<td></td>
</tr>

Selenium.prototype.getHello = function(text) {
return "hello";
};
测试文件
<tr>
<td>verifyHello</td>
<td></td>
<td>hello</td>
</tr>
<tr>
<td>verifyHello</td>
<td></td>
<td>hi is not hello</td>
</tr>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值