qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          開源自動化測試框架Tellurium

            Tellurium是什么?
            Tellurium是一種自動化的web測試框架。雖然它是在selemium的階段上建立起來的,但兩者之間有許多概念上的差異,Tellurium的主要特點如下:
            · 不是單一的“記錄和播放”風格。
            · 基于UI模塊,也就是說,它側重于UI元素
            · 讓你有結構化的代碼執行用戶界面和測試代碼之間的解耦
            · 魯棒性的變化,Tellurium達到使用復合定位建立在運行時和組的定位器定位,刪除里面的UI模塊和外部UI元素的UI元素之間的依賴
            · 表達所使用Groovy動態語言特性和DSL
            · 可重復使用,用戶界面模塊可重復使用相同的應用程序和Tellurium部件,可用于不同的應用
            · 地址在網絡上的動態因素。UI模板使用數據網格和Tellurium UI對象的回應屬性可以處理JavaScript事件
            · 核心框架是在Groovy實現和測試,可以在Groovy中的JUnit,TestNG的,或純DSL腳本書面
            · 支持數據驅動測試
            · 提供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.· 插件下載地址:
            http://www.oschina.net/news/·9279/groovy-eclipse-25·
            當然,你也可以使用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=·0··3&rt=27"
          type "Regform.RegEmail", "dddd"
          type "Regform.RegEmail", "chongshi"
          type "Regform.Pwd", "·23456"
          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[·].contains("All Downloads"));
          app.selectDownloadType(allTypes[·]);
          app.searchDownload("TrUMP");
          }
          }
            編譯項目并運行新的測試用例.
            TestNG創建項目
            如果我們想創建一個testNG的項目,可以使用maven通過下面的命令進行創建。
            mvn archetype:generate-DgroupId=example -DartifactId=demo -DarchetypeArtifactId=tellurium-testng-archetype -DarchetypeGroupId=tellurium -DarchetypeVersion=0.6.0
            后記:
            偶然在infoq上看到了關于這個自動化測試框架的介紹,本人對于陌生的測試技術有莫大的熱情,于是,開始查找它的相關資料,發現關于這個框架的資料很少。中文的更是簡單的介紹。因為是中國人做的這個框架,在開源軟件方面,老外嘲笑中國技術員只知道索取,沒有開創精神。這使我更產生了好奇,于是花費了點時間對這個框架了解了一番。發現做的還是挺不錯的,如果熟悉selenium的話,學習這個框架應該不是很難。不過這個框架也使用了一些非主流的技術,如groovy語言,我之前就沒停過,可能我孤陋寡聞,由于網上關于groovy語言的資料不多。
            當然,這個框架還有很多不足,沒有見有公司用這個測試框架進行測試。雖然,它的提出的一些技術是比selenium優秀的。但還需項目來驗證。沒有自己的官方網站,目前只寄托在google code上面。極其缺乏中文資料。看到最新的版本和新聞也是去年的,貌似今年一年都沒什么動靜。希望別太監了。我寫這篇文檔也是希望更多的測試人員來關注這個自動化測試框架。
            作者花費那么多時間和精力來做這個自動化測試框架,不管他做的如何,是否能應用我們的項目中,給我們帶來利益,但他的精神是值得我們學習。

          posted on 2014-03-07 10:49 順其自然EVO 閱讀(350) 評論(0)  編輯  收藏 所屬分類: 測試學習專欄selenium and watir webdrivers 自動化測試學習

          <2014年3月>
          2324252627281
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 崇左市| 格尔木市| 桐庐县| 合水县| 黎城县| 凤庆县| 垫江县| 嫩江县| 新丰县| 蓬莱市| 札达县| 台东市| 拉孜县| 琼结县| 田林县| 赤壁市| 新密市| 花垣县| 肇州县| 和平区| 昭通市| 福清市| 克拉玛依市| 安徽省| 锡林郭勒盟| 久治县| 仁布县| 舒兰市| 大邑县| 社会| 民县| 山丹县| 奉新县| 石棉县| 阜城县| 运城市| 保德县| 肃宁县| 苏尼特右旗| 定结县| 龙里县|