- Timestamp:
- 09/07/08 15:07:28 (3 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/selenium_rc_spec/lib/spec/selenium_rc.rb
r11214 r18938 1 1 require 'spec/rails' 2 2 require 'selenium' 3 require 'yaml' 4 require 'erb' 3 5 4 6 module Spec 5 7 module SeleniumRc 8 CONFIG_PATH = RAILS_ROOT + '/config/selenium_rc.yml' 9 DEFAULT_CONFIG = { 10 :app => { 11 :host => 'localhost', 12 :binding => '127.0.0.1', 13 :port => 4545, 14 :environment => 'test', 15 }.freeze, 16 :seleniumrc => { 17 :host => 'localhost', 18 :port => 4444, 19 :browsers => %w[ *firefox ].freeze 20 }.freeze 21 }.freeze 22 23 CONFIG = Module.new.module_eval do 24 if File.exist?(CONFIG_PATH) 25 yaml = File.open(CONFIG_PATH) {|f| 26 ERB.new(f.read).result(binding) 27 } 28 user_config = YAML.load(yaml).symbolize_keys 29 DEFAULT_CONFIG.merge \ 30 :app => user_config[:app].symbolize_keys, 31 :seleniumrc => user_config[:seleniumrc].symbolize_keys 32 else 33 DEFAULT_CONFIG 34 end 35 end 36 6 37 module Example 7 38 class SeleniumRcExampleGroup < Spec::Rails::Example::RailsExampleGroup … … 19 50 def create_server 20 51 @server_pid = Process.fork do 21 exec File.join(RAILS_ROOT, *%w[ script server ]), *%w[-p 4545 -e test] 52 config = CONFIG[:app] 53 host, port, env = config[:binding], config[:port], config[:environment] 54 server = File.join(RAILS_ROOT, *%w[ script server ]) 55 exec server, *%W[-b #{host} -p #{port} -e #{env}] 22 56 end 23 57 catch(:server_connected) { … … 30 64 end 31 65 def create_proxy 32 @@selenium = Selenium::SeleniumDriver.new('localhost', 4444, "*firefox", 'http://localhost:4545') 66 rc_config = CONFIG[:seleniumrc] 67 host, port, browser = rc_config[:host], rc_config[:port], rc_config[:browsers].first 68 app_url = "http://#{CONFIG[:app][:host]}:#{CONFIG[:app][:port]}" 69 @@selenium = Selenium::SeleniumDriver.new(host, port, browser, app_url) 33 70 @@selenium.start 34 71 @@selenium.set_context("test_new") … … 44 81 private 45 82 def server_connectable? 46 TCPSocket.open('localhost', 4545) { 83 host = CONFIG[:app][:host] 84 TCPSocket.open(CONFIG[:app][:host], CONFIG[:app][:port]) { 47 85 return true 48 86 } … … 125 163 wait_for_page_to_load(timeout) 126 164 end 165 def clicks_and_waits(locator, timeout = 3000) 166 click(locator) 167 wait_for_page_to_load(timeout) 168 end 169 170 # by http://twitter.com/nazoking/statuses/83616812 171 def waits_for_ajax_loaded(timeout = 3000) 172 wait_for_condition(<<-JAVASCRIPT, timeout) 173 selenium.page().currentWindow.Ajax.activeRequestCount==0 174 JAVASCRIPT 175 end 127 176 end 128 177 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)