watirmark 5.14.16 → 5.27.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +7 -0
  2. data/bin/watirmark +2 -8
  3. data/generators/new_project/generator.rb +58 -0
  4. data/{app_generators/create_project/templates/project → generators/new_project/templates}/config.yml.erb +0 -0
  5. data/{app_generators/create_project → generators/new_project}/templates/features/env.rb.erb +0 -0
  6. data/{app_generators/create_project → generators/new_project}/templates/features/model_steps.rb.erb +0 -0
  7. data/{app_generators/create_project → generators/new_project}/templates/features/post_error_steps.rb.erb +0 -0
  8. data/{app_generators/create_project → generators/new_project}/templates/features/sample.feature.erb +0 -0
  9. data/{app_generators/create_project → generators/new_project}/templates/features/site_steps.rb.erb +0 -0
  10. data/generators/new_project/templates/gemfile.rb.erb +10 -0
  11. data/generators/new_project/templates/generators/mvc/generator.rb.erb +61 -0
  12. data/generators/new_project/templates/generators/mvc/templates/controller.rb.erb +9 -0
  13. data/generators/new_project/templates/generators/mvc/templates/model.rb.erb +7 -0
  14. data/generators/new_project/templates/generators/mvc/templates/view.rb.erb +16 -0
  15. data/{app_generators/create_project/templates/library → generators/new_project/templates/lib}/configuration.rb.erb +0 -0
  16. data/{app_generators/create_project/templates/library → generators/new_project/templates/lib}/core_libraries.rb.erb +0 -0
  17. data/{app_generators/create_project/templates/library → generators/new_project/templates/lib}/loader.rb.erb +0 -0
  18. data/{app_generators/create_project/templates/library → generators/new_project/templates/lib/name/checkers}/page_load_checker.rb.erb +0 -0
  19. data/{app_generators/create_project/templates/library → generators/new_project/templates/lib/name/checkers}/post_errors_checker.rb.erb +0 -0
  20. data/{app_generators/create_project/templates/library → generators/new_project/templates/lib/name/site}/base_controller.rb.erb +0 -0
  21. data/{app_generators/create_project/templates/library → generators/new_project/templates/lib/name/site}/base_view.rb.erb +0 -0
  22. data/{app_generators/create_project/templates/library → generators/new_project/templates/lib/name/site}/search_controller.rb.erb +0 -0
  23. data/{app_generators/create_project/templates/library/project_require_file.rb.erb → generators/new_project/templates/lib/name.rb.erb} +0 -0
  24. data/{app_generators/create_project/templates/library → generators/new_project/templates/lib}/workflows.rb.erb +0 -0
  25. data/{app_generators/create_project/templates/project → generators/new_project/templates}/rakefile.rb.erb +1 -1
  26. data/generators/new_project/templates/script/generate.rb.erb +4 -0
  27. data/lib/watirmark/at_exit.rb +5 -9
  28. data/lib/watirmark/configuration.rb +7 -2
  29. data/lib/watirmark/controller/actions.rb +35 -12
  30. data/lib/watirmark/controller/controller.rb +8 -4
  31. data/lib/watirmark/controller/dialogs.rb +3 -3
  32. data/lib/watirmark/cucumber/email_helper.rb +19 -0
  33. data/lib/watirmark/cucumber/env.rb +6 -5
  34. data/lib/watirmark/cucumber/hook_helper.rb +38 -0
  35. data/lib/watirmark/cucumber/hooks.rb +13 -8
  36. data/lib/watirmark/cucumber/load_cached_models.rb +9 -0
  37. data/lib/watirmark/cucumber/model_helper.rb +4 -4
  38. data/lib/watirmark/cucumber/transforms.rb +3 -1
  39. data/lib/watirmark/extensions/ruby_extensions.rb +8 -0
  40. data/lib/watirmark/extensions/webdriver_extensions.rb +38 -3
  41. data/lib/watirmark/formatters/snapshot_formatter.rb +3 -0
  42. data/lib/watirmark/models/cucumber_helper.rb +12 -5
  43. data/lib/watirmark/models/factory.rb +35 -2
  44. data/lib/watirmark/page/page.rb +1 -0
  45. data/lib/watirmark/page/page_definition.rb +7 -5
  46. data/lib/watirmark/profile.rb +2 -2
  47. data/lib/watirmark/rake/smoketest.rb +6 -4
  48. data/lib/watirmark/screenshot.rb +3 -8
  49. data/lib/watirmark/session.rb +105 -9
  50. data/lib/watirmark/version.rb +1 -1
  51. data/lib/watirmark.rb +1 -8
  52. data/spec/config_spec.rb +45 -37
  53. data/spec/controller_actions_spec.rb +70 -7
  54. data/spec/controller_spec.rb +103 -83
  55. data/spec/model_factory_spec.rb +191 -8
  56. data/spec/model_traits_spec.rb +5 -0
  57. data/spec/page_spec.rb +10 -2
  58. data/spec/process_page_spec.rb +3 -3
  59. data/spec/session_spec.rb +56 -0
  60. data/spec/spec_helper.rb +1 -1
  61. metadata +146 -142
  62. data/app_generators/create_project/create_project_generator.rb +0 -115
  63. data/app_generators/create_project/templates/generators/controller.rb.erb +0 -9
  64. data/app_generators/create_project/templates/generators/generate.rb.erb +0 -9
  65. data/app_generators/create_project/templates/generators/model.rb.erb +0 -7
  66. data/app_generators/create_project/templates/generators/mvc_generator.rb.erb +0 -100
  67. data/app_generators/create_project/templates/generators/rbeautify.rb.erb +0 -212
  68. data/app_generators/create_project/templates/generators/view.rb.erb +0 -16
  69. data/app_generators/create_project/templates/generators/workflow_loader.rb.erb +0 -1
  70. data/app_generators/create_project/templates/project/gemfile.rb.erb +0 -11
  71. data/bin/etapestry/Gemfile +0 -11
  72. data/bin/etapestry/config.yml +0 -3
  73. data/bin/etapestry/features/etapestry_home.feature +0 -5
  74. data/bin/etapestry/features/step_definitions/model_steps.rb +0 -9
  75. data/bin/etapestry/features/step_definitions/post_error_steps.rb +0 -15
  76. data/bin/etapestry/features/step_definitions/site_steps.rb +0 -7
  77. data/bin/etapestry/features/support/env.rb +0 -8
  78. data/bin/etapestry/generators/mvc/mvc_generator.rb +0 -100
  79. data/bin/etapestry/generators/mvc/rbeautify.rb +0 -212
  80. data/bin/etapestry/generators/mvc/templates/controller.rb.erb +0 -9
  81. data/bin/etapestry/generators/mvc/templates/model.rb.erb +0 -7
  82. data/bin/etapestry/generators/mvc/templates/view.rb.erb +0 -16
  83. data/bin/etapestry/generators/mvc/templates/workflow_loader.rb.erb +0 -1
  84. data/bin/etapestry/lib/etapestry/checkers/page_load_checker.rb +0 -11
  85. data/bin/etapestry/lib/etapestry/checkers/post_errors_checker.rb +0 -23
  86. data/bin/etapestry/lib/etapestry/configuration.rb +0 -6
  87. data/bin/etapestry/lib/etapestry/core_libraries.rb +0 -9
  88. data/bin/etapestry/lib/etapestry/loader.rb +0 -23
  89. data/bin/etapestry/lib/etapestry/site/base_controller.rb +0 -9
  90. data/bin/etapestry/lib/etapestry/site/base_view.rb +0 -6
  91. data/bin/etapestry/lib/etapestry/site/search_controller.rb +0 -12
  92. data/bin/etapestry/lib/etapestry/workflows.rb +0 -0
  93. data/bin/etapestry/lib/etapestry.rb +0 -8
  94. data/bin/etapestry/rakefile.rb +0 -21
  95. data/bin/etapestry/script/generate.rb +0 -9
  96. data/bin/twitter/features/hashtag_search.feature +0 -93
  97. data/bin/twitter/features/step_definitions/hashtag_steps.rb +0 -9
  98. data/bin/twitter/lib/twitter/workflows/search/result_controller.rb +0 -13
  99. data/bin/twitter/lib/twitter/workflows/search/result_model.rb +0 -5
  100. data/bin/twitter/lib/twitter/workflows/search/result_view.rb +0 -19
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2cd92d1a9b252f89b9bd5d392fd880321ea5eee0
4
+ data.tar.gz: 87d2a5c9088b3c8eaa7fe58fdc51618de4b56c19
5
+ SHA512:
6
+ metadata.gz: ffd2177cd8b04c599fb803f4ab52e611b85da37a3ac8c72547549d693475084b342c43c769eee7a3c3a449e9196bedea140d43765462400826333770c9d3ec2d
7
+ data.tar.gz: 9b45889cebcc93fb2c6f5124e9d191f152c6443e2e94ec32cd9b6b23c04aea862c9b3df5113aebff0296be548301d9ac1ce47c660657f62dab7a7068e036051e
data/bin/watirmark CHANGED
@@ -1,10 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- $:<< File.dirname(__FILE__)
3
2
 
