e代劍客——溫柔一刀

          生活就像海洋,只有意志堅強的人,才能到達彼岸

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            76 隨筆 :: 7 文章 :: 215 評論 :: 0 Trackbacks
          ActiveRecord是rails的框架,我們在selenium測試中肯定需要初始化數據或者清理數據庫數據以保證各個測試之間的獨立性,可以這樣用ActiveRecord來初始化或清理數據庫

          ????require?'test/unit'??
          ????require?'selenium'??
          ????require?'active_record'??
          ????ActiveRecord::Base.establish_connection(????
          ??????:adapter?
          =>?"mysql",????
          ??????:host?
          =>?"localhost",????
          ??????:username?
          =>?"dcrm",????
          ??????:password?
          =>?"dcrm",????
          ??????:database?
          =>?"dcrm2_test"????
          ???)????
          ?????
          ???class?FunctionalTestCase?
          <?Test::Unit::TestCase??
          ???????
          ?????@wait_default_time
          ="30000"??
          ?????
          ?????def?setup??
          ???????initBrowser?unless?@selenium??
          ?????end??
          ????????
          ?????def?teardown??
          ???????logout??
          ???????clear_database??
          ???????closeBrowser??
          ?????end??????
          ???????
          ?????def?logout??
          ???????@selenium.open?
          "http://localhost:3000/logout"??????
          ???????wait_default??
          ?????end??
          ???????
          ?????def?closeBrowser()??
          ???????@selenium.stop??
          ?????end??
          ???????
          ?????def?initBrowser??
          ???????@selenium?
          =?Selenium::SeleniumDriver.new("localhost",?4444,?"*iexplore",?"http://localhost:4444",?10000);??
          ???????@selenium.start??
          ?????end??
          ???????
          ?????def?wait_default??
          ???????@selenium.wait_for_page_to_load?@wait_default_time??
          ?????end??
          ???????
          ?????def?test_logout??????
          ???????logout??????
          ???????assert?@selenium.is_text_present(
          "用戶登錄")??
          ?????end??
          ???????
          ?????def?clear_database??
          ???????connection?
          =?ActiveRecord::Base.connection??
          ???????connection.execute(
          "DELETE?from?channels")???
          ?????????
          ?????end????
          ??????
          ???end??

          ?其中
          require?'active_record'?
          ActiveRecord::Base.establish_connection(??
          ??:adapter?
          =>?"mysql",????
          ??:host?
          =>?"localhost",????
          ??:username?
          =>?"dcrm",????
          ??:password?
          =>?"dcrm",????
          ??:database?
          =>?"dcrm2_development"????
          )???

          建立了DB Connection
          posted on 2007-12-30 17:24 溫柔一刀 閱讀(443) 評論(0)  編輯  收藏 所屬分類: ROR

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          聯系偶 zhupanjava@gmail.com 溫柔一刀
          主站蜘蛛池模板: 汾西县| 巴林左旗| 罗源县| 曲靖市| 调兵山市| 仁寿县| 清水县| 洛扎县| 六枝特区| 延安市| 呈贡县| 清丰县| 敦化市| 太湖县| 上蔡县| 汪清县| 金沙县| 保康县| 枣强县| 子长县| 浮梁县| 布尔津县| 中山市| 曲阳县| 毕节市| 大兴区| 屏南县| 丹棱县| 扎鲁特旗| 姜堰市| 大冶市| 万山特区| 青海省| 凤山市| 长乐市| 如皋市| 枣强县| 陵水| 麻江县| 堆龙德庆县| 元朗区|