开源自动化测试框架Tellurium

Tellurium是什么?

Tellurium是一种自动化的web测试框架。虽然它是在selemium的阶段上建立起来的,但两者之间有许多概念上的差异,Tellurium的主要特点如下:

 

 

  • l 不是单一的“记录和播放”风格。
  • l 基于UI模块,也就是说,它侧重于UI元素
  • l 让你有结构化的代码执行用户界面和测试代码之间的解耦
  • l 鲁棒性的变化,Tellurium达到使用复合定位建立在运行时和组的定位器定位,删除里面的UI模块和外部UI元素的UI元素之间的依赖
  • l 表达所使用Groovy动态语言特性和DSL
  • l 可重复使用,用户界面模块可重复使用相同的应用程序和Tellurium部件,可用于不同的应用
  • l 地址在网络上的动态因素。UI模板使用数据网格和Tellurium UI对象的回应属性可以处理JavaScript事件
  • l 核心框架是在Groovy实现和测试,可以在Groovy中的JUnit,TestNG的,或纯DSL脚本书面
  • l 支持数据驱动测试
  • l 提供Maven原型

 

如何使用Tellurium?

 

 

使用Maven创建一个新的Tellurium 测试项目

  首先,你需要安装maven ,确保本机有maven环境。关于maven环境的搭建,可以参考的我的博客,关于maven的文章:

http://www.cnblogs.com/fnng/category/345480.html

找到maven目录下的settings.xml 文件,我本机的路径在:F:\maven\apache-maven-3.0.3\conf\目录下。

打开文件,并在<profiles>....</profiles>之间添加如下信息:

 

<parofiles>
    <profile>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <repositories>
            <repository>
                <id>kungfuters-public-snapshots-repo</id>
                <name>Kungfuters.org Public Snapshot Repository</name>
                <releases>
                    <enabled>false</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <url>http://maven.kungfuters.org/content/repositories/snapshots</url>
            </repository>
            <repository>
                <id>kungfuters-public-releases-repo</id>
                <name>Kungfuters.org Public Releases Repository</name>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
                <url>http://maven.kungfuters.org/content/repositories/releases</url>
            </repository>
        </repositories>
    </profile>
<parofiles>

 

打开的你的命令提示符,切换到你的工作空间的目录下,运行下列Maven命令来创建一个新的Tellurium测试方案(项目)"demo"

mvn archetype:generate -DgroupId=example -DartifactId=demo -DarchetypeArtifactId=tellurium-junit-archetype -DarchetypeGroupId=tellurium -DarchetypeVersion=0.6.0

然后切换到该项目的目录下执行:mvn  eclipse:eclipse   构建成我们的eclipse所能识别的项目结构。

 

打开Eclipse将我们构建完成的项目导入。完成后项目结构如下:

 

在Telluriumconfig.groovy文件中包含Tellurium项目设置,你能根据你的需求对它进行自定义设置

 