4
- require 'rubigen'
5
- require 'rubigen/scripts/generate'
6
-
7
- source = RubiGen::PathSource.new(:application, File.join(File.dirname(__FILE__), "../app_generators"))
8
- RubiGen::Base.reset_sources
9
- RubiGen::Base.append_sources source
10
- RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'create_project')
3
+ require File.expand_path('../../generators/new_project/generator', __FILE__)
4
+ NewProject.start
@@ -0,0 +1,58 @@
1
+ require 'thor/group'
2
+ require 'active_support/inflector'
3
+
4
+ class NewProject < Thor::Group
5
+ include Thor::Actions
6
+
7
+ argument :name, banner: 'creates new test project'
8
+
9
+ def self.source_root
10
+ File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
11
+ end
12
+
13
+ def root_files
14
+ template "gemfile.rb.erb", "#{name}/Gemfile"
15
+ template "config.yml.erb", "#{name}/config.yml"
16
+ template "rakefile.rb.erb", "#{name}/rakefile.rb"
17
+ end
18
+
19
+ def lib_files
20
+ template "lib/configuration.rb.erb", File.join(name, "lib", name, "configuration.rb")
21
+ template "lib/workflows.rb.erb", File.join(name, "lib", name, "workflows.rb")
22
+ template "lib/core_libraries.rb.erb", File.join(name, "lib", name, "core_libraries.rb")
23
+ template "lib/loader.rb.erb", File.join(name, "lib", name, "loader.rb")
24
+ template "lib/name.rb.erb", File.join(name, "lib", "#{name}.rb")
25
+ end
26
+
27
+ def lib_checkers_files
28
+ template "lib/name/checkers/page_load_checker.rb.erb", File.join(name, "lib", name, "checkers", "page_load_checker.rb")
29
+ template "lib/name/checkers/post_errors_checker.rb.erb", File.join(name, "lib", name, "checkers", "post_errors_checker.rb")
30
+ end
31
+
32
+ def lib_site_files
33
+ template "lib/name/site/base_controller.rb.erb", File.join(name, "lib", name, "site", "base_controller.rb")
34
+ template "lib/name/site/search_controller.rb.erb", File.join(name, "lib", name, "site", "search_controller.rb")
35
+ template "lib/name/site/base_view.rb.erb", File.join(name, "lib", name, "site", "base_view.rb")
36
+ end
37
+
38
+ def features_files
39
+ template "features/model_steps.rb.erb", File.join(name, "features", "step_definitions", "model_steps.rb")
40
+ template "features/post_error_steps.rb.erb", File.join(name, "features", "step_definitions", "post_error_steps.rb")
41
+ template "features/site_steps.rb.erb", File.join(name, "features", "step_definitions", "site_steps.rb")
42
+ template "features/env.rb.erb", File.join(name, "features", "support", "env.rb")
43
+ template "features/sample.feature.erb", File.join(name, "features", "#{name}_home.feature")
44
+ end
45
+
46
+ def script_files
47
+ template "script/generate.rb.erb", File.join(name, "script", "generate.rb")
48
+ chmod File.join(name, "script", "generate.rb"), 0755
49
+ end
50
+
51
+ def generators_mvc_files
52
+ template "generators/mvc/generator.rb.erb", File.join(name, "generators", "mvc", "generator.rb")
53
+
54
+ template "generators/mvc/templates/controller.rb.erb", File.join(name, "generators", "mvc", "templates", "controller.rb.erb")
55
+ template "generators/mvc/templates/model.rb.erb", File.join(name, "generators", "mvc", "templates", "model.rb.erb")
56
+ template "generators/mvc/templates/view.rb.erb", File.join(name, "generators", "mvc", "templates", "view.rb.erb")
57
+ end
58
+ end
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'watirmark', :git => 'https://github.com/convio/watirmark.git'
4
+ gem 'watir-webdriver'
5
+ gem 'rspec'
6
+ gem 'rake'
7
+ gem 'builder'
8
+ gem 'cucumber'
9
+ gem 'gherkin'
10
+ gem 'bundler'
@@ -0,0 +1,61 @@
1
+ require 'thor'
2
+ require 'active_support/inflector'
3
+
4
+ class MvcGenerator < Thor
5
+
6
+ attr_accessor :product, :name
7
+
8
+ def self.source_root
9
+ File.join(File.dirname(__FILE__), 'templates')
10
+ end
11
+
12
+ include Thor::Actions
13
+
14
+ desc "mvc WORKFLOW BASENAME", "creates model view controller in your project workflow directory"
15
+
16
+ def mvc(product, name)
17
+
18
+ self.product = product
19
+ self.name = name
20
+
21
+ template "model.rb.erb", File.join(workflows_path, product, "#{name}_model.rb")
22
+ template "view.rb.erb", File.join(workflows_path, product, "#{name}_view.rb")
23
+ template "controller.rb.erb", File.join(workflows_path, product, "#{name}_controller.rb")
24
+
25
+ append_to_file "#{workflows_path}/../workflows.rb" do
26
+ "#{workflow_loader} '#{product.downcase}/#{name.downcase}'\n"
27
+ end
28
+
29
+ end
30
+
31
+ no_commands do
32
+
33
+ def workflows_path
34
+ "lib/<%= name.downcase %>/workflows"
35
+ end
36
+
37
+ def workflow_loader
38
+ "<%= name.camelize %>::Loader.load_workflow"
39
+ end
40
+
41
+ def create_modules
42
+ product.split('/').zip(indents).map { |e| "#{e[1]}module #{e[0].camelize}" }.join("\n").rstrip
43
+ end
44
+
45
+ # for workflow a/b/c returns ["", " ", " "] spaces for formatting output plus initial indentation
46
+ def indents
47
+ @indents ||= indents_calc_and_format
48
+ end
49
+
50
+ def indents_calc_and_format
51
+ i = []
52
+ product.split('/').each_index { |e| i << e * 2 }
53
+ i.map { |e| "\s" * e }.map { |e| "\s\s#{e}" }
54
+ end
55
+
56
+ def create_module_end
57
+ indents.reverse.map { |e| "#{e}end" }.join("\n")
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,9 @@
1
+ module <%= @name.camelize %>
2
+ <%%= create_modules %>
3
+ <%%= indents.last %>class <%%= name.camelize %> < BaseController
4
+ <%%= indents.last %> @model = <%%= name.camelize %>Model
5
+ <%%= indents.last %> @view = <%%= name.camelize %>View
6
+ <%%= indents.last %>end
7
+ <%%= create_module_end %>
8
+ end
9
+
@@ -0,0 +1,7 @@
1
+ module <%= name.camelize %>
2
+ <%%= create_modules %>
3
+ <%%= indents.last %>class <%%= name.camelize %>Model < Watirmark::Model::Factory
4
+ <%%= indents.last %> keywords <%%= name.camelize %>View.keywords
5
+ <%%= indents.last %>end
6
+ <%%= create_module_end %>
7
+ end
@@ -0,0 +1,16 @@
1
+ module <%= name.camelize %>
2
+ <%%= create_modules %>
3
+ <%%= indents.last %>class <%%= name.camelize %>View < BaseView
4
+ <%%= indents.last %> keyword(:keyword_name) { browser.text_field(:id, 'element_id') }
5
+
6
+ <%%= indents.last %> def home(model)
7
+ <%%= indents.last %> end
8
+
9
+ <%%= indents.last %> def create(model)
10
+ <%%= indents.last %> end
11
+
12
+ <%%= indents.last %> def edit(model)
13
+ <%%= indents.last %> end
14
+ <%%= indents.last %>end
15
+ <%%= create_module_end %>
16
+ end
@@ -14,7 +14,7 @@ require 'cucumber/rake/task'
14
14
  module RakeHelper
