watirsplash 1.4.3 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +16 -0
  4. data/Gemfile.lock +88 -0
  5. data/README.rdoc +87 -63
  6. data/Rakefile +3 -41
  7. data/lib/watirsplash.rb +2 -2
  8. data/lib/watirsplash/browser.rb +3 -1
  9. data/lib/watirsplash/cli.rb +22 -26
  10. data/lib/watirsplash/frameworks/firewatir.rb +1 -1
  11. data/lib/watirsplash/frameworks/helper.rb +2 -16
  12. data/lib/watirsplash/frameworks/watir-webdriver.rb +1 -1
  13. data/lib/watirsplash/frameworks/watir-webdriver/chrome.rb +3 -1
  14. data/lib/watirsplash/frameworks/watir-webdriver/firefox.rb +3 -1
  15. data/lib/watirsplash/frameworks/watir-webdriver/ie.rb +3 -1
  16. data/lib/watirsplash/frameworks/watir.rb +1 -3
  17. data/lib/watirsplash/generators/helper.rb +15 -0
  18. data/lib/watirsplash/generators/new_project.rb +14 -13
  19. data/lib/watirsplash/generators/page.rb +64 -0
  20. data/lib/watirsplash/generators/templates/new_project/.rspec +1 -1
  21. data/lib/watirsplash/generators/templates/new_project/config.rb.tt +3 -30
  22. data/lib/watirsplash/generators/templates/new_project/environment.rb.tt +12 -10
  23. data/lib/watirsplash/generators/templates/page/lib/%formatted_namespace%/page/%formatted_page_name%.rb.tt +8 -0
  24. data/lib/watirsplash/generators/templates/page/spec/%formatted_namespace%/page/%formatted_page_name%_spec.rb.tt +5 -0
  25. data/lib/watirsplash/html_formatter.rb +1 -1
  26. data/lib/watirsplash/page/base.rb +41 -0
  27. data/lib/watirsplash/rspec_patches.rb +5 -7
  28. data/lib/watirsplash/spec_helper.rb +5 -12
  29. data/lib/watirsplash/util.rb +3 -35
  30. data/lib/watirsplash/version.rb +10 -0
  31. data/spec/environment.rb +14 -0
  32. data/spec/spec_helper_spec.rb +3 -4
  33. data/spec/spec_match_array_spec.rb +2 -2
  34. data/watirsplash.gemspec +32 -0
  35. metadata +60 -45
  36. data/VERSION +0 -1
  37. data/environment.rb +0 -2
  38. data/lib/watirsplash/generators/migrate_project.rb +0 -25
  39. data/lib/watirsplash/generators/new_common_project.rb +0 -19
  40. data/lib/watirsplash/generators/templates/new_common_project/config.rb.tt +0 -34
  41. data/lib/watirsplash/generators/templates/new_common_project/environment.rb +0 -15
  42. data/lib/watirsplash/generators/templates/new_common_project/lib/common_application_helper.rb +0 -14
  43. data/lib/watirsplash/generators/templates/new_project/spec/%formatted_name%_helper.rb.tt +0 -18
  44. data/lib/watirsplash/generators/templates/new_project/spec/dummy_spec.rb.tt +0 -41
  45. data/spec/util_spec.rb +0 -48
@@ -1,4 +1,4 @@
1
- WatirSplash::Frameworks::Helper.load_gem :gem => "firewatir", :version => "1.8.1"
1
+ WatirSplash::Frameworks::Helper.load_gem "firewatir"
2
2
 
3
3
  module FireWatir #:nodoc:all
4
4
  class Firefox
@@ -3,22 +3,8 @@ module WatirSplash
3
3
  class Helper
4
4
  class << self
5
5
  def load_gems *gems
6
- failed_gems = []
7
- gems.each do |gem_params|
8
- begin
9
- gem gem_params[:gem], gem_params[:version]
10
- require gem_params[:require] || gem_params[:gem]
11
- rescue Gem::LoadError
12
- failed_gems << gem_params
13
- end
14
- end
15
- unless failed_gems.empty?
16
- puts "\nSome dependencies are missing. Install them with:"
17
- failed_gems.each do |failed_gem|
18
- puts " gem install #{failed_gem[:gem]}#{failed_gem[:version] ? " -v #{failed_gem[:version].gsub(/^[~>=]*\s*/, "")}" : ""}"
19
- end
20
- puts
21
- exit 1 unless failed_gems.empty?
6
+ gems.each do |gem|
7
+ require gem
22
8
  end
