Selenium Test Runner
当我们建立了大量的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
Selenium Core扩展及其应用
在实际应用中,我们会发现selenium core提供的命令不能完全满足深层次的需求。每个公司的业务和产品都或多或少存在差异,绝大多数外部的测试工具都不能完全满足深层次的测试需求,这时selenium提供了很好的扩充机制就派上用处了。
Seleniun的基本机制
1 核心代码在哪?
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。
2 代码分析
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中
3 对selenium命令进行扩展
动作命令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>
分享到:
相关推荐
To run Selenium tests exported from the legacy IDE, use the Selenium Html Runner.
免费 selenium-html-runner-3.5.2
seleniumtest.exe
可用于selenium自动化测试中的一个jar包,selenium-html-runner-3.5.0.jar
selenium-html-runner,测试脚本录制
Selenium可按两种模式来使用:test runner(selenium-core) 和 driven(selenium-rc)。 1、这两种模式在复杂性和编写方式方面有所不同: Driven 测试脚本编写起来往往要更复杂一些,因为它们是用编 程语言编写的。...
Coach Selenium Test
nodejs-selenium-runner 一个用于下载和启动Selenium Server的库。 重写 ,支持在定义的端口上运行。 一个用于下载和启动Selenium Server的库。 var seleniumRunner = require ( 'selenium-runner' ) ...
Selenium Core 是一个用来测试 Web 应用的测试工具。Selenium Core的测试直接运行在浏览器中,就像真实的用户在操作一样。它可以分别运行在 Windows,Linux 和 Macintosh 系统的 Internet Explorer,Mozilla 和 Fire...
FlexUISelenium是一个扩展客户机驱动Selenium RC,使得Selenium RC客户机驱动程序进行交互(和测试)Flex UI组件和方法的Flex应用程序。
seleniumTest
Graphene 项目的目的是使用非常性感的类型安全的 API 进行 Ajax 测试,是 Selenium 项目的扩展。 标签:Graphene
selenium selenium selenium selenium selenium selenium selenium selenium selenium selenium selenium selenium selenium selenium
通过C#调用谷歌浏览器,可以实现动态网页信息爬取,也可以实现自动化测试。参考博客教程:https://blog.csdn.net/Leaderxin/article/details/102923172
Selenium Core实例所用的JavaScript代码
Selenium 3.x不再能够直接运行SeleniumRC,而是通过仿真和WebDriverBackedSelenium接口来实现它。下载版本3.141.59以运行从遗留IDE导出的Selenium测试,使用SeleniumHTMLRunner。要在网格配置中使用SeleniumServer,...
Selenium 是 ThoughtWorks 专门为 Web 应用程序编写的一个验收测试...Selenium 测试可以在 Windows、Linux 和 MacintoshAnd 上的 Internet Explorer、Mozilla 和 Firefox 中运行。其他测试工具都不能覆盖如此多的平台。
Selenium
一个基于chart部署应用的模板
selenium_test.py