15
15
  def self.cucumber_task(task_name, files=nil)
16
16
  Cucumber::Rake::Task.new(task_name) do |t|
17
- t.cucumber_opts = "-r features #{FileList[files]} -b --format html -o reports/report.html --format pretty"
17
+ t.cucumber_opts = "-r features #{FileList[files]} -b --format html -o cucumber_#{task_name}.html --format pretty"
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('../../generators/mvc/generator', __FILE__)
4
+ MvcGenerator.start
@@ -1,13 +1,9 @@
1
1
  module Watirmark
2
- def self.add_exit_task &block
2
+ def self.add_exit_task
3
3
  at_exit {
4
- if $!.nil? || $!.is_a?(SystemExit) && $!.success?
5
- code = 0
6
- else
7
- code = $!.is_a?(SystemExit) ? $!.status : 1
8
- end
9
- block.call
10
- exit code
4
+ code = $watirmark_exit
5
+ yield if block_given?
6
+ exit code if code
11
7
  }
12
8
  end
13
- end
9
+ end
@@ -1,5 +1,6 @@
1
1
  require 'singleton'
2
2
  require 'logger'
3
+ require 'yaml'
3
4
 
4
5
  module Watirmark
5
6
 
@@ -21,6 +22,7 @@ module Watirmark
21
22
  :loglevel => Logger::INFO,
