`
yutiansky
  • 浏览: 193209 次
  • 性别: Icon_minigender_1
  • 来自: 本溪
社区版块
存档分类
最新评论

Selenium循环测试,使用变量,抓屏

阅读更多

一,前言

  Selenium是测试Web应用程序的很好的客户端工具。这里举例说明如何写循环测试的脚本。

 

二,需要的工具

  1,Selenium : http://seleniumhq.org/download/

 

 

 

  2,sideflow.js : https://github.com/darrenderidder/sideflow

    也可从附件中得到。

 

 

 

 

三,把【sideflow.js】安装到SelehniumCore中。


 

 

四,扩展抓屏函数(captureEntirePageScreenshot)

  原装的 captureEntirePageScreenshot 不能用动态文件名,就限制了抓多图的功能。为了解决这个问题,只要在扩展 js 中加入下面代码就行啦。

  我的附件中加了这段代码。

Selenium.prototype.doMySave = function( arg )
{
    this.doCaptureEntirePageScreenshot(eval(arg), "");
}
 

五,给个例子。

 

 

<?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.iteye.com/" />
<title>test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">test</td></tr>
</thead><tbody>
<tr>
	<td>store</td>
	<td>0</td>
	<td>count</td>
</tr>
<tr>
	<td>while</td>
	<td>storedVars.count++ &lt; 3</td>
	<td></td>
</tr>
<!--// WHILE START-->
<tr>
	<td>open</td>
	<td>/login</td>
	<td></td>
</tr>
<tr>
	<td>type</td>
	<td>id=user_name</td>
	<td>aaa</td>
</tr>
<tr>
	<td>type</td>
	<td>id=password</td>
	<td>123</td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>id=button</td>
	<td></td>
</tr>
<tr>
	<td>mySave</td>
	<td>var str1 = 'd:\\test'; var str2 = '.png'; str1 + storedVars.count + str2</td>
	<td></td>
</tr>
<!--// WHILE END-->
<tr>
	<td>endWhile</td>
	<td></td>
	<td></td>
</tr>
</tbody></table>
</body>
</html>
 


 

  • 大小: 40 KB
  • 大小: 8 KB
  • 大小: 16.5 KB
  • 大小: 57.5 KB
分享到:
评论
1 楼 shouchun_w 2013-03-28  
写的非常翔实!辛苦了!

我在按照你的“扩展抓屏函数”(命令完全一样)运行时发生了如下错误,麻烦帮忙看一下哪里出了问题? 谢谢!

[error] Unexpected Exception: QueryInterface -> function QueryInterface() { [native code] }, message -> Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIFileOutputStream.init], result -> 2147500037, name -> NS_ERROR_FAILURE, filename -> chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js, lineNumber -> 2967, columnNumber -> 0, location -> JS frame :: chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js :: anonymous :: line 2967, inner -> null, data -> null, initialize -> function initialize() { [native code] }

相关推荐

Global site tag (gtag.js) - Google Analytics