tellurium{
    //embedded selenium server configuration
    embeddedserver {
        //port number
        port = "4444"
        //whether to use multiple windows
        useMultiWindows = false
        //whether to run the embedded selenium server. If false, you need to manually set up a selenium server
        runInternally = true
        //profile location
        profile = ""
        //user-extension.js file, for example, "target/test-classes/extension/user-extensions.js"
        userExtension = ""
    }
    //event handler
    eventhandler{
        //whether we should check if the UI element is presented
        checkElement = false
        //wether we add additional events like "mouse over"
        extraEvent = true
    }
    //data accessor
    accessor{
        //whether we should check if the UI element is presented
        checkElement = true
    }
    connector{
        //selenium server host
        //please change the host if you run the Selenium server remotely
        serverHost = "localhost"
        //server port number the client needs to connect
        port = "4444"
        //base URL
        baseUrl = "http://localhost:8080"
        //Browser setting, valid options are
        //  *firefox [absolute path]
        //  *iexplore [absolute path]
        //  *chrome
        //  *iehta
        browser = "*chrome"
        //user's class to hold custom selenium methods associated with user-extensions.js
        //should in full class name, for instance, "com.mycom.CustomSelenium"
        customClass = ""
    }
    datadriven{
        dataprovider{
            //specify which data reader you like the data provider to use
            //the valid options include "PipeFileReader", "CVSFileReader" at this point
            reader = "PipeFileReader"
        }
    }
    test{
    //at current stage, the result report is only for tellurium data driven testing
    //we may add the result report for regular tellurium test case
        result{
            //specify what result reporter used for the test result
            //valid options include "SimpleResultReporter", "XMLResultReporter", and "StreamXMLResultReporter"
            reporter = "XMLResultReporter"
            //the output of the result
            //valid options include "Console", "File" at this point
            //if the option is "File", you need to specify the file name, other wise it will use the default
            //file name "TestResults.output"
            output = "Console"
            //test result output file name
            filename = "TestResult.output"
        }
        exception{
            //whether Tellurium captures the screenshot when exception occurs.
            //Note that the exception is the one thrown by Selenium Server
            //we do not care the test logic errors here
            captureScreenshot = true
            //we may have a series of screenshots, specify the file name pattern here
            //Here the ? will be replaced by the timestamp and you might also want to put
            //file path in the file name pattern
            filenamePattern = "Screenshot?.png"
        }
    }
    uiobject{
        builder{
            //user can specify custom UI objects here by define the builder for each UI object
            //the custom UI object builder must extend UiObjectBuilder class
            //and implement the following method:
            //
            // public build(Map map, Closure c)
            //
            //For container type UI object, the builder is a bit more complicated, please
            //take the TableBuilder or ListBuilder as an example
            //example:
//        Icon="org.tellurium.builder.IconBuilder"
        }
    }
    widget{
        module{
            //define your widget modules here, for example Dojo or ExtJs //
            included="dojo, extjs"
            included=""
        }
    } 

}

 

  GoogleSearchModule.groovy是用户界面模块的谷歌搜索,它自化生成Tellurium 所需要的火狐浏览器插件TrUMP.  doGoogleSearch() 和 doImFeelingLucky() 两个方法是增加定期谷歌搜索和谷歌“手气不错”搜索。

 

public class GoogleSearchModule extends DslContext {
public void 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"])
    }
 }
 public void doGoogleSearch(String input) {
    keyType "Google.Input", input
    pause 500
    click "Google.Search"
    waitForPageToLoad 30000
 }
 public void doImFeelingLucky(String input) {
    type "Google.Input", input
    pause 500
    click "Google.ImFeelingLucky"
    waitForPageToLoad 30000
    }
 }

 

因为Tellurium只支持groovy语言,所以无groovy语言无法直接在Eclipse IDE中运行,需要Eclipse安装对groovy语言支持的插件。

 

Groovy-Eclipse 2.5.1 插件下载地址:

 

http://www.oschina.net/news/19279/groovy-eclipse-251 

 

当然,你也可以使用IntelliJ IDEA 工具,它同样也运行java语言非常优秀的IDE。 而且IntelliJ IDEA本身是支持groovy语言。

 

 

 

Tellurium IDE 插件

 

 

这个同样也是基于firefox浏览器的插件有,功能与selenium IDE类似,如果你熟悉selenium IDE的话,Tellurium IDE就很容易操作。

 

Tellurium IDE 插件安装地址: 

 

https://addons.mozilla.org/en-US/firefox/addon/tellurium-ide/?src=search

 

注意:本插件不支持最新的firefox 9 ,firefox这小子一年换版本比翻书还快,本人使用的是firefox 3.6 版本,用firefox打开上面的链接后点击“add  to  firefox”根据提示,浏览器开始下载安装重启。

 

在菜单栏---工具----Tellurium IDE打开插件。

 

 

 

 

我们打开人人网的注册页面,填写个人信息,Tellurium IDE会自动记录我的操作。

 

Record :录制按钮。打开时默认是按下的,再次点击将取消录制状态。

 

Step :单步运行。点击一次,运行一步。

 

Run : 运行按钮。点击之后将会把脚本从头到尾运行一遍。

 

Clear : 清楚脚本。清楚录制的脚本。

 

 

 

本例子录制了一个人人网的注册页面(不完整,只是填写了注册信息,并被“提交”注册)。

 

我们切换到Source View标签,可查看录制的代码。

 

点击菜单栏File 可选择将代码以不同的形式导出或保存到剪切版上。 

 

 

 

在Eclipse中运行测试代码

 

 

我们在Eclipse中创建一个NewUiModule.groovy 的文件。并把我Tellurium IDE中录制的代码插入,内容如下:

 