22
23
  :uuid => nil,
23
24
  :webdriver => :firefox,
25
+ :headless => false,
24
26
  # database
25
27
  :dbhostname => nil,
26
28
  :dbusername => nil,
@@ -30,8 +32,10 @@ module Watirmark
30
32
  # snapshots
31
33
  :snapshotwidth => 1000,
32
34
  :snapshotheight => 1000,
33
- :sandbox => false,
34
35
  :projectpath => nil,
36
+ :sauce_username => nil,
37
+ :sauce_access_key => nil,
38
+ :dbi_url => nil,
35
39
 
36
40
  #to deprecate
37
41
  :profile => Hash.new { |h, k| h[k] = Hash.new },
@@ -109,12 +113,13 @@ module Watirmark
109
113
  def read_from_environment
110
114
  @settings.each_key do |var|
111
115
  next if var.to_s.upcase == "USERNAME"
116
+ next if var.to_s.upcase == "HOSTNAME" && self.hostname
112
117
  env = ENV[var.to_s.upcase]
113
118
  if var == :webdriver
114
119
  ENV['JOB_NAME']=~ /WEBDRIVER=(\w+)/
115
120
  env ||= $1
116
121
  end
117
- update var.to_sym => env if env
122
+ update_key var, env if env
118
123
  end
