教你初识Tellurium自动测试框架

发表于:2009-05-30来源:作者:点击数: 标签:框架Tellurium自动初识
Tellurium Automated Testing Framework(Tellurium自动 测试 框架)是一个新的 开源 项目。已经有一些用户, 主要来自美国和印度, 国内的还是比较少。 希望这里把Tellurium介绍给国内的同行,请多多使用,多多交流。 目前,Tellurium还是建立在 Selenium 框
Tellurium Automated Testing Framework(Tellurium自动测试框架)是一个新的开源项目。已经有一些用户, 主要来自美国和印度, 国内的还是比较少。 希望这里把Tellurium介绍给国内的同行,请多多使用,多多交流。

  目前,Tellurium还是建立在Selenium框架之上, 在不久的将来希望Tellurium会开发自己的测试驱动Engine来更好,更有效地支持Tellurium.

  尽管Tellurium脱胎于Selenium, 但两者在概念上是大大的不同。 打个比方,Selenium是C, 而Tellurium是C++。

  首先, Selenium主要用于记录和重播模式(Record and replay), 这是很方便,但是在比较复杂的应用中这种模式并不能很好地工作, 因为你必须记录可能的所以的测试情况, 除此之外, Data dependency(数据的依赖性)也是个大问题。

  第二, Selenium将测试的页面表述(Locator)和测试代码混在一起, 很难维护和重复使用(reuse)。

  第三, Selenium面对的是一个个单独的网页元素, 而且网页元素的Locator很难作到鲁棒性(robust)。

  那么Tellurium是如何克服上面的问题的呢?

  第一, Tellurium不是记录和重播模式, 而是注重网页模块的。 首先你必须定义网页模块和对模块的方法。 以Google页面为例, Google搜索模块可以定义为:

  ui.Container(uid: "Google", clocator: [tag: "td"], group: "true"){

  InputBox(uid: "SearchBox", clocator: [title: "Google Search"])

  SubmitButton(uid: "Search", clocator: [name: "btnG", value: "Google Search"])

  SubmitButton(uid: "Feelinglucky", clocator: [value: "I'm Feeling Lucky"])

  }

  然后, 你可以定义一些对它的操作方法,

  def doGoogleSearch(String input){

  type "Google.SearchBox", input

  pause 500

  click "Google.Search"

  waitForPageToLoad 30000

  }

  def doImFeelingLucky(String input){

  type "Google.SearchBox", input

  pause 500

  click "Google.FeelingLucky"

  waitForPageToLoad 30000

  }

  在此之上你可以像写JUnit测试一样的写测试代码, 例如:

  public class GoogleStartPageJavaTestCase extends TelluriumJavaTestCase {

  protected static NewGoogleStartPage ngsp;

  @BeforeClass

  public static void initUi() {

  ngsp = new NewGoogleStartPage();

  ngsp.defineUi();

  }

  @Test

  public void testGoogleSearch(){

  connectUrl("http://www.google.com");

  ngsp.doGoogleSearch("tellurium selenium Groovy Test");

  }

  @Test

  public void testGoogleSearchFeelingLucky(){

  connectUrl("http://www.google.com");

  ngsp.doImFeelingLucky("tellurium selenium DSL Testing");

  }

  }

  其次, 因为Tellurium是面向网页模块的, 而不是单独的元素, 所以它可以应用团体信息来给元素定位(Group Locating)。 比如, 在上面例子中, 元素"Google"可以用它包含的InputBox和SubmitButton中的信息来给

  它自己定位。这样使得这个网页模块只利用本身的信息, 而不依赖外部的信息。

  另一个Tellurium显著的特点是它用Composite Locator,就是上面定义的clocator。 clocator很贴近网页语言

  的定义, 而且它的Runtime(运行时)的locator是由Tellurium动态产生的, 比如,你改变了InputBox的title 属性, 你不需要再修改其他的地方。 这一点和上面的Group Locating使得Tellurium具有很好的鲁棒性, 可以自

  动适应网页模块外和模块内的变化。

  Tellrium核心是用Groovy语言写的, 这样你可一用DSL来写测试代码。 Tellurium的特点包括:

  1)支持JUnit和TestNG

  2)测试代码可以用Java, Groovy或DSL来写

  3)支持Data Driven Testing (数据驱动测试)

  4)支持Ant和Maven

  Tellurium由下面的子项目构成:

  1)Tellurium Core: 核心

  2)Tellurium Reference Projects: 有TestNG和JUnit项目教用户如何用Tellurium

  3)Tellurium UI Module Firefox Plugin (TrUMP), 它是一个Firefox的扩展,用户可以用它来自动生成网页模块。

  4)Tellurium Widget Extension: 有Dojo和ExtJS的Widget模块代码, 这样你只要在你的项目中加入一些jar文件,你就可以之间定义和测试这些Widget了。

  5)Tellurium Engine: 将来的测试驱动模块。

原文转自:http://www.ltesting.net