class NewUiModule extends DslContext {
    public void 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", class: "inputtext", id: "regEmail", name: "regEmail"])
            InputBox(uid: "Pwd", clocator: [tag: "input", type: "password", class: "inputtext", id: "pwd", name: "pwd"])
            InputBox(uid: "Name", clocator: [tag: "input", type: "text", class: "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", class: "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", class: "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", "漂亮宝贝"

    }  //Add your methods here
    public void searchDownload(String keyword) {
        keyType "TelluriumDownload.Input", keyword
        click "TelluriumDownload.Search"
        waitForPageToLoad 30000
    }
    public String[] getAllDownloadTypes() {
        return getSelectOptions("TelluriumDownload.DownloadType")
    }
    public void selectDownloadType(String type) {
        selectByLabel "TelluriumDownload.DownloadType", type
    }
}

编写一个测试类对上面的方法时行测试:

public class NewTestCase extends TelluriumJavaTestCase {
    private static NewUiModule app;
    @BeforeClass
    public static void initUi() {
        app = new NewUiModule();
        app.defineUi();     }
    @Before
    public void setUpForTest() {
        connectUrl("http://code.google.com/p/aost/downloads/list");
    }
    @Test
    public void testTelluriumProjectPage() {
        String[] allTypes = app.getAllDownloadTypes();
        assertNotNull(allTypes);
        assertTrue(allTypes[1].contains("All Downloads"));
        app.selectDownloadType(allTypes[1]);
        app.searchDownload("TrUMP");
    }
 }

 

编译项目并运行新的测试用例.

 

TestNG创建项目

如果我们想创建一个testNG的项目,可以使用maven通过下面的命令进行创建。

 

mvn archetype:generate-DgroupId=example -DartifactId=demo -DarchetypeArtifactId=tellurium-testng-archetype -DarchetypeGroupId=tellurium -DarchetypeVersion=0.6.0

 

相关资料阅读:

网站:

http://code.google.com/p/aost/

 

一个简易的文档:

http://aost.googlecode.com/files/Ten.Minutes.To.Tellurium.pdf

 

一段教你如何使用的视频

 

http://aost.googlecode.com/files/TenMinutesToTellurium.ogg

 

 

 

 

后记:

 

  偶然在infoq上看到了关于这个自动化测试框架的介
绍,本人对于陌生的测试技术有莫大的热情,于是,开始查找它的相关资料,发现关于这个框架的资料很少。中文的更是简单的介绍。因为是中国人做的这个框架,
在开源软件方面,老外嘲笑中国技术员只知道索取,没有开创精神。这使我更产生了好奇,于是花费了点时间对这个框架了解了一番。发现做的还是挺不错的,如果
熟悉selenium的话,学习这个框架应该不是很难。不过这个框架也使用了一些非主流的技术,如groovy语言,我之前就没停过,可能我孤陋寡闻,由
于网上关于groovy语言的资料不多。

     当然,这个框架还有很多不足,没有见有公司用这
个测试框架进行测试。虽然,它的提出的一些技术是比selenium优秀的。但还需项目来验证。没有自己的官方网站,目前只寄托在google
code上面。极其缺乏中文资料。看到最新的版本和新闻也是去年的,貌似今年一年都没什么动静。希望别太监了。我写这篇文档也是希望更多的测试人员来关注
这个自动化测试框架。

 

