watir-webdriver-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+
2
+ /.loadpath
3
+ /.project
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "watir-webdriver", ">= 0.3.5", :platform => :ruby_19
4
+
5
+ # Specify your gem's dependencies in watir-webdriver-rails.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ watir-webdriver-rails
2
+ ===============
3
+
4
+ watir-webdriver-rails provides a dead-simple integration test of Watir with Rails 3.
5
+
6
+ Installation
7
+ --------
8
+
9
+ In your Gemfile, drop the below line
10
+
11
+ ``
12
+ gem 'watir-webdriver-rails'
13
+ ``
14
+
15
+ and type:
16
+
17
+ ``
18
+ bundle install
19
+ ``
20
+
21
+ from your command line and Rails's root folder
22
+
23
+ How to use
24
+ -------
25
+
26
+ In your spec_helper.rb, please place the below lines:
27
+ (watir-webdriver-rails uses RSpec as the testing framework)
28
+
29
+ ```ruby
30
+
31
+ require 'rspec/rails'
32
+ require 'watir-webdriver-rails'
33
+
34
+ WatirWebdriverRails.host = "localhost"
35
+ WatirWebdriverRails.port = 57124
36
+
37
+ ```
38
+
39
+ In your integration test file, it should look something like this:
40
+
41
+ ```ruby
42
+
43
+ require 'spec_helper'
44
+
45
+ describe "Test something" do
46
+
47
+ it "should go to some page and fill textbox" do
48
+
49
+ browser.goto "/member"
50
+
51
+ browser.text_field(:id=>"first_name").set "Tanin"
52
+ browser.text_field(:id=>"last_name").set "Na Nakorn"
53
+
54
+ browser.text_field(:id=>"first_name").value.should == "Tanin"
55
+ end
56
+ end
57
+
58
+ ```
59
+
60
+ browser is of type Watir::Browser. You may interact with it freely.
61
+ See http://rubydoc.info/gems/watir-webdriver/0.3.2/Watir/Browser
62
+
63
+ Dependencies
64
+ ------------
65
+
66
+ * watir-webdriver
67
+ * rspec
68
+
69
+ Development
70
+ -----------------------------
71
+
72
+ * Fork the project.
73
+ * Add features or fix bugs
74
+ * Add test cases for it
75
+ * Send me a pull request
76
+
77
+ Please try running all the test cases first by going to the root folder and type:
78
+
79
+ ``
80
+ bundle exec rspec spec/*
81
+ ``
82
+
83
+
84
+ License
85
+ ---------
86
+
87
+ There are parts which are copied from capybara and capybara-firebug gems. Please also be aware of their licenses.
88
+ Other than that, you can do anything with it.
89
+
90
+ Author
91
+ ---------
92
+ Tanin Na Nakorn
@@ -0,0 +1,10 @@
1
+ module WatirWebdriverRails
2
+ class << self
3
+ attr_accessor :browser
4
+
5
+ def initialize_browser
6
+ @browser = Watir::Browser.new(WatirWebdriverRails.driver)
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,46 @@
1
+ require 'watir-webdriver'
2
+
3
+ module WatirWebdriverRails
4
+
5
+ # Copied from capybara-firebug
6
+ class Selenium::WebDriver::Firefox::Profile
7
+ def self.firebug_version
8
+ @firebug_version ||= '1.7.3'
9
+ end
10
+
11
+ def self.firebug_version=(version)
12
+ @firebug_version = version
13
+ end
14
+
15
+ def enable_firebug(version = nil)
16
+ version ||= Selenium::WebDriver::Firefox::Profile.firebug_version
17
+ add_extension(File.expand_path("../firebug/firebug-#{version}.xpi", __FILE__))
18
+
19
+ # Prevent "Welcome!" tab
20
+ self["extensions.firebug.currentVersion"] = "999"
21
+
22
+ # Enable for all sites.
23
+ self["extensions.firebug.allPagesActivation"] = "on"
24
+
25
+ # Enable all features.
26
+ ['console', 'net', 'script'].each do |feature|
27
+ self["extensions.firebug.#{feature}.enableSites"] = true
28
+ end
29
+
30
+ # Closed by default.
31
+ self["extensions.firebug.previousPlacement"] = 2
32
+ end
33
+ end
34
+
35
+ class << self
36
+ def driver
37
+ profile = Selenium::WebDriver::Firefox::Profile.new
38
+ profile.enable_firebug
39
+ driver = Selenium::WebDriver.for(:firefox, { :profile => profile })
40
+
41
+ return driver
42
+ end
43
+ end
44
+
45
+
46
+ end
@@ -0,0 +1,30 @@
1
+ Software License Agreement (BSD License)
2
+
3
+ Copyright (c) 2007, Parakey Inc.
4
+ All rights reserved.
5
+
6
+ Redistribution and use of this software in source and binary forms, with or without modification,
7
+ are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above
10
+ copyright notice, this list of conditions and the
11
+ following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above
14
+ copyright notice, this list of conditions and the
15
+ following disclaimer in the documentation and/or other
16
+ materials provided with the distribution.
17
+
18
+ * Neither the name of Parakey Inc. nor the names of its
19
+ contributors may be used to endorse or promote products
20
+ derived from this software without specific prior
21
+ written permission of Parakey Inc.
22
+
23
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
24
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
25
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
29
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,72 @@
1
+ require 'rspec/core'
2
+ require 'uri'
3
+ require 'net/http'
4
+
5
+ module WatirWebdriverRails
6
+
7
+ class Identify
8
+ def initialize(app)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ if env["PATH_INFO"] == "/__identify__"
14
+ [200, {}, [@app.object_id.to_s]]
15
+ else
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+
21
+ class << self
22
+ attr_accessor :host, :port, :server_boot_timeout, :app
23
+
24
+
25
+
26
+ def run_server
27
+
28
+ @app = Rack::Builder.new {
29
+ map "/" do
30
+ if Rails.version.to_f >= 3.0
31
+ run Rails.application
32
+ else # Rails 2
33
+ use Rails::Rack::Static
34
+ run ActionController::Dispatcher.new
35
+ end
36
+ end
37
+ }.to_app
38
+
39
+ Thread.new do
40
+ begin
41
+ require 'rack/handler/thin'
42
+ Thin::Logging.silent = true
43
+ Rack::Handler::Thin.run(Identify.new(app), :Port => @port)
44
+ rescue LoadError
45
+ require 'rack/handler/webrick'
46
+ Rack::Handler::WEBrick.run(Identify.new(app), :Port => @port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
47
+ end
48
+ end
49
+
50
+ timeout(@server_boot_timeout) do
51
+ if responsive?
52
+ true
53
+ else
54
+ sleep(0.5)
55
+ false
56
+ end
57
+ end
58
+ end
59
+
60
+
61
+ def responsive?
62
+ res = Net::HTTP.start("127.0.0.1", @port) { |http| http.get('/__identify__') }
63
+
64
+ if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
65
+ return res.body == @app.object_id.to_s
66
+ end
67
+ rescue Errno::ECONNREFUSED, Errno::EBADF
68
+ return false
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,9 @@
1
+ module WatirWebdriverRails
2
+ module RSpec
3
+
4
+ def browser
5
+ return WatirWebdriverRails.browser
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ module WatirWebdriverRails
2
+ class << self
3
+
4
+ # Copied from Capybara
5
+ def timeout(seconds = 1, driver = nil, error_message = nil, &block)
6
+ start_time = Time.now
7
+
8
+ result = nil
9
+
10
+ until result
11
+ return result if result = yield
12
+
13
+ delay = seconds - (Time.now - start_time)
14
+ if delay <= 0
15
+ raise TimeoutError, error_message || "timed out"
16
+ end
17
+
18
+ driver && driver.wait_until(delay)
19
+
20
+ sleep(0.05)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module WatirWebdriverRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,36 @@
1
+ require 'watir-webdriver'
2
+
3
+ module WatirWebdriverRails
4
+ class WatirWebdriverRailsError < StandardError; end
5
+ class TimeoutError < WatirWebdriverRailsError; end
6
+
7
+ end
8
+
9
+ require 'watir-webdriver-rails/rails'
10
+ require 'watir-webdriver-rails/driver'
11
+ require 'watir-webdriver-rails/browser'
12
+ require 'watir-webdriver-rails/rspec'
13
+
14
+ # start server
15
+ RSpec.configure do |config|
16
+
17
+ config.include WatirWebdriverRails::RSpec
18
+
19
+ config.before(:suite) do
20
+ WatirWebdriverRails.run_server
21
+ WatirWebdriverRails.initialize_browser
22
+
23
+ WatirWebdriverRails.browser.class_eval do
24
+ alias_method :old_goto,:goto
25
+
26
+ def goto(*args)
27
+
28
+ if !args[0].match(/^https?:/)
29
+ args[0] = "http://#{WatirWebdriverRails.host}:#{WatirWebdriverRails.port}#{args[0]}"
30
+ end
31
+
32
+ old_goto(*args)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Rails startup process" do
4
+ it "should fill textbox" do
5
+ browser.goto "/"
6
+ browser.text_field(:id=>"test_textbox").set("Hello")
7
+ browser.text_field(:id=>"test_textbox").value.should == "Hello"
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ source 'http://rubygems.org'
2
+ gem 'rails', '3.0.9'
@@ -0,0 +1,74 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.9)
6
+ actionpack (= 3.0.9)
7
+ mail (~> 2.2.19)
8
+ actionpack (3.0.9)
9
+ activemodel (= 3.0.9)
10
+ activesupport (= 3.0.9)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.5.0)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.14)
16
+ rack-test (~> 0.5.7)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.9)
19
+ activesupport (= 3.0.9)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.5.0)
22
+ activerecord (3.0.9)
23
+ activemodel (= 3.0.9)
24
+ activesupport (= 3.0.9)
25
+ arel (~> 2.0.10)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.9)
28
+ activemodel (= 3.0.9)
29
+ activesupport (= 3.0.9)
30
+ activesupport (3.0.9)
31
+ arel (2.0.10)
32
+ builder (2.1.2)
33
+ erubis (2.6.6)
34
+ abstract (>= 1.0.0)
35
+ i18n (0.5.0)
36
+ mail (2.2.19)
37
+ activesupport (>= 2.3.6)
38
+ i18n (>= 0.4.0)
39
+ mime-types (~> 1.16)
40
+ treetop (~> 1.4.8)
41
+ mime-types (1.16)
42
+ polyglot (0.3.2)
43
+ rack (1.2.3)
44
+ rack-mount (0.6.14)
45
+ rack (>= 1.0.0)
46
+ rack-test (0.5.7)
47
+ rack (>= 1.0)
48
+ rails (3.0.9)
49
+ actionmailer (= 3.0.9)
50
+ actionpack (= 3.0.9)
51
+ activerecord (= 3.0.9)
52
+ activeresource (= 3.0.9)
53
+ activesupport (= 3.0.9)
54
+ bundler (~> 1.0)
55
+ railties (= 3.0.9)
56
+ railties (3.0.9)
57
+ actionpack (= 3.0.9)
58
+ activesupport (= 3.0.9)
59
+ rake (>= 0.8.7)
60
+ rdoc (~> 3.4)
61
+ thor (~> 0.14.4)
62
+ rake (0.8.7)
63
+ rdoc (3.9.2)
64
+ thor (0.14.6)
65
+ treetop (1.4.10)
66
+ polyglot
67
+ polyglot (>= 0.3.1)
68
+ tzinfo (0.3.29)
69
+
70
+ PLATFORMS
71
+ x86-mingw32
72
+
73
+ DEPENDENCIES
74
+ rails (= 3.0.9)
@@ -0,0 +1,5 @@
1
+ class HomeController < ActionController::Base
2
+
3
+ layout "main"
4
+
5
+ end
@@ -0,0 +1 @@
1
+ <input type="text" id="test_textbox">
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <title>Rails testing for Watir Webdriver</title>
6
+ </head>
7
+ <body>
8
+ <%=yield%>
9
+ </body>
10
+ </html>
@@ -0,0 +1,23 @@
1
+
2
+ require File.expand_path('../boot', __FILE__)
3
+
4
+ # Pick the frameworks you want:
5
+ # require "active_record/railtie"
6
+ require "action_controller/railtie"
7
+ #require "action_mailer/railtie"
8
+ require "active_resource/railtie"
9
+ #require "rails/test_unit/railtie"
10
+
11
+
12
+
13
+ # If you have a Gemfile, require the gems listed there, including any gems
14
+ # you've limited to :test, :development, or :production.
15
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
16
+
17
+ module WatirRails
18
+ class Application < Rails::Application
19
+ config.encoding = "utf-8"
20
+ config.filter_parameters += [:password]
21
+ config.active_support.deprecation = :stderr
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,10 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ WatirRails::Application.initialize!
6
+
7
+ WatirRails::Application.config.secret_token = '81d5a4d251df513e47294d8ca73770dd43039b821f06e0a6161f93f1cbdfecd1d7e57f20ceeb6c2ce7e12e5b595c55808a403859cc4b0c324c4760bac9645bb9'
8
+
9
+ Rails.logger = Logger.new(STDOUT)
10
+
@@ -0,0 +1,4 @@
1
+ WatirRails::Application.routes.draw do
2
+ root :to => "home#index"
3
+ match ':controller(/:action(/:id(.:format)))'
4
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run WatirRails::Application
File without changes
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+
4
+ ENV["RAILS_ENV"] ||= 'test'
5
+
6
+ require File.expand_path("../rails/config/environment", __FILE__)
7
+
8
+ require 'rspec/rails'
9
+ require 'watir-webdriver-rails'
10
+
11
+ WatirWebdriverRails.host = "localhost"
12
+ WatirWebdriverRails.port = 57124
13
+
14
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
15
+
16
+
17
+ RSpec.configure do |config|
18
+ config.mock_with :rspec
19
+ end
20
+
21
+
22
+
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "watir-webdriver-rails/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "watir-webdriver-rails"
7
+ s.version = WatirWebdriverRails::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Tanin Na Nakorn"]
10
+ s.email = ["tanin47@gmail.com"]
11
+ s.homepage = "http://github.com/tanin47/watir-webdriver-rails"
12
+ s.summary = %q{Watir on WebDriver for Rails}
13
+ s.description = %q{WebDriver-backed Watir for Rails}
14
+
15
+ s.rubyforge_project = "watir-webdriver-rails"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "watir-webdriver", '>= 0.3.2'
23
+
24
+ s.add_development_dependency "rails", "3.0.9"
25
+ s.add_development_dependency "rspec"
26
+ s.add_development_dependency "rspec-rails"
27
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watir-webdriver-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tanin Na Nakorn
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-06 00:00:00.000000000 +07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: watir-webdriver
17
+ requirement: &13210680 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.3.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *13210680
26
+ - !ruby/object:Gem::Dependency
27
+ name: rails
28
+ requirement: &13901244 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - =
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.9
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *13901244
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &13948188 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *13948188
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec-rails
50
+ requirement: &14144532 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *14144532
59
+ description: WebDriver-backed Watir for Rails
60
+ email:
61
+ - tanin47@gmail.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - Gemfile
68
+ - README.md
69
+ - lib/watir-webdriver-rails.rb
70
+ - lib/watir-webdriver-rails/browser.rb
71
+ - lib/watir-webdriver-rails/driver.rb
72
+ - lib/watir-webdriver-rails/firebug/firebug-1.6.2.xpi
73
+ - lib/watir-webdriver-rails/firebug/firebug-1.7.0.xpi
74
+ - lib/watir-webdriver-rails/firebug/firebug-1.7.3.xpi
75
+ - lib/watir-webdriver-rails/firebug/firebug-1.8.0.xpi
76
+ - lib/watir-webdriver-rails/firebug/firebug-1.8.1.xpi
77
+ - lib/watir-webdriver-rails/firebug/firebug-license.txt
78
+ - lib/watir-webdriver-rails/rails.rb
79
+ - lib/watir-webdriver-rails/rspec.rb
80
+ - lib/watir-webdriver-rails/util/timeout.rb
81
+ - lib/watir-webdriver-rails/version.rb
82
+ - spec/integration/rails_spec.rb
83
+ - spec/rails/Gemfile
84
+ - spec/rails/Gemfile.lock
85
+ - spec/rails/app/controllers/home_controller.rb
86
+ - spec/rails/app/views/home/index.html.erb
87
+ - spec/rails/app/views/layouts/main.html.erb
88
+ - spec/rails/config.ru
89
+ - spec/rails/config/application.rb
90
+ - spec/rails/config/boot.rb
91
+ - spec/rails/config/environment.rb
92
+ - spec/rails/config/routes.rb
93
+ - spec/rails/log/test.log
94
+ - spec/spec_helper.rb
95
+ - watir-webdriver-rails.gemspec
96
+ has_rdoc: true
97
+ homepage: http://github.com/tanin47/watir-webdriver-rails
98
+ licenses: []
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project: watir-webdriver-rails
117
+ rubygems_version: 1.5.2
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Watir on WebDriver for Rails
121
+ test_files: []