• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

十分钟入门 Tellurium (英文版)

发布: 2009-6-16 13:08 | 作者: 网络转载 | 来源: 领测软件测试网采编 | 查看: 77次 | 进入软件测试论坛讨论

领测软件测试网

Ten Minutes To Tellurium

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:

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

Go the demo project directory and you will find the following files

where the TelluriumConfig.groovy includes Tellurium project settings and you can customize them to you need

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
   
}
   
//the configuration for the connector that connects the selenium client to the selenium server
    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
=""
       
}
   
}
}

The GoogleSearchModule is the UI module for Google search and it is automatically generated by Tellurium Firefox Plugin (TrUMP). The two test methods doGoogleSearch and doImFeelingLucky are added for regular Goolge search and Google search for "I'm Feeling Lucky".

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

The GoogleSearchTestCase is a Tellurium JUnit test case by extending the class TelluriumJavaTestCase.

public class GoogleSearchTestCase extends TelluriumJavaTestCase {
   
private static GoogleSearchModule gsm;

   
@BeforeClass
   
public static void initUi() {
        gsm
= new GoogleSearchModule();
        gsm
.defineUi();
   
}

   
@Before
   
public void connectToGoogle() {
        connectUrl
("http://www.google.com");
   
}

   
@Test
   
public void testGoogleSearch() {
        gsm
.doGoogleSearch("tellurium Groovy Test");
   
}

   
@Test
   
public void testGoogleSearchFeelingLucky() {
        gsm
.doImFeelingLucky("tellurium automated Testing");
   
}
}

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 as shown in the following picture

After that, you are read to run the sampel test file GoogleSearchTestCase.

If you want to run the sample tests in command line, you can use the following command

mvn test

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/

TAG: Tellurium 入门 英文版

21/212>

关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网