119
124
  end
120
125
 
@@ -3,12 +3,12 @@ module Watirmark
3
3
 
4
4
  attr_accessor :records
5
5
 
6
- def run(*actions)
6
+ def run(*actions, &block)
7
7
  begin
8
8
  run_callback_method :before_all
9
9
  record_list.each do |record|
10
- create_model_if_hash(record)
11
- execute_actions(actions)
10
+ create_model(record)
11
+ execute_actions(actions, block)
12
12
  end
13
13
  run_callback_method :after_all
14
14
  ensure
@@ -26,6 +26,14 @@ module Watirmark
26
26
  end
27
27
  end
28
28
 
29
+ def populate_data_overridden?
30
+ self.class.instance_method(:populate_data).owner == self.class
31
+ end
32
+
33
+ def check_for_noop_populate
34
+ warn "Warning: Expected to populate values but none were provided" unless @seen_value || populate_data_overridden?
35
+ end
36
+
29
37
  # Navigate to the View's edit page and for every value in
30
38
  # the models hash, verify that the html element has
31
39
  # the proper value for each keyword
@@ -41,6 +49,7 @@ module Watirmark
41
49
  search_for_record
42
50
  @view.edit @model
43
51
  populate_data
52
+ check_for_noop_populate
44
53
  end
45
54
 
