开源自动化测试框架 Tellurium

jopen 13年前
     <p class="p0"><span style="font-size:18pt;"><strong>Tellurium<span style="font-family:宋体;">是什么?</span></strong></span></p>    <p class="p0"><span style="font-size:16px;">Tellurium<span style="font-family:宋体;">是一种自动化的</span><span style="font-family:Times New Roman;">web</span><span style="font-family:宋体;">测试框架。虽然它是在</span><span style="font-family:Times New Roman;">selemium</span><span style="font-family:宋体;">的阶段上建立起来的,但两者之间有许多概念上的差异,</span><span style="font-family:Times New Roman;">Tellurium</span><span style="font-family:宋体;">的主要特点如下:</span></span></p>    <p class="p0"> </p>    <p><img title="开源自动化测试框架 Tellurium " border="0" alt="开源自动化测试框架 Tellurium " src="https://simg.open-open.com/show/bb4fed8e48b432d926f9b642b31eb8e6.png" width="381" height="315" /></p>    <p class="p0"> </p>    <ul>     <li class="p0"><span style="font-size:16px;">l 不是单一的“记录和播放”风格。</span></li>     <li class="p0"><span style="font-size:16px;">l 基于<span style="font-family:Times New Roman;">UI</span><span style="font-family:宋体;">模块,也就是说,它侧重于</span><span style="font-family:Times New Roman;">UI</span><span style="font-family:宋体;">元素</span></span></li>     <li class="p0"><span style="font-size:16px;">l 让你有结构化的代码执行用户界面和测试代码之间的解耦</span></li>     <li class="p0"><span style="font-size:16px;">l 鲁棒性的变化,Tellurium达到使用复合定位建立在运行时和组的定位器定位,删除里面的UI模块和外部UI元素的UI元素之间的依赖</span></li>     <li class="p0"><span style="font-size:16px;">l 表达所使用Groovy动态语言特性和DSL</span></li>     <li class="p0"><span style="font-size:16px;">l 可重复使用,用户界面模块可重复使用相同的应用程序和Tellurium部件,可用于不同的应用</span></li>     <li class="p0"><span style="font-size:16px;">l 地址在网络上的动态因素。UI模板使用数据网格和Tellurium UI对象的回应属性可以处理JavaScript事件</span></li>     <li class="p0"><span style="font-size:16px;">l 核心框架是在Groovy实现和测试,可以在Groovy中的JUnit,TestNG的,或纯DSL脚本书面</span></li>     <li class="p0"><span style="font-size:16px;">l 支持数据驱动测试</span></li>     <li class="p0"><span style="font-size:16px;">l 提供Maven原型</span></li>    </ul>    <p class="p0"> </p>    <p class="p0"><span style="font-size:18pt;">如何使用Tellurium?</span></p>    <p><img style="width:697px;height:469px;" title="开源自动化测试框架 Tellurium " border="0" alt="开源自动化测试框架 Tellurium " src="https://simg.open-open.com/show/10c123e4894c118ab3f64c62d57d5f33.png" /></p>    <p> </p>    <p> </p>    <p class="p0"><span style="font-size:18pt;"><strong>使用<span style="font-family:Times New Roman;">Maven</span><span style="font-family:宋体;">创建一个新的</span><span style="font-family:Times New Roman;">Tellurium </span><span style="font-family:宋体;">测试项目</span></strong></span></p>    <p class="p0"><span style="font-size:16px;"> 首先,你需要安装<span style="font-family:Times New Roman;">maven </span><span style="font-family:宋体;">,确保本机有</span><span style="font-family:Times New Roman;">maven</span><span style="font-family:宋体;">环境。关于</span><span style="font-family:Times New Roman;">maven</span><span style="font-family:宋体;">环境的搭建,可以参考的我的博客,关于</span><span style="font-family:Times New Roman;">maven</span><span style="font-family:宋体;">的文章:</span></span></p>    <p class="p0"><span style="font-size:16px;"><a href="/misc/goto?guid=4959500806481435272">http://www.cnblogs.com/fnng/category/345480.html</a></span></p>    <p class="p0"><span style="font-size:16px;">找到<span style="font-family:Times New Roman;">maven</span><span style="font-family:宋体;">目录下的</span>settings.xml 文件,我本机的路径在:<span style="font-family:Times New Roman;">F:\maven\apache-maven-3.0.3\conf</span>\<span style="font-family:宋体;">目录下。</span></span></p>    <p class="p0"><span style="font-size:16px;">打开文件,并在<span style="font-family:Times New Roman;color:#ff0000;"><profiles>....</profiles></span><span style="font-family:宋体;">之间添加如下信息:</span></span></p>    <p class="p0"> </p>    <div class="cnblogs_code">     <pre><span style="color:#ff0000;"><parofiles></span>     <span style="color:#0000ff;"><</span><span style="color:#800000;">profile</span><span style="color:#0000ff;">></span>         <span style="color:#0000ff;"><</span><span style="color:#800000;">activation</span><span style="color:#0000ff;">></span>                            <span style="color:#0000ff;"><</span><span style="color:#800000;">activeByDefault</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">activeByDefault</span><span style="color:#0000ff;">></span>                   <span style="color:#0000ff;"></</span><span style="color:#800000;">activation</span><span style="color:#0000ff;">></span>                   <span style="color:#0000ff;"><</span><span style="color:#800000;">repositories</span><span style="color:#0000ff;">></span>                            <span style="color:#0000ff;"><</span><span style="color:#800000;">repository</span><span style="color:#0000ff;">></span>                                     <span style="color:#0000ff;"><</span><span style="color:#800000;">id</span><span style="color:#0000ff;">></span>kungfuters-public-snapshots-repo<span style="color:#0000ff;"></</span><span style="color:#800000;">id</span><span style="color:#0000ff;">></span>                  <span style="color:#0000ff;"><</span><span style="color:#800000;">name</span><span style="color:#0000ff;">></span>Kungfuters.org Public Snapshot Repository<span style="color:#0000ff;"></</span><span style="color:#800000;">name</span><span style="color:#0000ff;">></span>                     <span style="color:#0000ff;"><</span><span style="color:#800000;">releases</span><span style="color:#0000ff;">></span>                          <span style="color:#0000ff;"><</span><span style="color:#800000;">enabled</span><span style="color:#0000ff;">></span>false<span style="color:#0000ff;"></</span><span style="color:#800000;">enabled</span><span style="color:#0000ff;">></span>                     <span style="color:#0000ff;"></</span><span style="color:#800000;">releases</span><span style="color:#0000ff;">></span>                          <span style="color:#0000ff;"><</span><span style="color:#800000;">snapshots</span><span style="color:#0000ff;">></span>                                <span style="color:#0000ff;"><</span><span style="color:#800000;">enabled</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">enabled</span><span style="color:#0000ff;">></span>                            <span style="color:#0000ff;"></</span><span style="color:#800000;">snapshots</span><span style="color:#0000ff;">></span>                                         <span style="color:#0000ff;"><</span><span style="color:#800000;">url</span><span style="color:#0000ff;">></span>http://maven.kungfuters.org/content/repositories/snapshots<span style="color:#0000ff;"></</span><span style="color:#800000;">url</span><span style="color:#0000ff;">></span>                   <span style="color:#0000ff;"></</span><span style="color:#800000;">repository</span><span style="color:#0000ff;">></span>                       <span style="color:#0000ff;"><</span><span style="color:#800000;">repository</span><span style="color:#0000ff;">></span>                           <span style="color:#0000ff;"><</span><span style="color:#800000;">id</span><span style="color:#0000ff;">></span>kungfuters-public-releases-repo<span style="color:#0000ff;"></</span><span style="color:#800000;">id</span><span style="color:#0000ff;">></span>                    <span style="color:#0000ff;"><</span><span style="color:#800000;">name</span><span style="color:#0000ff;">></span>Kungfuters.org Public Releases Repository<span style="color:#0000ff;"></</span><span style="color:#800000;">name</span><span style="color:#0000ff;">></span>                        <span style="color:#0000ff;"><</span><span style="color:#800000;">releases</span><span style="color:#0000ff;">></span>                                        <span style="color:#0000ff;"><</span><span style="color:#800000;">enabled</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">enabled</span><span style="color:#0000ff;">></span>                                 <span style="color:#0000ff;"></</span><span style="color:#800000;">releases</span><span style="color:#0000ff;">></span>                                      <span style="color:#0000ff;"><</span><span style="color:#800000;">snapshots</span><span style="color:#0000ff;">></span>                                 <span style="color:#0000ff;"><</span><span style="color:#800000;">enabled</span><span style="color:#0000ff;">></span>false<span style="color:#0000ff;"></</span><span style="color:#800000;">enabled</span><span style="color:#0000ff;">></span>                           <span style="color:#0000ff;"></</span><span style="color:#800000;">snapshots</span><span style="color:#0000ff;">></span>                                        <span style="color:#0000ff;"><</span><span style="color:#800000;">url</span><span style="color:#0000ff;">></span>http://maven.kungfuters.org/content/repositories/releases<span style="color:#0000ff;"></</span><span style="color:#800000;">url</span><span style="color:#0000ff;">></span>                   <span style="color:#0000ff;"></</span><span style="color:#800000;">repository</span><span style="color:#0000ff;">></span>                 <span style="color:#0000ff;"></</span><span style="color:#800000;">repositories</span><span style="color:#0000ff;">></span>          <span style="color:#0000ff;"></</span><span style="color:#800000;">profile</span><span style="color:#0000ff;">></span> <span style="color:#ff0000;"><parofiles></span></pre>    </div>    <p class="p0"> </p>    <p> </p>    <p class="p0"><span style="font-size:16px;">打开的你的命令提示符,切换到你的工作空间的目录下,运行下列<span style="font-family:Times New Roman;">Maven</span><span style="font-family:宋体;">命令来创建一个新的</span>Tellurium测试方案(<span style="font-family:宋体;">项目</span><span style="font-family:Times New Roman;">)"demo"</span></span></p>    <p class="p0"><strong><span style="color:#008080;font-size:16px;">mvn archetype:generate -DgroupId=example -DartifactId=demo -DarchetypeArtifactId=tellurium-junit-archetype -DarchetypeGroupId=tellurium -DarchetypeVersion=0.6.0</span></strong></p>    <p class="p0"><span style="font-size:16px;">然后切换到该项目的目录下执行:<strong>mvn  eclipse:eclipse</strong>   构建成我们的<span style="font-family:Times New Roman;">eclipse</span><span style="font-family:宋体;">所能识别的项目结构。</span></span></p>    <p class="p0"><span style="font-size:16px;"> </span></p>    <p class="p0"><span style="font-size:16px;">打开<span style="font-family:Times New Roman;">Eclipse</span><span style="font-family:宋体;">将我们构建完成的项目导入。完成后项目结构如下:</span></span></p>    <p class="p0"> </p>    <p><img title="开源自动化测试框架 Tellurium " border="0" alt="开源自动化测试框架 Tellurium " src="https://simg.open-open.com/show/a7ec27daee661fb6612bb09eea1ad7c2.png" width="278" height="319" /></p>    <p class="p0"><span style="font-size:16px;">在<span style="font-family:Times New Roman;">Telluriumconfig.groovy</span><span style="font-family:宋体;">文件中包含</span><span style="font-family:Times New Roman;">Tellurium</span><span style="font-family:宋体;">项目设置,你能根据你的需求对它进行自定义设置</span></span></p>    <p class="p0"> </p>    <div class="cnblogs_code">     <pre>tellurium{       <span style="color:#008000;">//</span><span style="color:#008000;">embedded selenium server configuration    </span><span style="color:#008000;"> </span>    embeddedserver {                  <span style="color:#008000;">//</span><span style="color:#008000;">port number         </span><span style="color:#008000;"> </span>        port = "4444"                 <span style="color:#008000;">//</span><span style="color:#008000;">whether to use multiple windows        </span><span style="color:#008000;"> </span>        useMultiWindows = <span style="color:#0000ff;">false</span>                  <span style="color:#008000;">//</span><span style="color:#008000;">whether to run the embedded selenium server. If false, you need to manually set up a selenium server        </span><span style="color:#008000;"> </span>        runInternally = <span style="color:#0000ff;">true</span>                  <span style="color:#008000;">//</span><span style="color:#008000;">profile location         </span><span style="color:#008000;"> </span>        profile = ""                 <span style="color:#008000;">//</span><span style="color:#008000;">user-extension.js file, for example, "target/test-classes/extension/user-extensions.js"         </span><span style="color:#008000;"> </span>        userExtension = ""          }     <span style="color:#008000;">//</span><span style="color:#008000;">event handler </span><span style="color:#008000;"> </span>    eventhandler{                 <span style="color:#008000;">//</span><span style="color:#008000;">whether we should check if the UI element is presented         </span><span style="color:#008000;"> </span>        checkElement = <span style="color:#0000ff;">false</span>                  <span style="color:#008000;">//</span><span style="color:#008000;">wether we add additional events like "mouse over"         </span><span style="color:#008000;"> </span>        extraEvent = <span style="color:#0000ff;">true</span>          }     <span style="color:#008000;">//</span><span style="color:#008000;">data accessor     </span><span style="color:#008000;"> </span>    accessor{                  <span style="color:#008000;">//</span><span style="color:#008000;">whether we should check if the UI element is presented</span><span style="color:#008000;"> </span>        checkElement = <span style="color:#0000ff;">true</span>          }      connector{         <span style="color:#008000;">//</span><span style="color:#008000;">selenium server host                  </span><span style="color:#008000;">//</span><span style="color:#008000;">please change the host if you run the Selenium server remotely </span><span style="color:#008000;"> </span>        serverHost = "localhost"                  <span style="color:#008000;">//</span><span style="color:#008000;">server port number the client needs to connect         </span><span style="color:#008000;"> </span>        port = "4444"                  <span style="color:#008000;">//</span><span style="color:#008000;">base URL         </span><span style="color:#008000;"> </span>        baseUrl = "http://localhost:8080"         <span style="color:#008000;">//</span><span style="color:#008000;">Browser setting, valid options are                 </span><span style="color:#008000;">//</span><span style="color:#008000;">  *firefox [absolute path]                  </span><span style="color:#008000;">//</span><span style="color:#008000;">  *iexplore [absolute path]                  </span><span style="color:#008000;">//</span><span style="color:#008000;">  *chrome                  </span><span style="color:#008000;">//</span><span style="color:#008000;">  *iehta </span><span style="color:#008000;"> </span>        browser = "*chrome"         <span style="color:#008000;">//</span><span style="color:#008000;">user's class to hold custom selenium methods associated with user-extensions.js                  </span><span style="color:#008000;">//</span><span style="color:#008000;">should in full class name, for instance, "com.mycom.CustomSelenium" </span><span style="color:#008000;"> </span>        customClass = ""      }     datadriven{                  dataprovider{                          <span style="color:#008000;">//</span><span style="color:#008000;">specify which data reader you like the data provider to use                          </span><span style="color:#008000;">//</span><span style="color:#008000;">the valid options include "PipeFileReader", "CVSFileReader" at this point             </span><span style="color:#008000;"> </span>            reader = "PipeFileReader"                  }          }          test{              <span style="color:#008000;">//</span><span style="color:#008000;">at current stage, the result report is only for tellurium data driven testing              </span><span style="color:#008000;">//</span><span style="color:#008000;">we may add the result report for regular tellurium test case         </span><span style="color:#008000;"> </span>        result{                          <span style="color:#008000;">//</span><span style="color:#008000;">specify what result reporter used for the test result                          </span><span style="color:#008000;">//</span><span style="color:#008000;">valid options include "SimpleResultReporter", "XMLResultReporter", and "StreamXMLResultReporter"             </span><span style="color:#008000;"> </span>            reporter = "XMLResultReporter"                         <span style="color:#008000;">//</span><span style="color:#008000;">the output of the result                         </span><span style="color:#008000;">//</span><span style="color:#008000;">valid options include "Console", "File" at this point                          </span><span style="color:#008000;">//</span><span style="color:#008000;">if the option is "File", you need to specify the file name, other wise it will use the default                          </span><span style="color:#008000;">//</span><span style="color:#008000;">file name "TestResults.output"             </span><span style="color:#008000;"> </span>            output = "Console"                          <span style="color:#008000;">//</span><span style="color:#008000;">test result output file name             </span><span style="color:#008000;"> </span>            filename = "TestResult.output"                  }                  exception{                          <span style="color:#008000;">//</span><span style="color:#008000;">whether Tellurium captures the screenshot when exception occurs.                          </span><span style="color:#008000;">//</span><span style="color:#008000;">Note that the exception is the one thrown by Selenium Server                          </span><span style="color:#008000;">//</span><span style="color:#008000;">we do not care the test logic errors here            </span><span style="color:#008000;"> </span>            captureScreenshot = <span style="color:#0000ff;">true</span>                          <span style="color:#008000;">//</span><span style="color:#008000;">we may have a series of screenshots, specify the file name pattern here                          </span><span style="color:#008000;">//</span><span style="color:#008000;">Here the ? will be replaced by the timestamp and you might also want to put                          </span><span style="color:#008000;">//</span><span style="color:#008000;">file path in the file name pattern             </span><span style="color:#008000;"> </span>            filenamePattern = "Screenshot?.png"                  }          }          uiobject{                 builder{                          <span style="color:#008000;">//</span><span style="color:#008000;">user can specify custom UI objects here by define the builder for each UI object                         </span><span style="color:#008000;">//</span><span style="color:#008000;">the custom UI object builder must extend UiObjectBuilder class                          </span><span style="color:#008000;">//</span><span style="color:#008000;">and implement the following method:                          </span><span style="color:#008000;">//</span><span style="color:#008000;">                          </span><span style="color:#008000;">//</span><span style="color:#008000;"> public build(Map map, Closure c)                          </span><span style="color:#008000;">//</span><span style="color:#008000;">                          </span><span style="color:#008000;">//</span><span style="color:#008000;">For container type UI object, the builder is a bit more complicated, please                          </span><span style="color:#008000;">//</span><span style="color:#008000;">take the TableBuilder or ListBuilder as an example                          </span><span style="color:#008000;">//</span><span style="color:#008000;">example: </span><span style="color:#008000;">//</span><span style="color:#008000;">        Icon="org.tellurium.builder.IconBuilder"                      </span><span style="color:#008000;"> </span>        }         }          widget{                 module{                          <span style="color:#008000;">//</span><span style="color:#008000;">define your widget modules here, for example Dojo or ExtJs </span><span style="color:#008000;">//</span><span style="color:#008000;"> </span>            included="dojo, extjs"                          included=""                  }          }           }  </pre>    </div>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;"> GoogleSearchModule.groovy<span style="font-family:宋体;">是用户界面模块的谷歌搜索,它自化生成</span><span style="font-family:Times New Roman;">Tellurium </span><span style="font-family:宋体;">所需要的火狐浏览器插件</span><span style="font-family:Times New Roman;">TrUMP.  </span>doGoogleSearch() 和 doImFeelingLucky() <span style="font-family:宋体;">两个方法是</span>增加定期谷歌搜索和谷歌<span style="font-family:Times New Roman;">“</span><span style="font-family:宋体;">手气不错</span><span style="font-family:Times New Roman;">”</span><span style="font-family:宋体;">搜索。</span></span></p>    <p class="p0"> </p>    <div class="cnblogs_code">     <pre><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> GoogleSearchModule <span style="color:#0000ff;">extends</span> DslContext {    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> defineUi() {         ui.Container(uid: "Google", clocator: [tag: "table"]) {            InputBox(uid: "Input", clocator: [tag: "input", title: "Google Search", name: "q"])            SubmitButton(uid: "Search", clocator: [tag: "input", type: "submit", value: "Google Search", name: "btnG"])            SubmitButton(uid: "ImFeelingLucky", clocator: [tag: "input", type: "submit", value: "I'm Feeling Lucky", name: "btnI"])          }     }      <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> doGoogleSearch(String input) {          keyType "Google.Input", input         pause 500         click "Google.Search"        waitForPageToLoad 30000     }     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> doImFeelingLucky(String input) {        type "Google.Input", input        pause 500       click "Google.ImFeelingLucky"        waitForPageToLoad 30000       }  }</pre>    </div>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;">因为<span style="font-family:Times New Roman;">Tellurium</span><span style="font-family:宋体;">只支持</span><span style="font-family:Times New Roman;">groovy</span><span style="font-family:宋体;">语言,所以无</span><span style="font-family:Times New Roman;">groovy</span><span style="font-family:宋体;">语言无法直接在</span><span style="font-family:Times New Roman;">Eclipse IDE</span><span style="font-family:宋体;">中运行,需要</span><span style="font-family:Times New Roman;">Eclipse</span><span style="font-family:宋体;">安装对</span><span style="font-family:Times New Roman;">groovy</span><span style="font-family:宋体;">语言支持的插件。</span></span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;">Groovy-Eclipse 2.5.1 插件下载地址:</span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;"><a href="/misc/goto?guid=4959500806578822968">http://www.oschina.net/news/19279/groovy-eclipse-251</a> </span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;">当然,你也可以使用<span style="font-family:Times New Roman;">IntelliJ IDEA </span><span style="font-family:宋体;">工具,它同样也运行</span><span style="font-family:Times New Roman;">java</span><span style="font-family:宋体;">语言非常优秀的</span><span style="font-family:Times New Roman;">IDE</span><span style="font-family:宋体;">。 而且</span><span style="font-family:Times New Roman;">IntelliJ IDEA</span><span style="font-family:宋体;">本身是支持</span><span style="font-family:Times New Roman;">groovy</span><span style="font-family:宋体;">语言。</span></span></p>    <p class="p0"> </p>    <p class="p0"> </p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:18pt;">Tellurium IDE <span style="font-family:宋体;">插件</span></span></p>    <p class="p0"> </p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;">这个同样也是基于<span style="font-family:Times New Roman;">firefox</span><span style="font-family:宋体;">浏览器的插件有,功能与</span><span style="font-family:Times New Roman;">selenium IDE</span><span style="font-family:宋体;">类似,如果你熟悉</span><span style="font-family:Times New Roman;">selenium IDE</span><span style="font-family:宋体;">的话,</span><span style="font-family:Times New Roman;">Tellurium IDE</span><span style="font-family:宋体;">就很容易操作。</span></span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;">Tellurium IDE <span style="font-family:宋体;">插件安装地址: </span></span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;"><a href="/misc/goto?guid=4959500806667485279">https://addons.mozilla.org/en-US/firefox/addon/tellurium-ide/?src=search</a></span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;">注意:本插件不支持最新的<span style="font-family:Times New Roman;">firefox 9 </span><span style="font-family:宋体;">,</span><span style="font-family:Times New Roman;">firefox</span><span style="font-family:宋体;">这小子一年换版本比翻书还快,本人使用的是</span><span style="font-family:Times New Roman;">firefox 3.6 </span><span style="font-family:宋体;">版本,用</span><span style="font-family:Times New Roman;">firefox</span><span style="font-family:宋体;">打开上面的链接后点击“</span><span style="font-family:Times New Roman;">add  to  firefox</span><span style="font-family:宋体;">”根据提示,浏览器开始下载安装重启。</span></span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;">在菜单栏<span style="font-family:Times New Roman;">---</span><span style="font-family:宋体;">工具</span><span style="font-family:Times New Roman;">----Tellurium IDE</span><span style="font-family:宋体;">打开插件。</span></span></p>    <p class="p0"> </p>    <p><img title="开源自动化测试框架 Tellurium " border="0" alt="开源自动化测试框架 Tellurium " src="https://simg.open-open.com/show/6bf3b12aadf3f71e3e9a3aad682d5e8b.png" width="700" height="525" /></p>    <p class="p0"> </p>    <p class="p0"> </p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;">我们打开人人网的注册页面,填写个人信息,<span style="font-family:Times New Roman;">Tellurium IDE</span><span style="font-family:宋体;">会自动记录我的操作。</span></span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;"><strong>Record </strong><span style="font-family:宋体;">:录制按钮。打开时默认是按下的,再次点击将取消录制状态。</span></span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;"><strong>Step </strong><span style="font-family:宋体;">:单步运行。点击一次,运行一步。</span></span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;"><strong>Run </strong><span style="font-family:宋体;">: 运行按钮。点击之后将会把脚本从头到尾运行一遍。</span></span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;"><strong>Clear </strong><span style="font-family:宋体;">: 清楚脚本。清楚录制的脚本。</span></span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;"> </span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;">本例子录制了一个人人网的注册页面(不完整,只是填写了注册信息,并被“提交”注册)。</span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;">我们切换到<span style="font-family:Times New Roman;">Source View</span><span style="font-family:宋体;">标签,可查看录制的代码。</span></span></p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;">点击菜单栏<span style="font-family:Times New Roman;">File </span><span style="font-family:宋体;">可选择将代码以不同的形式导出或保存到剪切版上。 </span></span></p>    <p class="p0"> </p>    <p><img style="width:754px;height:306px;" title="开源自动化测试框架 Tellurium " border="0" alt="开源自动化测试框架 Tellurium " src="https://simg.open-open.com/show/6045cf624cbc97d4b57b1639c19bff10.png" /></p>    <p> </p>    <p> </p>    <p><span style="font-size:18pt;">在Eclipse中运行测试代码</span></p>    <p class="p0"> </p>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;">我们在<span style="font-family:Times New Roman;">Eclipse</span><span style="font-family:宋体;">中创建一个</span>NewUiModule.groovy 的文件。并把我<span style="font-family:Times New Roman;">Tellurium IDE</span><span style="font-family:宋体;">中录制的代码插入,内容如下:</span></span></p>    <p class="p0"> </p>    <div class="cnblogs_code">     <pre><span style="color:#0000ff;">class</span> NewUiModule <span style="color:#0000ff;">extends</span> DslContext {       <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> defineUi() {             ui.Form(uid: "Regform", clocator: [tag: "form", action: "/s-c-i-reg.do", name: "regform", id: "regform", method: "post"]){             InputBox(uid: "RegEmail", clocator: [tag: "input", type: "text", <span style="color:#0000ff;">class</span>: "inputtext", id: "regEmail", name: "regEmail"])             InputBox(uid: "Pwd", clocator: [tag: "input", type: "password", <span style="color:#0000ff;">class</span>: "inputtext", id: "pwd", name: "pwd"])             InputBox(uid: "Name", clocator: [tag: "input", type: "text", <span style="color:#0000ff;">class</span>: "inputtext", id: "name", name: "name"])             RadioButton(uid: "Female", clocator: [tag: "input", type: "radio", value: "女生", id: "female", name: "gender"])             Selector(uid: "Birth_year", clocator: [tag: "select", name: "birth_year"])             Selector(uid: "Birth_month", clocator: [tag: "select", name: "birth_month"])             Selector(uid: "Birth_day", clocator: [tag: "select", name: "birth_day"])             Selector(uid: "Stage", clocator: [tag: "select", name: "stage", id: "stage"])             InputBox(uid: "Icode", clocator: [tag: "input", type: "text", <span style="color:#0000ff;">class</span>: "inputtext validate-code", id: "icode", name: "icode"])             Container(uid: "D_email", clocator: [tag: "dl", direct: "true", id: "d_email"]){             UrlLink(uid: "Xid_reg_handle", clocator: [tag: "a", text: "帐号", id: "xid_reg_handle"])             UrlLink(uid: "A", clocator: [tag: "a", text: "手机号"])         }         Container(uid: "Dl_gender", clocator: [tag: "dl", direct: "true", <span style="color:#0000ff;">class</span>: "dl_gender"]){             RadioButton(uid: "Male", clocator: [tag: "input", type: "radio", value: "男生", id: "male", name: "gender"])             }     }                  connectSeleniumServer()             connectUrl "http://reg.renren.com/xn6245.do?ss=10113&rt=27"             type "Regform.RegEmail", "dddd"             type "Regform.RegEmail", "chongshi"             type "Regform.Pwd", "123456"             type "Regform.Name", "小三"             click "Regform.Female"             selectByLabel "Regform.Birth_year", "80后"             selectByLabel "Regform.Birth_month", "7"             selectByLabel "Regform.Birth_day", "8"             selectByLabel "Regform.Birth_day", "7"             selectByLabel "Regform.Stage", "已经工作了"             type "Regform.Icode", "漂亮宝贝"          }  <span style="color:#008000;">//</span><span style="color:#008000;">Add your methods here  </span><span style="color:#008000;"> </span>    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> searchDownload(String keyword) {            keyType "TelluriumDownload.Input", keyword            click "TelluriumDownload.Search"            waitForPageToLoad 30000      }      <span style="color:#0000ff;">public</span> String[] getAllDownloadTypes() {            <span style="color:#0000ff;">return</span> getSelectOptions("TelluriumDownload.DownloadType")      }      <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> selectDownloadType(String type) {           selectByLabel "TelluriumDownload.DownloadType", type      } }</pre>    </div>    <p class="p0"> </p>    <p class="p0"><span style="font-size:16px;">编写一个测试类对上面的方法时行测试:</span></p>    <div class="cnblogs_code">     <pre><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> NewTestCase <span style="color:#0000ff;">extends</span> TelluriumJavaTestCase {         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> NewUiModule app;          @BeforeClass        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> initUi() {            app = <span style="color:#0000ff;">new</span> NewUiModule();             app.defineUi();     }         @Before       <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> setUpForTest() {            connectUrl("http://code.google.com/p/aost/downloads/list");      }         @Test       <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> testTelluriumProjectPage() {           String[] allTypes = app.getAllDownloadTypes();             assertNotNull(allTypes);              assertTrue(allTypes[1].contains("All Downloads"));          app.selectDownloadType(allTypes[1]);             app.searchDownload("TrUMP");       }  }</pre>    </div>    <p class="p0"> </p>    <div id="trans-result-content">     <p><span style="font-size:16px;">编译项目并运行新的测试用例.</span></p>     <p> </p>     <p><span style="font-size:14pt;">TestNG创建项目</span></p>    </div>    <p class="p0"><span style="font-size:16px;">如果我们想创建一个testNG的项目,可以使用maven通过下面的命令进行创建。</span></p>    <p class="p0"> </p>    <div id="trans-result-content">     <span style="color:#008080;"><strong><span class="pln">mvn archetype</span><span class="pun">:generate</span><span class="pun">-</span><span class="typ">DgroupId</span><span class="pun">=</span><span class="pln">example </span><span class="pun">-</span><span class="typ">DartifactId</span><span class="pun">=</span><span class="pln">demo </span><span class="pun">-</span><span class="typ">DarchetypeArtifactId</span><span class="pun">=</span><span class="pln">tellurium</span><span class="pun">-</span><span class="pln">testng</span><span class="pun">-</span><span class="pln">archetype </span><span class="pun">-</span><span class="typ">DarchetypeGroupId</span><span class="pun">=</span><span class="pln">tellurium </span><span class="pun">-</span><span class="typ">DarchetypeVersion</span><span class="pun">=</span><span class="lit">0.6</span><span class="pun">.</span><span class="lit">0</span></strong></span>    </div>    <p> </p>    <p><span style="font-size:16px;">相关资料阅读:</span></p>    <p><span style="font-size:16px;">网站:</span></p>    <p><span style="font-size:16px;"><a href="/misc/goto?guid=4959500806755158365">http://code.google.com/p/aost/</a></span></p>    <p> </p>    <p><a href="/misc/goto?guid=4959500806838403036" rel="nofollow"><span style="color:#000000;">一个简易</span></a>的文档:</p>    <p>http://aost.googlecode.com/files/Ten.Minutes.To.Tellurium.pdf</p>    <p> </p>    <p>一段教你如何使用的视频</p>    <p> </p>    <p><a href="/misc/goto?guid=4959500806929761525" rel="nofollow">http://aost.googlecode.com/files/TenMinutesToTellurium.ogg</a></p>    <p><br /> 来自:<a href="/misc/goto?guid=4959500807012284526" target="_blank">http://www.cnblogs.com/fnng/archive/2012/01/14/2322355.html</a></p>