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 温柔一刀 阅读(424) 评论(0)  编辑  收藏 所属分类: ROR

只有注册用户登录后才能发表评论。


网站导航:
 
联系偶 zhupanjava@gmail.com 温柔一刀