46
55
  # Navigate to the View's create page and
@@ -48,8 +57,10 @@ module Watirmark
48
57
  def create
49
58
  @view.create @model
50
59
  populate_data
60
+ check_for_noop_populate
51
61
  end
52
62
 
63
+
53
64
  def verify_until(&block)
54
65
  run_with_stop_condition(:verify, block)
55
66
  end
@@ -115,6 +126,7 @@ module Watirmark
115
126
  @view.create @model
116
127
  verify_data
117
128
  end
129
+
118
130
  alias :check_create_defaults :check_defaults
119
131
 
120
132
 
@@ -125,10 +137,17 @@ module Watirmark
125
137
  end
126
138
 
127
139
  # Stubs so converted XLS->RSPEC files don't fail
128
- def before_all; end
129
- def before_each; end
130
- def after_all; end
131
- def after_each; end
140
+ def before_all;
141
+ end
142
+
143
+ def before_each;
144
+ end
145
+
146
+ def after_all;
147
+ end
148
+
149
+ def after_each;
150
+ end
132
151
 
133
152
  private
134
153
 
@@ -138,7 +157,7 @@ module Watirmark
138
157
  Watirmark::Session.instance.stop_condition_block = block
139
158
  send(method)
140
159
  ensure
141
- Watirmark::Session.instance.stop_condition_block = Proc.new{}
160
+ Watirmark::Session.instance.stop_condition_block = Proc.new {}
142
161
  end
143
162
  raise Watirmark::TestError, "Expected a stop condition but no stop conditon met!"
144
163
  end
@@ -157,16 +176,20 @@ module Watirmark
157
176
  send name if respond_to?(name)
158
177
  end
159
178
 
160
- def execute_actions(actions)
179
+ def execute_actions(actions, block)
161
180
  actions.each do |action|
162
181
  run_callback_method :before_each
163
- send(action)
182
+ send(action, &block)
164
183
  run_callback_method :after_each
165
184
  end
166
185
  end
167
186
 
168
- def create_model_if_hash(model)
169
- @model = hash_to_model(model) if model.kind_of?(Hash)
187
+ def create_model(record)
188
+ if record.kind_of?(Hash)
189
+ @model = hash_to_model(record)
190
+ else
191
+ @model = record
192
+ end
170
193
  end
171
194
  end
172
195
  end
@@ -69,10 +69,10 @@ module Watirmark
69
69
 
70
70
  def populate_keyword(keyed_element)
71
71
  begin
72
- @seen_value = true
73
72
  before_keyword(keyed_element)
74
73
  populate_keyword_value(keyed_element)
75
74
  after_keyword(keyed_element)
75
+ @seen_value = true
76
76
  rescue => e
77
77
  Watirmark.logger.warn "Unable to populate '#{keyed_element.keyword}'"
78
78
  raise e
@@ -97,11 +97,11 @@ module Watirmark
97
97
  @seen_value = false
98
98
  end
99
99
 
100
- def call_method_if_exists(override, &block)
100
+ def call_method_if_exists(override)
101
101
  if respond_to?(override)
102
102
  send(override)
103
103
  else
104
- block.call if block
104
+ yield if block_given?
105
105
  end
106
106
  end
107
107
 
@@ -122,7 +122,11 @@ module Watirmark
122
122
  end
123
123
 
124
124
  def populate_keyword_value(keyed_element)