23
9
  end
24
10
 
@@ -1,4 +1,4 @@
1
- WatirSplash::Frameworks::Helper.load_gem :gem => "watir-webdriver", :version => ">=0.2.3"
1
+ WatirSplash::Frameworks::Helper.load_gem "watir-webdriver"
2
2
 
3
3
  module Watir
4
4
  class Browser
@@ -3,7 +3,9 @@ require_rel "../watir-webdriver.rb"
3
3
  module WatirSplash
4
4
  class Browser
5
5
  def self.new
6
- Watir::Browser.new :chrome
6
+ browser = Watir::Browser.new :chrome
7
+ Util.formatter.browser = browser
8
+ browser
7
9
  end
8
10
  end
9
11
  end
@@ -3,7 +3,9 @@ require_rel "../watir-webdriver.rb"
3
3
  module WatirSplash
4
4
  class Browser
5
5
  def self.new
6
- Watir::Browser.new :firefox
6
+ browser = Watir::Browser.new :firefox
7
+ Util.formatter.browser = browser
8
+ browser
7
9
  end
8
10
  end
9
11
  end
@@ -3,7 +3,9 @@ require_rel "../watir-webdriver.rb"
3
3
  module WatirSplash
4
4
  class Browser
5
5
  def self.new
6
- Watir::Browser.new :ie
6
+ browser = Watir::Browser.new :ie
7
+ Util.formatter.browser = browser
8
+ browser
7
9
  end
8
10
  end
9
11
  end
@@ -1,5 +1,4 @@
1
- WatirSplash::Frameworks::Helper.load_gems({:gem => "watir", :version => "1.8.1"},
2
- {:gem => "win32screenshot", :require => "win32/screenshot", :version => ">=1.0.3"})
1
+ WatirSplash::Frameworks::Helper.load_gems "watir", "win32/screenshot"
3
2
  require "watirsplash/mini_magick_patch"
4
3
  require "watir/ie"
5
4
 
@@ -20,7 +19,6 @@ module Watir
20
19
  self.speed = :fast
21
20
  @error_checkers ||= []
22
21
  add_checker Watir::PageCheckers::JAVASCRIPT_ERRORS_CHECKER
23
- maximize if @ie # @ie is not set here when attaching...
24
22
  end
25
23
 
26
24
  def save_screenshot(params)
@@ -0,0 +1,15 @@
1
+ module WatirSplash
2
+ module Generators
3
+ module Helper
4
+ def supported_frameworks
5
+ %w[default watir firewatir watir-webdriver/ie watir-webdriver/firefox watir-webdriver/chrome]
6
+ end
7
+
8
+ def frameworks_banner
9
+ "# What framework to use? Possible values are:\r\n" +
10
+ "# * #{supported_frameworks.join("\r\n# * ")}\r\n" +
11
+ "WatirSplash::Util.framework = \"#{framework}\""
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,42 +1,43 @@
1
1
  require "uri"
2
+ require "watirsplash/version"
2
3
 
3
4
  module WatirSplash
4
5
  module Generators
5
6
  class NewProject < Thor::Group
6
7
  include Thor::Actions
8
+ include Helper
7
9
 
8
10
  argument :name
9
11
  argument :url
10
12
  argument :framework
11
- argument :load_common, :optional => true
12
13
 
13
14
  def self.source_root
14
15
  File.dirname(__FILE__) + "/templates"
15
16
  end
16
17
 
17
18
  def generate
18
- directory("new_project", "ui-test")
19
- end
20
-
21
- def load_common_cmd
22
- cmd = "WatirSplash::Util.load_common"
23
- cmd = "# Uncomment the following line to load functionality from ui-test-common\n# " + cmd unless load_common
24
- cmd
25
- end
19
+ directory("new_project", name)
20
+ template("../../../../Gemfile", "#{name}/Gemfile")
26
21
 
27
- def formatted_name
28
- Thor::Util.snake_case(name)
22
+ gsub_file("#{name}/Gemfile", "gemspec", %Q{gem "watirsplash", "#{WatirSplash::Version::WATIRSPLASH}"})
23
+ gsub_file("#{name}/Gemfile", /WatirSplash::Version::WATIR_WEBDRIVER/, "\"#{WatirSplash::Version::WATIR_WEBDRIVER}\"")
24
+ gsub_file("#{name}/Gemfile", /WatirSplash::Version::WATIR/, "\"#{WatirSplash::Version::WATIR}\"")
25
+ gsub_file("#{name}/Gemfile", /WatirSplash::Version::WIN32SCREENSHOT/, "\"#{WatirSplash::Version::WIN32SCREENSHOT}\"")
29
26
  end
