- 温柔一刀
- 等级:
- 性别:
- 文章: 801
- 积分: 1192
- 来自: 上海
|
ActiveRecord是rails的框架,我们在selenium测试中肯定需要初始化数据或者清理数据库数据以保证各个测试之间的独立性,可以这样用ActiveRecord来初始化或清理数据库
ruby 代码
- 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
- @selenium.is_text_present("用户登录")
- end
-
- def clear_database
- connection = ActiveRecord::Base.connection
- connection.execute("DELETE from channels")
- ......
- end
-
- end
其中
ruby 代码
- require 'active_record'
- ActiveRecord::Base.establish_connection(
- :adapter => "mysql",
- :host => "localhost",
- :username => "dcrm",
- :password => "dcrm",
- :database => "dcrm2_development"
- )
建立了DB Connection
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|
- carrierlanhai
- 等级: 初级会员
- 性别:
- 文章: 77
- 积分: 30
- 来自: 上海
|
怎么多没看到MM的
|
返回顶楼 |
|
|