  作者花费那么多时间和精力来做这个自动化测试框架,不管他做的如何,是否能应用我们的项目中,给我们带来利益,但他的精神是值得我们学习。

时间: 2024-07-29 04:35:26

开源自动化测试框架Tellurium的相关文章

从0到1开发自动化测试框架

一.序言 随着项目版本的快速迭代.APP测试有以下几个特点: 首先,功能点多且细,测试工作量大,容易遗漏: 其次,代码模块常改动,回归测试很频繁,测试重复低效: 最后,数据环境多样,用户场景复杂,功能回归覆盖难全面. 为节省成本,保证高效及高质量迭代,我们需采用更高效的测试方式,App自动化测试是较高效的手段. 之前自动测试实践过程中遇到的诸多问题(代码复用率低,Case开发及数据构造繁琐,问题定位困难,学习成本高等),为解决相关痛点问题,我们重新实现了一套APP自动测试框架.本文将着重介绍技术

Tellurium自动化测试框架介绍

Tellurium自动化测试框架是由方剑在2007年6月创建的用于测试Web应用的框架,并在2008年6月移步到Google Code成为一个开源项目.它会定期发布版本,当前版本号是0.7.0.项目的核心已经历时两年,并繁衍出了多个子项目,包括:UDL.Core.Engine.Widget扩展. Maven Archetype.Trump.Tellurium IDE.TelluriumWorks以及参考项目. 这个框架是从Selenium框架发展而来,但又具有不同的测试理念.大多数Web测试框架

越来越强大的SAFS/STAF/STAX自动化测试框架

上一次,向大家介绍了Openqa.org社区提供的.适合web应用的.开源的自动化测试框架 (开源测试工 具/社区(Selenium /OpenQA.org)--今非昔比 ).最近,看到STAF+STAX发布了最新版本,包括许多服务 组件,可以看出STAF+STAX的框架越来越完整,值得向大家推荐. September 24, 2008: STAF 3.3.1, STAX 3.3.4, Cron 3.3.3, Email 3.3.2, Event 3.1.2, EventManager 3.3.

开发基于XML的Selenium自动化测试框架

为解决该群体的困扰,本文将介绍如何让不熟悉编程的业务http://www.aliyun.com/zixun/aggregation/9621.html">测试人员也能编写出类似传统功能测试用例的自动化测试用例,从而扫除自动化测试的技术障碍. 本文适用于需要为测试团队开发自动化回归测试框架的测试设计开发人员.目前业内主流的商业自动化测试工具和开放源代码测试工具,都需要测试人员熟悉开发编程语言.但是过高的编程门槛让很多测试人员只能对自动化测试驻足遥望.为解决该群体的困扰,本文将介绍一种基于 X

《精通自动化测试框架设计》目录—导读

作者简介 精通自动化测试框架设计 陈冬严,浙江大学硕士,具有10年软件测试和团队管理的工作经验,先后服务于ITSM.PLM软件研发企业,现就职于某金融行业核心机构IT规划部门.业余时间喜欢园艺. 邵杰明,热爱测试工作,10多年的测试行业经验,曾先后供职于多家世界一流软件公司担任测试开发和测试管理工作,积累了丰富的行业工作经验,拥有PMP认证,目前担任测试架构师的工作,致力于自动化测试设计.持续交付等方面的工作. 王东刚,常用网名fastpoint,资深测试专家,<软件测试与Junit实践>作者

自动化测试框架PhoenixAutotest入门

介绍 这里介绍一个基于Selenium实现的一个web自动化测试框架,本框架主要是通过对Selenium的封装实现降低学习自动化测试框架的难度.  如果,您还对Selenium不了解的话,可以先参考<Selenium学习建议>. 入门知识 Java基础 环境 jdk1.8.Eclipse.Maven 入门 可以根据您的习惯来新建Java工程或者Maven工程.如果是Maven工程的话,请添加如下依赖: <dependencies> <dependency> <gr

WebUI 自动化测试框架 PhoenixAutotest 发布 20170610

介绍 WebUI自动化测试框架phoenix.webui.framework发布20170610版本. 本次发布修正了一些bug,更多Isseus信息请访问Github.添加的主要功能如下: 增加了通过注解的方式来配置PageObject(页面对象),单元测试代码如下(本文所有的代码都可以在Github项目中获取): /* * Copyright 2002-2007 the original author or authors. Licensed under the Apache License

腾讯Android自动化测试实战1.1 Android自动化测试框架概述

1.1 Android自动化测试框架概述 2007年Android开源时,Monkey.Instrumentation和MonkeyRunner这3个测试框架,是跟Android源码一起发布的,这也是最早可用的自动化测试框架,那几年大家基本都是用这些框架来开展自动化相关测试工作的.2010年,第一个第三方的测试工具Robotium(基于Instrumentation)发布了,不少测试人员就转用这个框架,Robotium社区逐步发展起来.图1-1所示为Robotium热度随时间变化的趋势. 201

自动化测试框架Selenium 入门

1.什么是selenium selenium是ThoughtWork的一款开源测试框架. 下载selenium2.0lib包,点击http://code.google.com/p/selenium/downloads/list 这是官方文档:http://seleniumhq.org/docs/ 2.为什么选择selenium 自动化测试工具有很多了,QTP作为商业软件功能强大.但是要把QTP整合到已有的测试平台上面非常困难,selenium非常容易的可以整合到已有的测试平台上面去.如果你是一个