125
- call_method_if_exists("populate_#{keyed_element.keyword}") {@view.send("#{keyed_element.keyword}=", value(keyed_element))}
125
+ call_method_if_exists("populate_#{keyed_element.keyword}") do
126
+ # for the first element on a page we populate, wait for it to appear
127
+ @view.send(keyed_element.keyword).send(:wait_until_present) unless @seen_value
128
+ @view.send("#{keyed_element.keyword}=", value(keyed_element))
129
+ end
126
130
  end
127
131
 
128
132
  def verify_keyword_value(keyed_element)
@@ -4,13 +4,13 @@ module Watirmark
4
4
  !!(Page.browser.windows.size > 1)
5
5
  end
6
6
 
7
- def with_modal_dialog(&block)
7
+ def with_modal_dialog
8
8
  wait_for_modal_dialog
9
9
  parent_window = (Page.browser.windows.size) - 2
10
10
  begin
11
11
  Page.browser.windows.last.use
12
12
  Page.browser.wait
13
- block.call
13
+ yield
14
14
  ensure
15
15
  Page.browser.windows[parent_window].use
16
16
  end
@@ -30,4 +30,4 @@ module Watirmark
30
30
  end
31
31
  end
32
32
  end
33
- end
33
+ end
@@ -32,6 +32,15 @@ module EmailHelper
32
32
  email[model.model_name] = EmailBody.new(email_content)
33
33
  end
34
34
 
35
+ def read_email_from(model, from, timeout=30)
36
+ email_content = qa_inbox(model).get_email_text(["FROM", from, "TO", model.email], timeout)
37
+ email[model.model_name] = EmailBody.new(email_content)
38
+ end
39
+
40
+ def read_email_replyto(model, from, timeout=30)
41
+ qa_inbox(model).get_email_replyto(["FROM", from, "TO", model.email], timeout)
42
+ end
43
+
35
44
  def log_email(model)
36
45
  Watirmark.logger.info "Email Received"
37
46
  Watirmark.logger.info email[model.model_name].body.inspect
@@ -63,6 +72,16 @@ module EmailHelper
63
72
  end
64
73
  end
65
74
 
75
+ class EmailEnvelope
76
+ attr_accessor :envelope
77
+
78
+ def initialize(envelope)
79
+ @envelope = envelope
80
+ @from = envelope.from
81
+ end
82
+
83
+ end
84
+
66
85
  class EmailBody
67
86
  attr_accessor :doc, :body
68
87
 
@@ -1,8 +1,9 @@
1
- require 'watirmark/cucumber/cuke_helper'
2
- require 'watirmark/cucumber/email_helper'
3
- require 'watirmark/cucumber/model_helper'
4
- require 'watirmark/cucumber/transforms'
5
- require 'watirmark/cucumber/hooks'
1
+ require_relative 'cuke_helper'
2
+ require_relative 'email_helper'
3
+ require_relative 'model_helper'
4
+ require_relative 'transforms'
5
+ require_relative 'hooks'
6
+ require_relative 'load_cached_models' if Watirmark::Configuration.instance.use_cached_models
6
7
 
7
8
  World CukeHelper
8
9
  World EmailHelper
@@ -0,0 +1,38 @@
1
+ module HookHelper
2
+ class << self
3
+
4
+ def clear_post_errors
5
+ Watirmark::Session.instance.post_failure = nil
6
+ end
7
+
8
+ def trap_post_errors(&block)
9
+ Watirmark::Session.instance.catch_post_failures(&block)
10
+ end
11
+
12
+
13
+ def take_screenshot
14
+ image = "#{Time.now.to_i}-#{UUID.new.generate(:compact)}.png"
15
+ path = "reports/screenshots"
16
+ file = "#{path}/#{image}"
17
+ FileUtils.mkdir_p path unless File.directory? path
18
+ begin
19
+ Page.browser.screenshot.save file
20
+ data = File.open(file, 'rb') { |f| f.read }
21
+ data = Base64.encode64(data)
22
+ rescue Exception => e
23
+ Watirmark.logger.warn("Screenshot was not taken due to an exception")
24
+ Watirmark.logger.warn(e.to_s)
25
+ Watirmark.logger.warn(e.backtrace)
26
+ end
27
+
28
+ [data, 'image/png']
29
+ end
30
+
31
+ def serialize_models
32
+ return unless Watirmark::Configuration.instance.use_cached_models
33
+ Dir.mkdir("cache") unless Dir.exists? "cache"
34
+ File.unlink "cache/DataModels" if File.exists? "cache/DataModels"
35
+ File.open("cache/DataModels", "wb") { |f| f.print Marshal::dump(DataModels) }
36
+ end
37
+ end
38
+ end
@@ -1,16 +1,21 @@
1
+ require_relative "hook_helper"
2
+
1
3
  Around('@catch-post-failure') do |scenario, block|
