51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2416|回复: 0
打印 上一主题 下一主题

[原创] Ten Minutes To Tellurium

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2009-3-15 12:11:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Wiki page version at

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

Introduction

Tellurium is an automated web testing framework. Although it is built on top of Selenium at the current stage, there are many conceptual differences between the two. The main features of Tellurium are list as follows:

    * Not a "record and replay" style
    * UI module-based, i.e., it focuses more on a set of UI elements
    * Enforce the decoupling between UI and testing code so that you have structured code
    * Robust to change, Tellurium achieves this by using composite locator to build locator at runtime and group locating to remove the dependency among UI elements inside the UI module and external UI elements
    * Expressive by using Groovy dynamic language feature and DSL
    * Reusable, UI modules are reusable for the same application and Tellurium widgets can be used for different applications
    * Address dynamic factors on the web. UI templates are used for data grid and the respond attribute in Tellurium UI object can address Javascript events
    * Core framework is implemented in Groovy and tests can be written in Groovy, JUnit, TestNG, or pure dsl scripts
    * Support data driven testing
    * Provide Maven archetypes

This tutorial tries to achieve the following goals,

    * Walk you through the steps for creating Tellurium test cases
    * Illustrate how to use Tellurium Firefox Plugin (TrUMP) to create your own UI modules
    * How to create your own Tellurium test cases and run the tests
    * Experience the features in Tellurium

Create a New Tellurium Test Project using Maven

First, you need to have Maven 2.0.9 installed and make sure you have M2_HOME environment set in your system.

Then, add Tellurium Maven repository into your Maven settings.xml, usually it is at Your_HOME/.m2/. Cut and post the following profile between the

<settings>

and

</settings>

tags in your settings.xml

   <profiles>
        <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://kungfuters.org/nexus/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://kungfuters.org/nexus/content/repositories/releases</url>
                </repository>   
            </repositories>
        </profile>
</profiles>

Go to your work space and run the following Maven command to create a new Tellurium test project called "demo":

mvn archetype:create -DgroupId=example -DartifactId=demo -DarchetypeArtifactId=tellurium-junit-archetype -DarchetypeGroupId=tellurium -DarchetypeVersion=1.0-SNAPSHOT

Once the demo project is created you can load it up using your favourite IDE. For example, in IntelliJ IDEA, you should do the following steps

New Project > Import project from external model > Maven > Project directory > Finish

Since it is a Maven project, the IDE will automatically try to solve the project dependency for you and download appropriate jars. Then, click on module settings to make sure the Groovy version is 1.6.0.

After that, you are read to run the sampel test file GoogleSearchTestCase.
Create Your own UI modules and Test Cases

Tellurium provides TrUMP for you to automatically create UI modules. TrUMP can be download from Tellurium project site

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

Choose the Firefox 2 or Firefox 3 version depending on your Firefox version. Or you can download the Firefox 3 version directly from Firefox addons site at

https://addons.mozilla.org/en-US/firefox/addon/11035

Once you install it and restart Firefox, you are ready to record your UI modules by simply clicking on the UI element on the web and then click the "generate" button. You may like to customize your UI a bit by clicking the "Customize" button. More detailed TrUMP introductions can be found at

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

and

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

In our example, we open up Tellurium download page

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

and record the download search module. After we customize the UI module, we export it as the module file NewUiModule.groovy to the demo project and add couple methods to the class.

class NewUiModule extends DslContext {

  public void defineUi() {
    ui.Form(uid: "TelluriumDownload", clocator: [tag: "form", method: "get", action: "list"], group: "true") {
      Selector(uid: "DownloadType", clocator: [tag: "select", name: "can", id: "can"])
      InputBox(uid: "Input", clocator: [tag: "input", type: "text", name: "q", id: "q"])
      SubmitButton(uid: "Search", clocator: [tag: "input", type: "submit", value: "Search"])
    }
  }

  //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
  }
}

Then, create a new Tellurium test case NewTestCase by extending TelluriumJavaTestCase class.

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");
    }
}

Compile the project and run the new test case.
Tellurium TestNG Project

If you want to create a new Tellurium TestNG project, simply use a different Maven archetype as follows,

mvn archetype:create -DgroupId=example -DartifactId=demo -DarchetypeArtifactId=tellurium-testng-archetype -DarchetypeGroupId=tellurium -DarchetypeVersion=1.0-SNAPSHOT

and the new Tellurium test case should extend TelluriumTestNGTestCase class. The rest are the same as the JUnit ones.

Resources

The slides for this tutorial is available at

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

The Screencast video is available at

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

The online version is at

http://www.youtube.com/watch?v=DyUPeg-Y-Yg
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-16 17:14 , Processed in 0.064678 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表