<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    qileilove

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

    前端自動化測試工具doh學習總結(一)

     前言
      項目中需要用到前端自動化測試,自己被當作一個探針研究了下目前用的比較多的web自動化測試工具。一開始研究的是的selenium,但由于項目使用了大量的dijit控件,寫起testCase來很費勁;最主要的是selenium有嚴重的瀏覽器兼容性問題,于是徹底放棄,改投doh門下,畢竟是dojo他爸爸開發的跟dojo繼承起來非常方便。這幾篇主要介紹doh、doh/Robot以及將doh與selenium結合進而與CI工具集成起來。
      一、DOH 是什么
      DOH 是 Dojo Objective Harness 的簡稱,是 Dojo 在 0.9 版本之后新增的單元測試工具。隨著 Javascript 代碼的數量和復雜度的增加,Web 前端開發者也需要一個 Javascript 代碼的單元測試框架來保證自己寫出來的 Javascript 代碼是健壯的。所以,DOH 是 Web 前端開發者對 JUnit 的回應。DOH有如下特點:
      提供用戶界面:JUnit中的紅條測試失敗、綠條測試通過,大家都已經很熟悉了,DOH也有類似的用戶界面,用戶在測試時更加一目了然;
      平臺無關:DOH并不依賴某種瀏覽器平臺,甚至不依賴于瀏覽器;用戶可以根據自己的需要在命令行進行Javascript的自動化單元測試;
      支持Ajax:Ajax編程在Web前端開發中是必不可少的一環,DOH最有價值的一個特性就是支持Ajax的測試;
      不只適合與于Dojo,可用于任何JavaScript程序的單元測試。
      下載dojo源碼包,解壓后可以看到以下目錄:
      二、DOH第一次親密接觸
      部署到服務器后,我們訪問runner.html
      與JUnit類似,DOH也為我們提供了一個類似的界面,左側表示運行的測試案例,右側是測試日志,最上方的進度條表示的是本次運行中的已執行案例,同樣綠色表示成功,紅色表示失敗。默認情況下會加載“dojo/tests/module.js”文件,該文件的作用就是像runner.html中加載dojo所有核心模塊的測試案例。
      如果想要單獨加載某一模塊的測試案例,需要用到test參數指向該模塊:
      http://<server>/util/doh/runner.html?test=dojo/tests/fx
    我們可以吧測試案例放到自己的項目目錄下,通過test參數指向自定義測試模塊,這時需要用到paths參數:
      util/doh/runner.html?paths=org/myorg,../../../mycode/org/myorg&test=org/myorg/mymodule/tests/alltests
      paths參數中逗號前后的值相當于dojoConfig定義packages對象時的name和location
      同樣在path中我們可以定義多個模塊, 模塊之間用“;”分隔開來
      util/doh/runner.html?paths=org/myorg,../../../mycode/org/myorg;com/mycom,../../../x/com/mycom&test=com/mycom/tests
      doh中測試模塊要么是一個用來請求多個測試文件的文件,要么是一個使用doh.register方法注冊時測試案例,或者兩者皆有。
      define([
      "my/test/widget/Foo0",
      "my/test/widget/Foo1",
      "my/test/widget/Foo2"
      ]);
    doh.register(...)
    An almost 'magical' function. The doh.register() method accepts the function signatures of any of the other registration functions and determines the correct underlying function (listed below) to dispatch registration to. It's the function you'll most commonly use for registering Unit Tests.
    doh.registerTest(group, testFuncOrObj)
    This function registers a test as a member of the group 'group', and the test can either be a simple function definition or a 'Test Fixture', which is an object that defines the run requirements of the test.
    doh.registerTests(group, testFuncOrObjArr)
    This function registers an array of tests as a member of the group 'group'. The contents of the array of tests can be an array of simple test functions or an array of 'test fixtures', or a mix of them.
    doh.registerTestNs(group, obj)
    This function registers an object comprised of functions as a member of the group 'group'. Note that this function will only add in non-private (functions without an _ at the beginning of the name), as a test function. If you'd like to use fixtures (setUp(), tearDown(), and runTest()), please use doh.register(), doh.registerTest() or doh.registerTests().
    doh.registerTestUrl(url)
    This function registers a URL as a location to load tests from. The URL is used to populate the contents of an iframe, and usually refers to an HTML page that boot-loads D.O.H. internally for running tests in a segmented iframe. A good example showing this is the dojo/tests/fx.html. It loads dojo, doh, and then on dojo load completion calls doh.registerTests(). The D.O.H. instance in the iframe will proxy back the results of the test run to the primary D.O.H. instance.
      上面提到的dojo/test/fx模塊中我們可以看到該文件中主要定義了兩個TestSuite:
      define(["doh/main", "require"], function(doh, require){
      if(doh.isBrowser){
      doh.register("tests.fx", require.toUrl("./fx.html"), 30000);
      doh.register("tests.NodeList-fx", require.toUrl("./NodeList-fx.html"), 30000);
      }
      });
      對應于runner.html中
      打開該目錄下的fx.html文件,我們可以看到該文件中定義了一系列TestCase
      doh中有兩種測試結構:
      1、Simple Tests  將一個單獨的函數放到doh.register參數testCase數組里
      同步形式:
      function mySimpleTest(doh){
      doh.assertTrue(true);
      }
      異步形式:
    function mySimpleAsyncTest(doh){
    var deferred = new doh.Deferred();
    setTimeout(deferred.getTestCallback(function(){
    doh.assertTrue(true);
    }), 100);
    return deferred;
    }
      2、Test Fixture
      同步形式:
    {
    name: "thingerTest",
    setUp: function(){
    // Setup to do before runTest.//類似于JUnit中的@beforeTest
    this.thingerToTest = new Thinger();
    this.thingerToTest.doStuffToInit();
    },
    runTest: function(){
    // Our test function to run.//類似于JUnit中的@Test
    doh.assertEqual("blah", this.thingerToTest.blahProp);
    doh.assertFalse(this.thingerToTest.falseProp);
    // ...
    },
    tearDown: function(){
    // cleanup to do after runTest.//類似于JUnit中的@afterTest
    },
    timeout: 3000 // 3 second timeout.//測試運行時間,超過改時間會報錯
    }
      異步形式:
    {
    name: "thingerTest",
    setUp: function(){
    // Setup to do before runTest.
    this.thingerToTest = new Thinger();
    this.thingerToTest.doStuffToInit();
    },
    runTest: function(){
    // Our test function to run.
    var deferred = new doh.Deferred();
    setTimeout(deferred.getTestCallback(function(){
    doh.assertEqual("blah", this.thingerToTest.blahProp);
    doh.assertFalse(this.thingerToTest.falseProp);
    }), 100);
    return deferred;
    },
    tearDown: function(){
    // cleanup to do after runTest.
    },
    timeout: 3000 // 3 second timeout.
    }

    posted on 2014-05-29 11:42 順其自然EVO 閱讀(621) 評論(0)  編輯  收藏 所屬分類: web 前端性能測試

    <2014年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    常用鏈接

    留言簿(55)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 91免费福利视频| 亚洲国产成人综合精品| 色在线亚洲视频www| 久久久精品免费国产四虎| 免费在线观看中文字幕| 亚洲国产区男人本色| 91视频国产免费| 涩涩色中文综合亚洲| 无码国产精品一区二区免费| 国产亚洲日韩在线三区| 一级做a爰片久久免费| 亚洲无码日韩精品第一页| 黄页网址大全免费观看12网站| 国内精品乱码卡1卡2卡3免费| 亚洲欧洲国产成人精品| 18未年禁止免费观看| 亚洲福利视频网址| 免费看的成人yellow视频| 欧洲亚洲国产精华液| 国产高清在线免费视频| 成人亚洲国产精品久久| 亚洲精品久久久www| 久久国产美女免费观看精品| 亚洲高清无码专区视频| jizz在线免费播放| 亚洲一级二级三级不卡| 最近2019免费中文字幕6| 亚洲国产超清无码专区| 毛片免费观看网址| 中文字幕成人免费高清在线 | 中文字幕亚洲一区二区va在线| 日韩在线视频播放免费视频完整版| 亚洲AV无码成H人在线观看| 精品国产福利尤物免费| 亚洲伦理一区二区| 免费毛片在线播放| 成人电影在线免费观看| 亚洲福利一区二区精品秒拍| 又粗又大又黑又长的免费视频| 亚洲最大中文字幕无码网站| 人人揉揉香蕉大免费不卡|