2
- Watirmark::Session.instance.catch_post_failures(&block)
4
+ HookHelper.trap_post_errors(&block)
3
5
  end
4
6
 
5
- # Initialize post failures so we don't get leakage between scenarios
6
7
  Before('~@catch-post-failure') do
7
- Watirmark::Session.instance.post_failure = nil
8
+ HookHelper.clear_post_errors
9
+ end
10
+
11
+ Before do |scenario|
12
+ HookHelper.serialize_models
8
13
  end
9
14
 
10
15
  After do |scenario|
11
- image = "#{Time.now.to_i}-#{UUID.new.generate(:compact)}.png"
12
- path = "reports/screenshots"
13
- FileUtils.mkdir_p path unless File.directory? path
14
- Page.browser.screenshot.save "#{path}/#{image}"
15
- embed "screenshots/#{image}", 'image/png'
16
+ (file, file_type) = HookHelper.take_screenshot
17
+ embed file, file_type
18
+ HookHelper.serialize_models
16
19
  end
20
+
21
+
@@ -0,0 +1,9 @@
1
+ if File.exists?("cache/DataModels")
2
+ file = File.open("cache/DataModels", "rb")
3
+ DataModels = Marshal::load(file.read)
4
+ #DataModels.each_key { |k| DataModels.delete(k) unless DataModels[k].cache? == true }
5
+ warn "=========="
6
+ warn "USING CACHED MODELS:"
7
+ DataModels.each_pair { |k, v| warn " #{k}: #{v.to_h}" }
8
+ warn "=========="
9
+ end
@@ -9,20 +9,20 @@ module ModelHelper
9
9
  model.update(hash_record(table))
10
10
  end
11
11
 
12
- def with_updated_model(model, table, &block)
12
+ def with_updated_model(model, table)
13
13
  unless model.includes?(hash_record(table))
14
14
  update_model(model, table)
15
- block.call
15
+ yield
16
16
  Watirmark.logger.info "Updated models '#{model.model_name}':\n#{hash_record(table).inspect}"
17
17
  end
18
18
  end
19
19
 
20
20
  # Perform an action using a models and update
21
21
  # the models if that action is successful
22
- def with_model(model, table, &block)
22
+ def with_model(model, table)
23
23
  orig_model = model.clone
24
24
  update_model(model, table)
25
- block.call
25
+ yield
26
26
  if Watirmark::Session.instance.post_failure
27
27
  Watirmark.logger.info "Reverting Model #{Watirmark::Session.instance.post_failure}"
28
28
  model.update(orig_model.to_h) # revert models on failure
@@ -26,7 +26,9 @@ module Watirmark
26
26
  end
27
27
 
28
28
  def model_class_name(name)
29
- "#{name.split.map(&:camelize).join}Model"
29
+ class_name = name.split.map(&:camelize).join
30
+ class_name = "#{class_name}Model" unless class_name =~ /.+Model$/
31
+ class_name
30
32
  end
31
33
 
32
34
  def temporary_model?(user_defined_name)
@@ -1,3 +1,11 @@
1
+ module Kernel
2
+ alias :original_exit :exit
3
+ def exit(status=true)
4
+ $watirmark_exit=status
5
+ original_exit(status)
6
+ end
7
+ end
8
+
1
9
  module Watirmark::MatchMethod
2
10
  def matches(x)
3
11
  self == x