30
27
 
31
28
  def formatted_url
32
29
  uri = URI.parse(url)
33
- if load_common && !default_url? && uri.relative?
34
- %Q[Config.full_url("#{uri}")]
30
+ if !default_url? && uri.relative?
31
+ %Q[URI.join(#{formatted_name}::Config::URL, "#{uri}").to_s]
35
32
  else
36
33
  %Q["#{uri}"]
37
34
  end
38
35
  end
39
36
 
37
+ def formatted_name
38
+ Thor::Util.camel_case name.gsub("-", "_")
39
+ end
40
+
40
41
  def default_url?
41
42
  url.to_s == "about:blank"
42
43
  end
@@ -0,0 +1,64 @@
1
+ require "uri"
2
+
3
+ module WatirSplash
4
+ module Generators
5
+ class Page < Thor::Group
6
+ include Thor::Actions
7
+
8
+ argument :page_name
9
+ argument :elements
10
+ argument :namespace
11
+ argument :create_spec, :optional => true
12
+ argument :url, :optional => true
13
+
14
+ def self.source_root
15
+ File.dirname(__FILE__) + "/templates"
16
+ end
17
+
18
+ def generate
19
+ directory("page/lib", "lib")
20
+ directory("page/spec", "spec") if create_spec
21
+ end
22
+
23
+ def formatted_page_name
24
+ Thor::Util.snake_case(page_name)
25
+ end
26
+
27
+ def formatted_namespace
28
+ Thor::Util.snake_case(namespace)
29
+ end
30
+
31
+ def page_body
32
+ str = ""
33
+ str += %Q[url "#{url}"
34
+ ] if url
35
+
36
+ elements.each do |element|
37
+ name, type, locator_name, locator_value = element.split(":")
38
+ str += %Q[
39
+ def #{name}
40
+ #{type}(:#{locator_name} => "#{locator_value}")
41
+ end
42
+ ]
43
+ end
44
+ str
45
+ end
46
+
47
+ def spec_body
48
+ str = "#{formatted_page_name}_page = #{page_path}.new#{$/}"
49
+
50
+ elements.each do |element|
51
+ name, type, locator_name, locator_value = element.split(":")
52
+ str += %Q[ # #{formatted_page_name}_page.#{name} # => #{type}(:#{locator_name} => "#{locator_value}")
53
+ ]
54
+ end
55
+ str
56
+ end
57
+
58
+ def page_path
59
+ "#{Thor::Util.camel_case(namespace)}::Page::#{Thor::Util.camel_case(page_name)}"
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -1,2 +1,2 @@
1
1
  --require
2
- watirsplash
2
+ environment
@@ -1,34 +1,7 @@
1
- # What framework to use? Possible values are:
2
- # * watir
3
- # * firewatir
4
- # * watir-webdriver/ie
5
- # * watir-webdriver/firefox
6
- # * watir-webdriver/chrome
7
- <%=
8
- load_cmd = ""
9
- load_cmd += "# " if load_common
10
- load_cmd += "WatirSplash::Util.framework = \"#{framework}\""
11
- %>
12
-
13
1
  # Config for your application
14
- module Config
15
- module <%= name %>
16
- # URL, which will be opened before every test
17
- #
18
- # Replace it with the URL of your application under test
19
- # or if ui-test-common is used then
20
- # URL = Config.full_url("/relative/url/index.html")
2
+ module <%= formatted_name %>
3
+ module Config
4
+ # Main URL of your application under test
21
5
  URL = <%= formatted_url %>
22
6
  end
23
7
  end
24
-
25
- # A global configuration for specs in this project, which will include by default
26
- # an <%= name %>Helper module and open Config::<%= name %>::URL with
27
- # the browser.
28
- #
29
- # You can read more about RSpec-s before and after syntax from:
30
- # http://relishapp.com/rspec/rspec-core/dir/hooks/before-and-after-hooks
31
- RSpec.configure do |config|
32
- config.include(<%= name %>Helper)
33
- config.before(:all) {goto Config::<%= name %>::URL}
34
- end
@@ -1,13 +1,15 @@
1
- # Add all your require statements into this file to avoid unnecessary
2
- # code in your spec files
1
+ require "rubygems"
2
+ require "bundler"
3
+ Bundler.setup
4
+ require "watirsplash"
5
+
6
+ <%= frameworks_banner %>
3
7
 
4
- <%= load_common_cmd %>
8
+ # Load the framework specified by the environment variable WATIRSPLASH_FRAMEWORK or WatirSplash::Util.framework
9
+ WatirSplash::Util.load_framework
5
10
 
6
- # By default everything, which is not a spec file, will be loaded from spec directory
7
- # and it's subdirectories
8
- spec_dir = File.join(File.dirname(__FILE__), "spec/**/*.rb")
9
- filtered_ruby_files = Dir.glob(spec_dir).delete_if do |file|
10
- File.basename(file) =~ /.*_spec\.rb$/i
11
- end
12
- require_all filtered_ruby_files
11
+ require_all File.join(File.dirname(__FILE__), "lib/**/*.rb")
13
12
  require_rel "config.rb"
13
+
14
+ # Add all your require statements into this file to avoid unnecessary
15
+ # code in your spec files
@@ -0,0 +1,8 @@
1
+ module <%= Thor::Util.camel_case namespace %>
2
+ module Page
3
+ class <%= Thor::Util.camel_case page_name %> < WatirSplash::Page::Base
4
+ <%= page_body %>
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,5 @@
1
+ describe <%= page_path %> do
2
+ it "has something on the <%= formatted_page_name %> page" do
3
+ <%= spec_body %>
4
+ end
5
+ end
@@ -12,7 +12,7 @@ module WatirSplash
12
12
 
13
13
  # currently used browser object
14
14
  # needed for saving of screenshots and html
15
- attr_writer :browser
15
+ attr_accessor :browser
16
16
 
17
17
  def initialize(output) # :nodoc:
18
18
  @output_dir = File.expand_path(File.dirname(output))
@@ -0,0 +1,41 @@
1
+ module WatirSplash
2
+ module Page
3
+ class Base
4
+ include SpecHelper
5
+
6
+ class << self
7
+ @@url = "about:blank"
8
+
9
+ def url url
10
+ @@url = url
11
+ end
12
+ end
13
+
14
+ def initialize(browser=nil)
15
+ if browser
16
+ @browser = WatirSplash::Util.formatter.browser = browser
17
+ else
18
+ @browser = WatirSplash::Browser.new
19
+ @browser.goto @@url
20
+ end
21
+ end
22
+
23
+ def return_for element, methodz
24
+ methodz.each_pair do |meth, return_value|
25
+ element.instance_eval do
26
+ instance_variable_set("@#{meth}_return_value", return_value)
27
+ instance_eval %Q[
28
+ self.class.send(:alias_method, :__#{meth}, :#{meth}) if respond_to? :#{meth}
29
+
30
+ def #{meth}(*args)
31
+ self.send(:__#{meth}, *args) if respond_to? :__#{meth}
32
+ instance_variable_get("@#{meth}_return_value").call(*args)
33
+ end
34
+ ]
35
+ end
36
+ end
37
+ element
38
+ end
39
+ end
40
+ end
41
+ end
@@ -30,12 +30,8 @@ end
30
30
  RSpec.configure do |config| #:nodoc:
31
31
  config.include(WatirSplash::SpecHelper)
32
32
 
33
- config.before(:all) do
34
- open_browser_at "about:blank"
35
- end
36
-
37
33
  config.after(:all) do
38
- close if @browser
34
+ WatirSplash::Util.formatter.browser.close if WatirSplash::Util.formatter.browser
39
35
  end
40
36
  end
41
37
 
@@ -117,7 +113,9 @@ RSpec::Matchers.constants.each do |const|
117
113
 
118
114
  inst_methods = instance_methods.map {|m| m.to_sym}
119
115
 
120
- if inst_methods.include?(:matches?) || inst_methods.include?(:does_not_match?)
116
+ if !(inst_methods.include?(:__matches?) || inst_methods.include?(:__does_not_match?)) &&
117
+ (inst_methods.include?(:matches?) || inst_methods.include?(:does_not_match?))
118
+
121
119
  def in(timeout)
122
120
  Kernel.warn "DEPRECATION NOTICE: #in(timeout) is DEPRECATED, please use #within(timeout) method instead!"
123
121
  within(timeout)
@@ -162,7 +160,7 @@ RSpec::Matchers.constants.each do |const|
162
160
  def does_not_match?(actual)
163
161
  @timeout ? (Watir::Wait.until(@timeout) {__does_not_match?(actual)} rescue false) : __does_not_match?(actual)
164
162
  end
165
- else
163
+ elsif inst_methods.include? :matches?
166
164
  def does_not_match?(actual)
167
165
  @timeout ? !(Watir::Wait.while(@timeout) {__matches?(actual)} rescue true) : !__matches?(actual)
168
166
  end
@@ -4,31 +4,24 @@ module WatirSplash
4
4
  # these methods can be used in specs directly
5
5
  module SpecHelper
6
6
 
7
- # opens the browser at specified url
8
- def open_browser_at url
9
- @browser = WatirSplash::Browser.new
10
- Util.formatter.browser = @browser
11
- goto url
12
- end
13
-
14
7
  def method_missing name, *args #:nodoc:
15
- if @browser.respond_to?(name)
8
+ if WatirSplash::Util.formatter.browser.respond_to?(name)
16
9
  SpecHelper.module_eval %Q[
17
10
  def #{name}(*args)
18
- @browser.send(:#{name}, *args) {yield}
11
+ WatirSplash::Util.formatter.browser.send(:#{name}, *args) {yield}
19
12
  end
20
13
  ]
21
- @browser.send(name, *args) {yield}
14
+ WatirSplash::Util.formatter.browser.send(name, *args) {yield}
22
15
  else
23
16
  super
24
17
  end
25
18
  end
26
19
 
27
- # make sure that using method 'p' will be invoked on @browser
20
+ # make sure that using method 'p' will be invoked on browser
28
21
  # and not Kernel
29
22
  # use Kernel.p if you need to dump some variable
30
23
  def p *args #:nodoc:
31
- @browser.p *args
24
+ WatirSplash::Util.formatter.browser.p *args
32
25
  end
33
26
 
34
27
  end
@@ -3,24 +3,6 @@ module WatirSplash
3
3
  class Util
4
4
  class << self
5
5
 
6
- # loads ui-test-common/environment.rb
7
- #
8
- # ui-test-common has to be located at some higher level within directory
9
- # structure compared to project/ui-test directory
10
- def load_common
11
- dir = common_dir
12
- puts "Loading ui-test-common from #{dir}..."
13
- require File.join(dir, "environment.rb")
14
- end
15
-
16
- # loads environment.rb for the project if it exists in the ui-test
17
- # or in some higher level directory
18
- def load_environment
19
- Pathname(Dir.pwd).ascend do |path|
20
- require File.join(path, "environment.rb") if has_environment?(path)
21
- end
22
- end
23
-
24
6
  # configure RSpec to use documentation and WatirSplash::HtmlFormatter formatters
25
7
  def configure_rspec_formatters
26
8
  config = RSpec.configuration
@@ -38,7 +20,8 @@ module WatirSplash
38
20
  @@framework = nil
39
21
 
40
22
  def framework= framework
41
- @@framework = framework.to_sym
23
+ framework = framework.to_sym
24
+ @@framework = framework == :default ? default_framework : framework.to_sym
42
25
  end
43
26
 
44
27
  def framework
@@ -47,7 +30,7 @@ module WatirSplash
47
30
 
48
31
  def load_framework
49
32
  self.framework = ENV["WATIRSPLASH_FRAMEWORK"] || framework || default_framework
50
- require "watirsplash/frameworks/#{framework}"
33
+ require "watirsplash/frameworks/#{framework}"
51
34
  end
52
35
 
53
36
  private
@@ -63,21 +46,6 @@ module WatirSplash
63
46
  end
64
47
  end
65
48
 
66
- def common_dir
67
- ui_test_common_dir = "ui-test-common"
68
- Pathname(Dir.pwd).ascend do |path|
69
- if File.exists?(dir = File.join(path, ui_test_common_dir)) &&
70
- has_environment?(dir)
71
- return dir
72
- end
73
- end
74
- raise "#{ui_test_common_dir} directory was not found! It has to exist somewhere higher in directory tree than your project's directory and it has to have environment.rb file in it!"
75
- end
76
-
77
- def has_environment? dir
78
- File.exists?(File.join(dir, "environment.rb"))
79
- end
80
-
81
49
  end
82
50
  end
83
51
  end